- 1、本文档共9页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C复习题有答案
分析下列程序的输出结果
1.
#include iostream.h
class M
{
int a;
public:
M(int i=15) {a=i; coutin M\n;}
int geta() {return a;}
};
void main()
{
M r1,r2(18);
coutoctr1.geta()endl;
coutdecr2.geta()endl;
}
int M
int M
17
18
2.
#include iostream.h
class A
{
double x;
public:
A(double i) { x=i; }
A operator +(A c)
{ return A(x*c.x); }
double Getx() { return x;}
};
void main()
{
A a(0);
a=A(3)+A(4);
couta.Getx()+8endl;
}
20
3.
#include iostream.h
class P1
{
public:
P1(int i) { p1=i; }
virtual int fun() { return p1;}
private:
int p1;
};
class P2:public P1
{
public:
P2(int i,int j):P1(i),p2(j) { }
int fun() { return p2;}
private:
int p2;
};
void main()
{
P1 *pf=new P1(10);
P2 *pd=new P2(8,18);
P1 b=*pd;
coutpf-fun()endl;
coutb.fun()endl;
cout(*pd).fun()endl;
delete pf;
delete pd;
}
10
18
18
4.
#include iostream.h
class A
{
tatic int N;
int *a;
public:
A(int k)
{
a=new int[N];
for(int j=0;jN;j++)
a[j]=j+k;
}
int geta(int i)
{ return *(a+i);}
static int getN()
{ return N;}
~A()
{ coutD\n; delete [] a;}
};
void main()
{
A x(6),y(9);
for(int i=0;iA::getN();i++)
coutx.geta(i)+y.geta(i)endl;
}
int A::N=3;
15
17
19
D
D
5.
#include iostream.h
void main()
{
int a=40;
while(--a)
{
if(a==20)
break;
if(a%2==0||a%3==0||a%5)
continue;
couta-1endl;
}
}
34
24
6.
#include iostream.h
void main()
{
int x(5);
int fun(int );
int y=fun(x)--;
coutyendl;
}
int w;
int fun(int i)
{
w=i*i;
return w;
}
25
7.
#include iostream.h
int y=3;
int fun(int,int =2,int c=y);
void main()
{
int a(2),b(3),c(4);
int x=fun(a);
int y=fun(a,b);
int z=fun(a,b,c);
coutx+y+zendl;
}
int fun(int a,int b,int c)
{
a=b; b=c; c=a;
couta+b+cendl;
return a+b+c;
}
7
8
10
25
8.
#include iostream.h
class AB
{
public:
AB(int i,int j):b(j)
{ ab=i+2; coutAB\n; }
~AB()
{ coutabendl; }
friend int fun(AB a);
private:
static int a;
int ab;
const i
您可能关注的文档
- 01N变速箱电脑锁一档故障码01316维修.doc
- ----房地产业主项目管理应用价值顺德区巴索工程信息管理有限.ppt
- ----捷联科技策划方案V10.doc
- 03QYJ-100转盘式切药机.doc
- 03近代西方报业的产生和发展.ppt
- 07-08年度读书会聚会小四活动方案设计.doc
- 081402空间结构研究中心结构工程专业硕士研究生培养方案.doc
- 1 猎聘网服务资料及渠道分析.doc
- 01摄影简史.ppt
- 1-金科集团评价中心操作手册.doc
- 2024年证券分析与咨询服务项目投资申请报告代可行性研究报告.docx
- 2024年铬酸酐项目资金申请报告代可行性研究报告.docx
- 2024年清洁胶项目资金申请报告代可行性研究报告.docx
- 2024年肉松饼项目投资申请报告代可行性研究报告.docx
- 2024年陆上泵项目资金需求报告代可行性研究报告.docx
- 2024年未硫化复合橡胶及其制品项目资金需求报告代可行性研究报告.docx
- 2024年精密温控节能设备项目资金筹措计划书代可行性研究报告.docx
- 2024年汽车覆盖件模具项目资金筹措计划书代可行性研究报告.docx
- 宋词行书钢笔字帖.pdf
- 我的暑假生活作文三年级300字10篇.pdf
文档评论(0)