欢迎来到天天文库
浏览记录
ID:38120928
大小:59.44 KB
页数:14页
时间:2019-06-06
《C++期末练习题(带答案)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、(一)读程序题1.类中包括其他类的对象成员,构造函数中要列出成员对象名带实参,生成该类对象时,要先调用成员对象的构造函数。如果是成员对象的缺省构造函数可以不列,但生成该类对象时,仍要先调用成员对象的缺省构造函数。1.如下程序运行时的输出结果是1135。#includeclassONE{intc;public:ONE():c(0){cout<<1;}ONE(intn):c(n){cout<<3;}};classTWO:publicONE{ONEone1;ONEone2;public:TWO(intm):one2(m){cout<<5;}};voidmain(){TWO
2、t(2);}二.派生类构造函数中要列出基类名带实参,生成派生类对象时,要先调用基类的构造函数,再调用派生类的构造函数。冲突规则与支配规则。2.如下程序运行时的输出结果是。#includeclassA{public:intx;A(){x=10;}A(inti){x=i;}voidShow(){cout<<"x="<3、ic:inty;C(inta,intb,intc):A(a),B(b+30){y=c;}voidShow(){cout<<"y="<4、成员对象的缺省构造函数。构造函数与析构函数调用顺序相反。3.如下程序运行时的输出结果是。#includeclassA{public:A(){cout<<"A()";}~A(){cout<<"~A()";}};classB{public:B(){cout<<"B()";}~B(){cout<<"~B()";}};classC:publicB,publicA{Aa;public:C(){cout<<"C()";}~C(){cout<<"~C()";}};voidmain(){Cc1;}4.如下程序运行时的输出结果是。#include5、am.h>classA{public:A(){cout<<'A'<classA{public:A(){cout<<"A";}~A(){cout<<"~A";}};classB:virtualpublicA{public:B():A(){cout<<"B";}~B(){cout6、<<"~B";}};classC:publicvirtualA{public:C():A(){cout<<"C";}~C(){cout<<"~C";}};classD:publicC,publicB{public:D():B(),C(),A(){cout<<"D";}~D(){cout<<"~D";}};voidmain(){Dd1;}6.下列程序的输出结果是。#includeclassA{public:A(){cout<<"A";}~A(){cout<<"~A";}};classB:publicA{public:B():A(){cout7、<<"B";}~B(){cout<<"~B";}};classC:publicA{public:C():A(){cout<<"C";}~C(){cout<<"~C";}};classD:publicC,publicB{public:D():B(),C(){cout<<"D";}~D(){cout<<"~D";}};voidmain(){Dd1;}7.下列程序的输出结果是。#include
3、ic:inty;C(inta,intb,intc):A(a),B(b+30){y=c;}voidShow(){cout<<"y="<4、成员对象的缺省构造函数。构造函数与析构函数调用顺序相反。3.如下程序运行时的输出结果是。#includeclassA{public:A(){cout<<"A()";}~A(){cout<<"~A()";}};classB{public:B(){cout<<"B()";}~B(){cout<<"~B()";}};classC:publicB,publicA{Aa;public:C(){cout<<"C()";}~C(){cout<<"~C()";}};voidmain(){Cc1;}4.如下程序运行时的输出结果是。#include5、am.h>classA{public:A(){cout<<'A'<classA{public:A(){cout<<"A";}~A(){cout<<"~A";}};classB:virtualpublicA{public:B():A(){cout<<"B";}~B(){cout6、<<"~B";}};classC:publicvirtualA{public:C():A(){cout<<"C";}~C(){cout<<"~C";}};classD:publicC,publicB{public:D():B(),C(),A(){cout<<"D";}~D(){cout<<"~D";}};voidmain(){Dd1;}6.下列程序的输出结果是。#includeclassA{public:A(){cout<<"A";}~A(){cout<<"~A";}};classB:publicA{public:B():A(){cout7、<<"B";}~B(){cout<<"~B";}};classC:publicA{public:C():A(){cout<<"C";}~C(){cout<<"~C";}};classD:publicC,publicB{public:D():B(),C(){cout<<"D";}~D(){cout<<"~D";}};voidmain(){Dd1;}7.下列程序的输出结果是。#include
4、成员对象的缺省构造函数。构造函数与析构函数调用顺序相反。3.如下程序运行时的输出结果是。#includeclassA{public:A(){cout<<"A()";}~A(){cout<<"~A()";}};classB{public:B(){cout<<"B()";}~B(){cout<<"~B()";}};classC:publicB,publicA{Aa;public:C(){cout<<"C()";}~C(){cout<<"~C()";}};voidmain(){Cc1;}4.如下程序运行时的输出结果是。#include5、am.h>classA{public:A(){cout<<'A'<classA{public:A(){cout<<"A";}~A(){cout<<"~A";}};classB:virtualpublicA{public:B():A(){cout<<"B";}~B(){cout6、<<"~B";}};classC:publicvirtualA{public:C():A(){cout<<"C";}~C(){cout<<"~C";}};classD:publicC,publicB{public:D():B(),C(),A(){cout<<"D";}~D(){cout<<"~D";}};voidmain(){Dd1;}6.下列程序的输出结果是。#includeclassA{public:A(){cout<<"A";}~A(){cout<<"~A";}};classB:publicA{public:B():A(){cout7、<<"B";}~B(){cout<<"~B";}};classC:publicA{public:C():A(){cout<<"C";}~C(){cout<<"~C";}};classD:publicC,publicB{public:D():B(),C(){cout<<"D";}~D(){cout<<"~D";}};voidmain(){Dd1;}7.下列程序的输出结果是。#include
5、am.h>classA{public:A(){cout<<'A'<classA{public:A(){cout<<"A";}~A(){cout<<"~A";}};classB:virtualpublicA{public:B():A(){cout<<"B";}~B(){cout
6、<<"~B";}};classC:publicvirtualA{public:C():A(){cout<<"C";}~C(){cout<<"~C";}};classD:publicC,publicB{public:D():B(),C(),A(){cout<<"D";}~D(){cout<<"~D";}};voidmain(){Dd1;}6.下列程序的输出结果是。#includeclassA{public:A(){cout<<"A";}~A(){cout<<"~A";}};classB:publicA{public:B():A(){cout
7、<<"B";}~B(){cout<<"~B";}};classC:publicA{public:C():A(){cout<<"C";}~C(){cout<<"~C";}};classD:publicC,publicB{public:D():B(),C(){cout<<"D";}~D(){cout<<"~D";}};voidmain(){Dd1;}7.下列程序的输出结果是。#include
此文档下载收益归作者所有