ImageVerifierCode 换一换
格式:DOCX , 页数:14 ,大小:20.81KB ,
资源ID:2690311      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-2690311.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C++ Test answer.docx)为本站会员(b****2)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

C++ Test answer.docx

1、C+ Test answer1. Describe the difference of the keyword public, private and protected.(描述关键字public, private 和 protected的区别。)Public member can be accessed by any program.If a member is not accessible from the other part of the program, its private.A protected member of a class Base can be accessed by

2、 classes derived from Base, but it is still hidden from the rest of the program.公有的数据成员可以被任何程序访问私有的数据成员不能被该程序以外的部分程序访问受保护的基类的数据成员可以被基类继承自基类的派生类访问,但是类内可以访问,类外不可以访问2. Please find the bug inside the following code and modify it.(请找到下面的代码里面的错误,并修改它。)#include class Apublic: A() A() ;class B : public Apub

3、lic: B() _pVar = new int100;B() delete _pVar;private: int* _pVar;int main()A* pA = new B(); /派生类的对象给基类对象赋值delete pA; /基类指针对象被删除,则基类的析构函数必须是虚析构,否则结果未定义。return 0;Note: Basic class destructor must be virtual if it may be inheriteted./如果可以被继,基类的析构函数必须是虚析构。 考虑:子类、父类构造&析构的调用顺序。 如果delete的是派生类的指针,调用的是派生类的析构

4、函数,如果delete的是基类的指针,就会出问题,只有这时,没有将基类的析构函数声明为虚函数会出问题。虽然类体系的析构函数的名字不一样,但是虚函数机制仍然起作用。3. What problems will be generated in the following program?Program 1:int* p = new int;int var = 10;p = &var;Note: if use new must be delete/ 即 delete p;Program 2:int* p = new int20;delete p;/delete p; 4. What is the be

5、nefits of the inline function? (内联函数的好处是什么?)Avoid function call overhead(减少函数调用的开销)5. Please describe the different functionality of “Static” when it is used to declare a variable in the function, and when it is used to declare a global variable, and when it is used to declare a member variable in t

6、he class.(请描述“静态”时,当在函数中被用来声明一个变量,当它被用来声明一个全局变量,当它被用于声明类中的成员变量的不同功能。)Static Local Variables(静态局部变量)1 Variables declared as static in a function are not stored with the other local variables on stack.在一个函数中变量被声明为静态时,不与其他局部变量在栈上存储2 They act like global variables and retain their value between function

7、 calls but unlike global variables they are only visible from within the function. i.e. their scope is only the function where they are declared.他们的行为像全局变量和函数调用之间保留其价值,但与全局变量不同,它们只在函数内可见。即其范围是声明它们的功能。3 Static local variables are automatically initialized to zero.静态局部变量自动初始化为零。Static global variable(

8、静态全局变量)It is used in the file that defines the variable. /它只在所在的原文件内使用有效Static members of a class(一个类的静态成员)A static member of a class does not belong to any specific object. It can be accessed directly by class_name : static_member.一个类的静态成员不属于任何特定的对象,它可以直接通过 类名:静态成员对象名.静态成员 来被访问 Static member functi

9、on(静态成员函数)1 Static member function are not associated with any particular object of their class.,so they do not have this pointer.静态成员函数是不与任何特定的对象关联的,因此它不可以使用“This”指针。2 Static member function can access all static members of their class, but not the non-static members of objects of their class.静态成员函

10、数可以访问所有的静态成员,但是不能访问非静态成员。 6. Please explain the difference of struct and class in the C+ language. (请解释在C+语言中struct和class的区别)Struct default is public /C+中结构默认均为publicClass default is private /C+中类的默认均为privateInhanrite is the same /继承是相同的 结构体继承 struct Cint age;double weight;struct D:C void print()cou

11、t This is Dn;7. What is the overload and what is the override? When we overload the operator , we write it as the following:(什么是重载,什么是重写?当我们重载运算符 , 我们编写如下:)ostream& operatorsize = b.size; / 等价与size = b.size; rep = new charsize; /开辟新空间,并用size对rep初始化,返回指针给rep strcpy( rep, a.rep ); /进行拷贝:把对象a赋值到新的对象rep

12、1 an object is initialized by an existing object. /用一个现有的对象对一个新的对象初始化时i.e. A x; A* p = new A(x); 2 an object is passed to or returned from a function by value./一个对象是通过函数传值的方式被传递或被返回时10. Please interpret the functionality of three “const” in the following method declaration:(请解释在下面的方法声明中的三个单词“const”的

13、功能) const int* computeResult( const int& var ) const; 1 A function that returns a constant int pointer. / 修饰一个函数 返回一个常量int型的指针pointer to constants. The value that pointer point to cant be modified /指向常量的指针。指针指向不能被修改的值2 A function that accepts a constant pointer parameter / 接受一个常量指针参数的函数The parameter

14、 cant be modified in the function. /函数的参数不能被修改3 constant member function. The member variables cannt be modified by the function. /常量成员函数 Const function must be a member function of a class / 类的成员函数才可以被constant修饰We may pass a non-constant object to a constant function, but we cannot pass a constant

15、object to a non-constant function.Constant function can invoke constant function and constant variables only./ 类中的constant函数只能调用该类对象成员的constant函数,类中同一个函数可以有constant和非constant两个版本11. Please interpret how many exceptions will be threw respectively in the following two functions. ( 在以下两个函数中有多少异常将被抛出)vo

16、id f();If no exception specifier is given, the function can throw any exception 没有throw(),表示可以抛出任何异常void f() throw()If a function is not expected to throw any exception, it can be specified by throw()不能抛出任何类型的异常int func( int x ) throw( int, Error_message)the function may throw either an int or an ob

17、ject in class Error_messagge.该函数可能抛出一个int或一个类Error_messagge的对象 /若抛出与声明的异常类型不同的异常,VC6.0中正常执行,Dev-cpp会出错。12. What is the difference between map and multimap? What is the difference between list and vector?关联容器:map和multimap之间的区别是什么?有序容器:list 和 vector之间的区别是什么?Map(映射) no duplicated keys / 不允许有重复键Multimap

18、( 多重映射) may have duplicate keys /可以有重复的键List doubly-linked list; sequential access; add or delete anywhere /双向链表;顺序访问;添加或删除的任何地方 Segmented buffer, used to store large data. /分段缓冲区,用来存储大量的数据。 Operator is not overloaded. Vector random access to any element; typically add or delete at the end /随机存取任何元素

19、;通常在队尾添加或删除 Flat buffer, used to store small data. /平缓冲区,用来存储 小数据。 Operator is overloaded.13. Please point out the bug in the following code. / 请指出下面代码中的错误#include int main() int i = 10; cout”the result is ”iendl; return 0;Note: no namespace; /没有命名空间 using namespace std; 14. What is polymorphism? Ho

20、w to implement polymorphism? What is abstract base class? Give a sample of abstract base class? /什么是多态性?如何实施多态性?什么是抽象基类?举一个抽象基类的样本多态性:是将子类类型的指针赋值给父类类型的指针,赋值之后,父对象就可以根据当前赋值给它的子对象的特性以不同的方式运作多态性通过派生类重载基类中的虚函数型方法来实现.abstract base class is which include pure virtual function.抽象基类是包括有纯虚函数(虚函数在定义时所赋的初值为0,可

21、以没有函数体)的类virtual typeT function_name( parameter_list ) = 0;15. What is the virtual base class? What is the virtual class introduced?/什么是虚拟基类?什么是虚拟类的?Class A : public virual R /A类虚继承自R类,R类被称作“虚基类”,A类被称作“虚拟类”16. Please use the UML diagram to interpret what is “IS-A” and what is “HAS-A”. (请使用UML图来解释什么是

22、“ - A ”,什么是“ HAS - A ”)Is-a is inheritance /类之间的继承关系 如果A是B,那么B就是A的基类Has-a is Cpmposition /对象和它的成员之间的从属关系 如果A中有B,那么B就是A的组成部分17. What is the Singleton pattern? What is the benefit of this pattern?(Singleton模式是什么?这种模式的好处是什么?)Ensure a class only has one instance, and provide a global point of access to

23、it./单例模式确保一个类只有一个实例,并提供一个访问它的全局访问点。单例模式的优点: 1,实例控制:单例模式防止其它对象对自己的实例化,确保所有的对象都访问一个实例。 2,伸缩性:因为由类自己来控制实例化进程,类就在改变实例化进程上有相应的伸缩性。单例模式的好处就是:类只实例化一次,省资源,节省开销,提高速度18 implement the function strcpy() (实现拷贝函数)Char* strcpy( char* strDest, const char* strSrc) If(strDest = NULL) | ( strSrc = NULL ) Throw “Invali

24、d argument(s)”; Char* strDestCopy = strDest; While(*strDest+ = *strSrc+)!=0)/* while(*strSrc != 0) *strDest = *strSrc; strDest+; strSrc+; */ Return strDestCopy;19 Write a class String including default construct, copy constructor, overloaded assignment operator(写一个String类的默认构造,拷贝构造函数,赋值运算符重载)Class S

25、tringPublic: String(); String( char* str ); String( const String& aString ); Const String& operator=(const String& aString ); String();Private: Char* _str;String:String(void) / 3分 delete m_data; / 由于m_data是内部数据类型,也可以写成 delete m_data; / String的普通构造函数 String:String(const char *str) / 6分 if(str=NULL) m

26、_data = new char1; / 若能加 NULL 判断则更好 *m_data = 0; else int length = strlen(str); m_data = new charlength+1; / 若能加 NULL 判断则更好 strcpy(m_data, str); / 拷贝构造函数 String:String(const String &other) / 3分 int length = strlen(other.m_data); m_data = new charlength+1; / 若能加 NULL 判断则更好 strcpy(m_data, other.m_data); / 赋值函数 const String & String:operate =(const String &other) /

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2