面向对象程序设计(C++)(双语).doc_第1页
面向对象程序设计(C++)(双语).doc_第2页
面向对象程序设计(C++)(双语).doc_第3页
面向对象程序设计(C++)(双语).doc_第4页
面向对象程序设计(C++)(双语).doc_第5页
免费预览已结束,剩余15页可下载查看

下载本文档

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

文档简介

江西财经大学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 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 *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); coutx=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 overloading, ( ) 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 accessed 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 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 members 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. 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 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 without 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, 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 &).-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 name 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 program (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 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, int 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; 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() return 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 result 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;test( );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 (string& 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) coutconstructing 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)coutconstructing 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 on 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、single-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. hello, 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 executing 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 ( ) times.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 main() 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 characteristics 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 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 not 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, ( ) 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 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 static 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. 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 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 *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, double yy=0) x=xx;y=yy;double getx() return x;double gety() return y;friend double dist(point &a, point &b); private:double x,y;double point :dist( point& a, point& b) double dx=a.x-b.x; double dy=a.y-b.y; return sqrt(dx*dx+dy*dy);5、class a public: void seta(int); void showa(); private: int a;class b public: void setb(int); void showb();private: int b;class c : public b, a public: void setc(int, int, int); void showc();private: int c;int main() c obj; obj.seta(5); obj.showa(); obj.setc(6,7,9); obj.showc();obj.setb(6); obj.showb(); 6、class a public: void f();void g();class b public: void f(); void g();class c: public a, public b public: void g(); void h();void main() c c;c. g();c. f(); iii、complete the program (every question takes 5 points, the total score is 15 points) (note: one line for only one c+ sentence)1、 according to the running results of the following program, please complete the program.results: 9 18 27 3210#include using namespace std;class myclass int num; -public:myclass(int x)num=x;- myclass() sum=sum-1; - - void display() coutnumtsumendl; ; - void main() myclass a(9); a.display(); myclass b(8); b.display();- c.display(); 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, int 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; char *getdep() return department;int getnum() return number;-number=num;3、after the main function, the running results are: constructer be called.birthday:1988-10-25number

温馨提示

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

最新文档

评论

0/150

提交评论