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

非电类c++大一期末复习资料

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

{

int x,y; public: Sample(int a=1,int b=1) {

x=a, y=b; disp();

}

Sample(Sample & s) { }

x = s.x; y = s.y;

cout << \

Sample& operator= (Sample & s) { }

~Sample() { if(x==y) cout<<\

else cout<<\ x = s.x; y = s.y;

cout << \return *this;

}

void disp() {

cout << \ }

friend void ms(Sample s); };

void ms(Sample s) { }

void main() {

Sample s1(2,3); Sample s2 = s1; ms(s2); s.x = s.y;

}

4. 以下程序运行后的输出结果是(4分) #include class CSample{ int n; static int k; public:

CSample(int i){n=i;k++;}; void disp(); };

void CSample::disp( ){

cout<<\}

int CSample::k=0;

void main(void){

CSample a(10),b(20),C(30),d(40); a.disp(); b.disp(); C.disp();

d.disp();

}

5. 以下程序运行后的输出结果是(4分) #include class A {

public: virtual void print()

{ cout<<\ }

};

class B:public A {

public:

void print() {

cout<<\

}; };

class C:public B {

public: void print() {

cout<<\

} };

void print(A a) {

a.print(); }

void main(void) {

A a,*pa; B b; C c; pa=&c;

pa->print(); pa=&b;

pa->print();

c.print(); print(c); }

6.以下程序运行后的输出结果是(8分) #include

class money{ int yuan,jiao,fen; public: money(int y=0,int j=0,int f=0)

{yuan=y;jiao=j;fen=f;} money operator+(money c)

money t=c;

yuan=yuan+c.yuan; jiao=jiao+c.jiao; fen=fen+c.fen; return t;

{ }

};

friend money operator+(money,int); void Show() {

cout<<\cout<<\}

money operator+(money c1,int s) { c1.yuan=c1.yuan; c1.jiao=c1.jiao;

c1.fen=c1.fen+s;

return c1; }

void main(void){ money d1(25,50,70),d2(100,200,55),d3,d4;

int s1=50; d3=d1+d2; d4=d2+s1; d1.Show(); d2.Show();

d3.Show(); d4.Show();

}

7. 程序运行后的输出结果是(4分) #include void main() { }

char c[]=\char *p=c; while(*p) { }

if(*p==' ') { *p=*(p-1)-(‘a’-‘A’); cout<

p++;

三、程序完善题(每空2分,共34分)

1. 有如下类定义,请将下列程序补充完整,使得该程序的输出结果是15。要求填写的地

方只允许一条语句,不能写2条以上的语句。(注:语句的结束符号“;”已在句末给出) #include class A{ private:

int *p; A(){} A(int data){

p= (1) ; *p=data;

public:

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