第一范文网 - 专业文章范例文档资料分享平台

自考C++试题及答案(9套合集)

来源:用户分享 时间:2025/5/23 2:07:15 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

void main() {A *pa; B b(7); pa=&b; }

4. #include class X {public: int x; public: X(int x)

{cout<x=x<

cout<

void fun(X); };

void fun(X t)

{cout<

5. #include #include class Bas {public:

Bas(char *s=\\0\void show(); protected:

char name[20]; };

Bas b;

void show()

{cout<<\void main()

{Bas d2(\show(); }

四、完成程序题(本大题共5小题,每小题4分,共20分) 1. 在下面程序横线处填上适当字句,以使该程序执行结果为:

50 4 34 21 10

0 7.1 8.1 9.1 10.1 11.1 #include template void f (__________) {__________;

for (int i=0;i

t=a[i], a[i]=a[n-1-i], a[n-1-i]=t; }

void main ()

{int a[5]={10,21,34,4,50};

double d[6]={11.1,10.1,9.1,8.1,7.1}; f(a,5);f(d,6);

for (int i=0;i<5;i++) cout <

for (i=0;i<6;i++) cout << d[i] << \cout << endl; }

2. 在下面程序的底画线处填上适当的字句,使该程序执行结果为40。 #include class Test { public: ______;

Test (int i=0) {x=i+x;} int Getnum()

{return Test::x+7;} };

_______; void main() {Test test;

cout<

3. 在下列程序的空格处填上适当的字句,使输出为:0,2,10。 #include #include class Magic {double x; public:

Magic(double d=0.00):x(fabs(d)) {}

Magic operator+(______) {

return Magic(sqrt(x*x+c.x*c.x)); }

_______operator<<(ostream & stream,Magic & c) { stream<

void main() {Magic ma;

cout<

4. 下面是一个输入半径,输出其面积和周长的C++程序,在下划线处填上正确的语句。 #include _________;

_________; void main() {double rad; cout<<\cin>>rad;

double l=2.0*pi*rad; double s=pi*rad*rad;

cout<<\\n The long is:\cout<<\:\5. 程序实现大写字母转换成小写字母。 #include void main() {char a; _______; cin>>a; if(_______) a=a+i;

cout<

五、程序分析题(本大题共4小题,每小题5分,共1. 给出下面程序输出结果。

#include class a {public:

virtual void print()

{cout<< \};

class b:public a {};

class c:public b {public:

void print(){cout<<\};

void show(a *p) {(*p).print(); }

void main() {a a; b b; c c;

show(&a); show(&b); show(&c); }

2. 给出下面程序输出结果。 #include #include #include bool fun(long n); void main()

20分) {long a=10,b=30,l=0; if(a%2==0) a++;

for(long m=a;m<=b;m+=2) if(fun(m)) {if(l++==0) cout <

cout <

bool fun(long n)

{int sqrtm=(int)sqrt(n); for(int i=2;i<=sqrtm;i++) if(n%i==0) return false; return true; }

3. 给出下面程序输出结果。 #include class Test {int x,y; public:

Test(int i,int j=0) {x=i;y=j;}

int get(int i,int j) {return i+j;} };

void main()

{Test t1(2),t2(4,6);

int (Test::*p)(int,int=10); p=Test::get;

cout<<(t1.*p)(5)<

cout<<(p1->*p)(7,20)<

4. #include #include #include class student {char name[8]; int deg;

char level[7];

friend class process; // 说明友元类 public:

student(char na[],int d) { strcpy(name,na); deg=d; } };

class process { public:

搜索更多关于: 自考C++试题及答案(9套合集) 的文档
自考C++试题及答案(9套合集).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c5jzjm3itlw62a898ee75_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top