云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 非电类c++大一期末复习资料

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

  • 62 次阅读
  • 3 次下载
  • 2025/7/3 16:09:26

{

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++大一期末复习资料 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

{ 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()

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com