[计算机类试卷]国家二级C++机试(类和对象)模拟试卷9及答案与解析.doc
《[计算机类试卷]国家二级C++机试(类和对象)模拟试卷9及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(类和对象)模拟试卷9及答案与解析.doc(22页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(类和对象)模拟试卷 9及答案与解析 一、选择题 1 有如下类声明: class Foo int bar; ; 则 Foo类的成员 bar是 ( )。 ( A)公有数据成员 ( B)公有成员函数 ( C)私有数据成员 ( D)私有成员函数 2 下列关于 getValue成员函数的实现中,正确的是 ( )。 ( A) SAMPLE: setValue(int n0)n=n0; ( B) void SAMPLE: setValue(int n0)n=n0; ( C) void setValue(int n0)n=n0; ( D) (int n0)n=n0; 3 如果派生类以 pr
2、otected方式继承基类,则原基类的 protected成员和 public成员在派生类中的访问属性分别是 ( )。 ( A) public和 public ( B) public和 protected ( C) protected和 public ( D) protected和 protected 4 有如下程序: #include #include using namespace std; class XCD char*a: int b; public: XCD(char*aa, int bb) a-new charstrlen(aa)+1; strcpy(a, aa); b=bb; c
3、har*Geta()return a; int Getb()return b; ; int main() char*p1=abed, *p2=weirong; int d1=6, d2=8; XCD x(p1, d1), y(p2, d2); cout using namespace std; class test private: int a; public: test0cout+constructor+endl; test(int a)cout+a+endl; test(const test&test) a=test a; cout+, copy constructor+endl; tes
4、t()Cout+destructor+endl; ; int main() test A(3); return 0; 运行时输出的结果是 ( )。 ( A) 3 ( B) constructor destructor ( C) copy constructor destructor ( D) 3 destructor 11 有如下程序: #include using namespace std; class Base public: Base(int x=0)cout using namespace std; class Sample public: Sample() Sample()cout
5、 using namespace std; class ONE int c; public: ONE(): c(0)cout using namespace std; class Name char name20; public: Name() strcpy(name, “); cout using namespace std; class CD public: CD()cout using namespace std; class Monkey public: Monkey() cout using namespace std; class MyClass public: MyClass()
6、+count; MyClass()-count; static int getCount()(return count; private: static int count; ; int MyClass: count=0; int main() MyClass obj; cout using namespace std; class XA int a: public: static int b: XA(int aa): a(aa)b+; int getA()return a; ; int XA: b=0; int main() XA d1(4), d2(5); cout using names
7、pace std; class VAC public; int f() constreturn 3; int f()return 5; ; Int main() VAC v1; const VAC v2; cout using namespace std; class A public: A(int i): rl(i) void print() cout using namespace std; class Boat; class Car public: Car(int i): weight(i) friend int Total(const Car c, const Boat b); pri
8、vate: int weight; ; class Boat public: Boat(int i): weight(i) friend int Total(const Car&c, const Boat b); private: int weight; ; int Total(const Car c, const Boat&b) return c weight+b weight; int main() Car c(10); Boat b(8); cout执行成员对象的构造函数,调用顺序按照各个成员对象在类中声明的顺序 -执行自身的构造函数。本题中,首先会构造基类 Base,调用 Base类的
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 对象 模拟 答案 解析 DOC
