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

2025-08-16

D. 虚函数必须在派生类中重新实现

二、阅读程序题(共36分)(注:答案请写在该题右边空白处。)

1.以下程序运行后的输出结果为(4分) #include void fun(int *a,int b) { }

b=*a+b; *a=b%4;

cout<<*a<<','<

void main(void) { int x=4,y=5; fun(&y,x);

cout<

cout<

2.以下程序运行后的输出结果是(6分) #include #define N 6 int* LG(int& m)

{

int* a = new int[m]; int* p = a;

for(int i=0; i

return a;

void main() {

int i,a[N]={2,4,6,8,10,12}; int *b=a, n=N; for( i=0; i

cout<

}

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

{

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++大一期末复习资料(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:35吨履带起重机臂架系统 - 图文

相关阅读
本类排行
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 7

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219