面向对象程序设计(C++)(双语).doc

上传人:椰子壳 文档编号:5028168 上传时间:2020-01-29 格式:DOC 页数:20 大小:121.50KB
返回 下载 相关 举报
面向对象程序设计(C++)(双语).doc_第1页
第1页 / 共20页
面向对象程序设计(C++)(双语).doc_第2页
第2页 / 共20页
面向对象程序设计(C++)(双语).doc_第3页
第3页 / 共20页
面向对象程序设计(C++)(双语).doc_第4页
第4页 / 共20页
面向对象程序设计(C++)(双语).doc_第5页
第5页 / 共20页
点击查看更多>>
资源描述

《面向对象程序设计(C++)(双语).doc》由会员分享,可在线阅读,更多相关《面向对象程序设计(C++)(双语).doc(20页珍藏版)》请在三一文库上搜索。

1、江西财经大学06-07学年第一学期期末考试试卷试卷代码: 03874B 课时: 64学时课程名称:面向对象程序设计(C+)(双语) 适用对象:05级信管、信计一、Single-Choice (Every question is 2 point, total is 32 point)1、( ) has the same function as the sentence: printf(“Hello worldn”) in C language.A. cout”Hello worldn” B. cin”Hello worldn”C. cout”Hello worldn” D. cin”Hello

2、worldn”2、The result of the program is ( ).#include double f(double x, int n) double val = 1.0; while (n-)val = val*x;return(val); void main(void) cout f(5,2) endl; A. 10 B. 7 C. 25 D. 33、For pointers, ( ) is not right.A. int i; int* ptr=&i B. int i; int *ptr; i=*ptrC. int *ptr; ptr=0 D. int i=5; int

3、 *ptr; *ptr=i4、In the following functions, ( ) can not be overloaded.A. Common member functions B. Common non-member functionsC. Destructor D. Constructor5、After executing the following program, ( ) is the result.#includevoid Swap(int a, int b)int t;t=a;a=b;b=t;int main() int x=5, y=10; Swap(x,y); c

4、outx=x y=yendl; return 0; A. x=5 y=10 B. x=10 y=5 C. x=5 y=5 D. x=10 y=106、If a derived class is gained from a base class by private inherit, the private and public members in the base class will become ( ) members for derived class. A. public B. private C. protectedD. friend7、For operator overloadi

5、ng, ( ) is correct.A. The number of operands can be changedB. The priority for operators can be changed C. The syntax for operators cant be changedD. The combination sequence can be changed8、( ) is not right for the description of class.A. Class is a user defined type B. The private members can be a

6、ccessed by friend functions in classC. In class, without declaration the member data are private D. In class, without declaration the member functions are public9、Given a class MyClass, after executing the sentence: MyClass a, b, *p, the constructor will be called ( ) times.A. 1 B. 2 C. 3 D. 410、The

7、 default constructor can exist in the situation of ( ).A. All the timeB. No copy constructor is givenC. No constructor with arguments is givenD. No constructor is given 11、A friend function in a class or a friend class can access ( ) of the class. A. public members B. protected members C. private me

8、mbers D. all members12、For static member data, it is initialized at().A. Before the declaration of class and after the main functionB. Before the main function and after the declaration of classC. In the classD. In the main function13、( ) is equal to the sentence: while(!x).A. x=1 B. x!=1C. x!=0 D.

9、x=014、For macros, ( ) is the result of the following program.#include #define ONE 1#define TWO ONE+ONE#define THREE ONE+TWOvoid main() coutTHREEendl; cout(TWO)*5endl;A. 2 10 B. 1 10 C. 3 10 D. 0 015、In the case of ( ), it can be used inline functions.A. There are cycle sentences in the function like

10、 for(int i)B. There are recursive sentences in the functionC. In order to speed the functionD. There are many codes in the function and they are not frequently used 16、For the descriptions of pure virtual functions and abstract class, () is wrong.A. Pure virtual function is a special function withou

11、t given definitionsB. Abstract class is a class with pure virtual functionsC. If a base class has pure virtual functions, the derived class form it will never be abstract class D. Abstract class can be used as base class, the pure virtual functions in it will defined in the derived class二、Judgment,

12、if it is right please otherwise . (Every question is 2 point, total is 18 point)1、C+ is a sub-set of C, it reserves almost all the characteristics of C.-2、Given int a; int b=a; a=10; b=20; if couta,b; the result is: 20,20.-3、Given class AB, the copy constructor can be defined as: AB:AB(const AB &).-

13、4、Both constructor and destructor can not be overloaded.-5、If class B is a friend of class A, then all member functions of class B can access the members in class A, vice versa.-6、For a non-member operator overloading function, a mode computation can de defined as: X operator%(X), where X is the nam

14、e of a class.-7、No objects of an abstract base class can be instantiated.-8、Given class B int x; /*.*/; we can define class D: public Bint z; public: void SetXZ( int a, int c) x=a; z=c; int Sun() return x+z;-9、Object of a base class can be treated as an object of the derived class.- 三、Complete the p

15、rogram (3*5=15) (Every question is 5 point, total is 15 point) (attention: one line for just one sentence)1、After the main function, the result is: x=0;y=0x=3;y=5x=3;y=5Destructor is called.Destructor is called.Destructor is called.Please complete the program.#include void main()demo d;d.show();demo

16、 d1(3,5); d1.show(); demo d2(d1); d2.show();class demoint x, y;public:-x=a; y=b;- x=d.x;y=d.y;- - void show()-;2、#include #include class personchar *Name;int Age;public:person(char * name, int age); person();char *GetName()return Name;int GetAge()return Age;void show(); ;person:person(char * name, i

17、nt age) - Age=age;person:person()delete Name;void person:show() coutGetName()tGetAge()endl;class student :public personchar *Department; int Number;public:student(char *, int , char*, int);student() delete Department;void SetDep(char *) / the implementation is omittedvoid SetNum(int num) Number=num;

18、 char *GetDep() return Department;int GetNum() return Number;-Number=num;3、The following program is used to calculate the distance between two points, please complete the program.#include #include class Pointpublic: Point(double xx=0, double yy=0) X=xx;Y=yy; double GetX() return X; double GetY() ret

19、urn Y; -private:double X,Y;double Dist( Point& a, Point& b) - - return sqrt(dx*dx+dy*dy);int main() Point p1(3.0, 5.0), p2(4.0, 6.0); - coutThe distance is dendl; return 0;The result is-四、Read the program and write out the result. (Every question is 5 point, total is 20 point)1、Please write the resu

20、lt of the following program:#include int sub(int n)int a; if(n=1) return 1; a=n+sub(n-1); return(a); void main() int i=5; coutsub(i)endl; 2、Please write the result of the following program:#include class testprivate:int num;float fl;public:test( );int getint( )return num;float getfloat( )return fl;t

21、est( );test:test( )coutInitalizing defaultendl;num=0;fl=0.0;test:test( )coutDestructor is activeendl;void main( )test array2;coutarray1.getint ( ),array1.getfloat()endl;3、Please write the result of the following program:#include#includeclass Student string name;public: static int num; Student (strin

22、g& str) name = str; +num; ;int Student:num = 0; int main() Student s1(Smith), s2(“John”); cout”Student:num=” Student:num “n”; Student s3(Marry), s4(“Tom”); cout s3.num= s3.num endl;cout s4.num= s4.num endl;4、Please write the result of the following program:#include class B1 public:B1(int i) coutcons

23、tructing B1 iendl;B1() coutdestructing B1 endl;class B2public:B2(int j) coutconstructing B2 jendl;B2() coutdestructing B2 endl;class B3public:B3() coutconstructing B3 *endl;class C: public B2, public B3, public B1 public:C(int a, int b, int c, int d): B1(a),memberB2(d),memberB1(c),B2(b)coutconstruct

24、ing Cendl;C() coutdestructing C endl;private:B2 memberB2;B1 memberB1;B3 memberB3;void main()C obj(1,3,5,7);五、Programming (The question is 15 point)According to the description, design a program with main function. (Description: In the first step, please declare an abstract class Shape. Then, based o

25、n it two classes named Rectangle and Circle are derived. In both the two classes, the functions GetArea() calculating for the area and GetPeri() calculating for the perimeter must be involved.) 江西财经大学06-07学年第二学期期末考试试卷试卷代码: 03874A 课时: 64学时课程名称:面向对象程序设计(C+)(双语) 适用对象:计算机及其相关专业 试卷命题人:杨勇 试卷审核人:舒蔚 I、Singl

26、e-Choice (Every question takes 2 points, the total score is 32 points)1、When we input “ Tao Zou” , the output of the following program is ( ) consequently.#include#include using namespace std;int main( ) string str; coutplease enter your namestr; couthello, str!n;A. hello, Zou! B. hello, Tao! C. hel

27、lo, Tao Zou! D. hello,!2、The statement ( ) is not the characteristic of the standard library. A. It supports Strings and I/O streamsB. B. It supports the C standard library with very minor modifications C. It Supports for numerical computation D. It supports compiling checking errorsE.3、After execut

28、ing the following program, ( ) is the running result.#includelong fac(int n) long f; if (n1) f=n*fac(n-1); else f=1; return f;void main() coutfac(6)endl;A. 120 B. 720 C. 30. D . 14、Given a class MyClass, after executing the sentence: MyClass a2, b, *p, the destructor MyClass( ) will be called ( ) ti

29、mes.A. 1 B. 2 C. 3 D. 45、In order to improve the speed of the function, the function can be written as ( ). A. Inline function B. Function overloading C. Recursive function D. Friend function6、The running results of the program are ( ). #include void func(int p, int &q) int t; t=p; p=q; q=t; void ma

30、in() int x=1,y=2; func(x,y); coutx”,”yendl;A. 1, 2 B. 2, 1 C, 1, 1 D. 2, 27、For functions with default arguments, ( ) is not wrong.A. int add(int x,int y=5,int z=6)B. int add(int x=1,int y=5,int z)C. int add(int x=1,int y,int z=6)D. int add(int x,int y=5,int z)E.8、C+ has the following characteristic

31、s except ( ). A. Polymorphism B. Object C. Abstract D. Inheritance 9、One of the following description is right, it is ( ).A. C+ is a sub-set of C, it reserves almost all the characteristics of CB. Both constructor and destructor can not be overloadedC. If class B is a friend of class A, then class A

32、 is also the friend of class BD. No objects of an abstract base class can be instantiated10、For a non-member operator overloaded function, a mode computation can de defined as( ).A. X operator%(const X)B. X operator%( const X, const X)C. X operator%( )D. void operator%( const X, const X)11、( ) is no

33、t true for the description of constructor.A. The constructor should have the same name as the class nameB. The system will automatically call the constructor during defining objectC. No returning type for the constructorD. The constructor can have just only one12、Among the following descriptions, (

34、) is not correct.A. Inside inline function, there is no cycle and switch sentences.B. Using the same name for operations on different types is called overloadingC. Given the function prototype: double sqrt(double), we can write cout sqrt(three)D. The form of operator overloading for prefix increment

35、 is like: type operator +()13、For virtual functions, among the following declarations ( )is right.A. Virtual functions can be defined as friend functionsB. Virtual functions can be overloadedC. Constructors can be virtual functions, while destructors cannotD. Virtual functions cannot be defined as s

36、tatic functions14、If we want to define a friend function of class AB, we can define it as:A. void friend func(AB&)B. friend func(AB&)C. friend int func(AB&)D. friend void func()15、About class and object, ( ) is wrong.A. A class can just have one object B. Class is an abstract of one type of objectsC

37、. Object is an instance of a class D. The relation like the variables and their type 16、For static member data, it is initialized at().E. Before the declaration of class and after the main functionF. Before the main function and after the declaration of classG. In the class declarationD. In the main

38、 functionII、True or False (Six programs are given in the following, for each of them, if it is defined correctly, please mark “” for it, else please mark “” and point out the wrong sentences or sentence. Each question takes 3 points, the total score is 18 points)1、void main() int *p= new int(3); int

39、 *q; q=p; cout*pendl; p+=3;/ other operations delete p; 2、class rectangle public:Rectangle( ); Rectangle(int width=4, int length=6); Rectangle() private: int width; int length; ;int main() Rectangle rect1; Rectangle rect2(4,5); 3、class StudentID public: StudentID(int id) value=id; coutAssigning student idvalueendl; protected: int value;class student public: student(char * pName=no name, int ssID=0) coutConstructing student,pNameendl; protected: StudentID id;void main() Student s(“Randy”,9818);student t(“Jenny”);4、class Pointpublic:Point(double xx=0,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 研究报告 > 商业贸易


经营许可证编号:宁ICP备18001539号-1