C++模拟期末考试(1).doc_第1页
C++模拟期末考试(1).doc_第2页
C++模拟期末考试(1).doc_第3页
C++模拟期末考试(1).doc_第4页
C++模拟期末考试(1).doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

一、 判断题(10分)(对的打,错的打)1. 友元函数用于允许一个函数访问不相关类的私有部分。T2. 构造函数可以被继承。f3. 动态绑定的多态性是通过虚函数实现的。t4. 在c+中,传引用调用等同于传地址调用。F5. 重载函数必须有不同的参数列表。t6. 可以用delete释放不是用new运算符分配的内存。f7. 类成员的默认访问模式是private。t8. 在类Time中的析构函数可以声明为:void Time(int);f9. const对象必须初始化。t10. 在c+中,只能重载已有的运算符。t二 、选择题(20分)1. 关键字 _c_ 说明对象或变量初始化后不会被修改。 a. static b. public c. const d. inline2. 如果调用带有默认参数的函数时缺少一个参数,则_b_参数就作为这一参数。 a. 第一个 b. 最后一个 c. 中间一个 d. 以上都不是3. 成员函数可声明为静态的,条件是它不访问 _c_类成员。 a. 静态 b. 常数 c. 非静态 d. 公共4. 已知一个运行正常的的程序中有下面两个语句:int *p1, *p2=&a; p1=b; 由此可知,变量a和b的类型分别是C 。 A. int 和 int B. int * 和 int C. int 和 int* D. int * 和 int *5. 默认参数的值由_c_提供。 a. 该函数 b. 调用程序 c. 上述二者 d. 以上都不是6假定要对类AB定义加号操作符重载成员函数,实现两个AB类对象的加法,并返回相加结果,则该成员函数的声明语句为:d 。A. AB operator+(AB & a , AB & b) B. AB operator+(AB & a)C. operator+(AB a) D. AB & operator+( )7下面对于友元函数的描述是正确的是_c_。A.友元函数的实现必须在类的内部定义B.友元函数是类的成员函数C.友元函数破坏了类的封装性和隐藏性D.友元函数不能成访问类的私有成员8. 假定MyClass为一个类,则该类的拷贝初始化构造函数的声明语句DA).MyClass(MyClass x);B)MyClass(const MyClass x)C) MyClass(MyClass *x)D)MyClass (MyClass &x)9. 在函数声明中,()是不必要的。bA)函数参数的类型和参数名 B)函数体C) 函数的类型D)函数名10. 设置虚基类的目的是:ba.简化程序 b.消除二义性 c.提高运行效率 d.减少目标代码三 、指出下列程序片段中的错误标号,写出正确语句或解释错在何处。(15分)1) int index=675;const int *ptr=&index;int *const ntptr=&index;*ptr=555;*ntptr=666;int another=8;ptr=&another;ntptr=&another;2) int *arrp;arrp=new int15;delete arrp;3)阅读下面的程序,请指出程序中的错误并说明错误的原因。#include class MyClass public: void Fun(int a) X = a; private: int X; ; void mian( ) Myclass *my; *my.Fun( 10 ); Delete my;四 、写出下面程序的执行结果:(15分)1)#include using namespace std;class Afriend double count(A&);public:A(double t, double r):total(t),rate(r)private:double total;double rate;double count(A& a)a.total+=a.rate*a.total;return a.total;int main(void)A x(80,0.5),y(100,0.2);coutcount(x),count(y)n;coutcount(x)n;return 0;执行结果:120 120 1802)#include using namespace std;class Count private: static int counter; int obj_id; public: Count(); /constructor static void display_total(); /static function void display(); Count(); /destructor ; int Count:counter; /definition of static data member Count:Count() /constructor counter+; obj_id = counter; Count:Count() /destructor counter-; coutObject number obj_id being destroyedn; void Count:display_total() /static function cout Number of objects created is = counterendl; void Count:display() cout Object ID is obj_idendl; int main(void) Count a1; Count:display_total(); Count a2, a3,a4; Count:display_total(); a2.display(); a4.display(); return 0;结果:1 4 2 4 4 3 2 13)#include using namespace std;class BASE char c; public: BASE(char n):c(n) virtual BASE()coutc; ; class DERIVED:public BASE char c; public: DERIVED(char n):BASE(n+1),c(n) DERIVED()coutc; ; int main(void) DERIVED(X); return 0; 答案:XY五、 程序填空:(20分)1)#include using namespace std;class A_public:_char name80;public:A( const_char*n_ ) _strcpy(name,n) _ / 对两个字符串赋值;class B_:_public A_public:B(const char*n)_:_ A(n)_ _void PrintName( ) cout”name:”nameendl;void main( )B b1(“Ling Li”);b1.PrintName( ) ; /执行结果:name: Ling Li2)下列的程序定义了一个实部为real ,虚部为image的复数类Complex,并在类中重载了复数的,操作。请将下列的程序补充完整。 class Complex public: Complex(double r=0.0 , double I=0.0) real = r; image = i; _Complex_operator + ( Complex ); _friend_operator ( Complex , Complex ); private: double real , image ; _complex:complex_operator + ( Complex c ) return Complex ( _real+c.real_image+c.image_ ); Complex operator ( Complex c1, Complex c2 ) return Complex ( c1.real c2.real , c1.image + c2.image );六、编程题(20分)1)定义一个类Point,要求如下所述:(1)构造函数初始化类的对象。(2)定义类的成员函数Distance,计算平面上两点间的距离2)已知如

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论