15、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), whe
16、re 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 B{ int z; public: void SetXZ( int a, int c) { x=a; z=c;} int Sun() { return x+z;}};------------
9、Object of a base
17、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=0
x=3;y=5
x=3;y=5
Destructor is called...
18、
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 demo{
int x, y;
public:
-------------①---------{x=a; y=b;}
-------------②-
19、----------- {
x=d.x;
y=d.y;
}
-------------③-------- {-----------④--------------}
void show()
{
-------------------⑤---------------------------------
}
};
2、#include
#include
class person{
char *Name;
int Age;
public:
person(char * name, int ag
20、e);
~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() {
21、 cout<
22、p() {return Department;}
int GetNum(){ return Number;}
};
--------------------------③--------------------------------------------
{
--------------------------④---------------------
--------------------------⑤---------------------
Number=num;
}
3、The following program is used to calcul
23、ate the distance between two points, please complete the program.
#include
#include
class Point
{public:
Point(double xx=0, double yy=0) {X=xx;Y=yy;}
double GetX() {return X;}
double GetY() {return Y;}
-----------------①---------------------------
private:
24、 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);
----------------④--------------------
cout<<"The distance is "<
25、
}
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);
26、
}
void main()
{ int i=5;
cout<
class test{
private:
int num;
float fl;
public:
test( );
int getint( ){return num;}
float getfloat( ){return fl;}
~test( );
};
test::test( ){
cout<<"Init
27、alizing default"<
#include< string.h>
class St
28、udent{
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="<<
29、s3.num <
30、B2 "<
31、 {cout<<"destructing C "<
32、 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.)
江西財(cái)經(jīng)大學(xué)
06-07學(xué)年第二學(xué)期期末考試試卷
試卷代碼: 03874A 課時(shí):
33、 64學(xué)時(shí)
課程名稱:面向?qū)ο蟪绦蛟O(shè)計(jì)(C++)(雙語(yǔ)) 適用對(duì)象:計(jì)算機(jī)及其相關(guān)專業(yè)
試卷命題人:楊勇 試卷審核人:舒蔚
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
#inclu
34、de
using namespace std;
int main( )
{
string str;
cout<<"please enter your name"<>str;
cout<<"hello, "<
35、ibrary.
A. It supports Strings and I/O streams
B.
B.
It supports the C standard library with very minor modifications
C. It Supports for numerical computation
D. It supports compiling checking errors
E.
3、After executing the following program, ( ) is the running result.
#inclu
36、de
long fac(int n){
long f;
if (n>1) f=n*fac(n-1);
else f=1;
return f;
}
void main()
{
cout<
37、s( ) will be called ( ) times.
A. 1 B. 2 C. 3 D. 4
5、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 function
6、The running results of the prog
38、ram 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);
cout<
39、ng.
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
40、description is right, it is ( ).
A. C++ is a sub-set of C, it reserves almost all the characteristics of C
B. Both constructor and destructor can not be overloaded
C. If class B is a friend of class A, then class A is also the friend of class B
D. No objects of an abstract base class can be inst
41、antiated
10、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
42、 have the same name as the class name
B. The system will automatically call the constructor during defining object
C. No returning type for the constructor
D. The constructor can have just only one
12、Among the following descriptions, ( ) is not correct.
A. Inside inline function, there is no c
43、ycle and switch sentences.
B. Using the same name for operations on different types is called overloading
C. 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 fu
44、nctions, among the following declarations ( )is right.
A. Virtual functions can be defined as friend functions
B. Virtual functions can be overloaded
C. Constructors can be virtual functions, while destructors cannot
D. Virtual functions cannot be defined as static functions
14、If we want to de
45、fine 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 objects
C. Object is
46、 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 function
F. Before the main function and after the declaration of class
G. In the class declaration
D. In th
47、e main function
II、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
48、 *p= new int(3);
int *q;
q=p;
cout<<*p<
49、 int width;
int length;
};
int main()
{
Rectangle rect1;
Rectangle rect2(4,5);
}
3、class StudentID
{ public:
StudentID(int id)
{ value=id;
cout<<"Assigning student id"<
50、t(char * pName="no name", int ssID=0)
{ cout<<"Constructing student,"<
51、
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:
52、 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(
53、);
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 q
54、uestion 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 1
8 2
7 3
2
1
0
#include
using namespace std;
class myclass{
in
55、t num;
------------①-------------------
public:
myclass(int x){
num=x;
-------------②----------------
}
~myclass(){
sum=sum-1;
------------------③----- -------
}
void display(){
cout<
56、myclass a(9);
a.display();
myclass b(8);
b.display();
------------------⑤---------------------
c.display();
}
2、#include
#include
class person{
char *Name;
int Age;
public:
person(char * name, int age);
~person();
char *GetName(){return
57、Name;}
int GetAge(){return Age;}
void show();
};
person::person(char * name, int age){
------------①------------------------
-------------②-----------------------
Age=age;
}
person::~person()
{
delete Name;
}
void person::show() {
cout<
58、ass student :public person{
char *Department;
int Number;
public:
student(char *, int , char*, int);
~student() {delete Department;}
void SetDep(char *) {// ……the implementation is omitted}
void SetNum(int num){ Number=num;}
char *GetDep() {return Department;}
int GetNum(){ ret
59、urn Number;}
};
--------------------------③--------------------------------------------
{
--------------------------④---------------------
--------------------------⑤---------------------
Number=num;
}
3、After the main function, the running results are:
constructer be called.
birthday:1
60、988-10-25
number:12345 sex:f id:9
destructor be called.
Please complete the program.
#include
using namespace std;
class birthday{
private:
int year, month, day;
public:
birthday(int Year,int Month,int Day){year=Year; month=Month; day=Day;}
------------①-------------
61、-----------
void show() {
cout<<" birthday: "<
62、er be called."<
63、 people c(12345,f,9,d);
--------------------------⑤---------------------
}
IV、Read the following programs and write down the running results (Every question takes 5 points, the total score is 20 points)
1、Please write down the running results of the following program:
#include
cl
64、ass simplecat
{ public:
simplecat(int age=1, int weight=2);
int GetAge() { return itsage;}
int GetWeight() {return itsweight;}
private:
int itsage;
int itsweight;
};
simplecat::simplecat(int age, int weight)
{
itsage=age;
65、 itsweight=weight;
}
void main()
{
simplecat F1;
cout<
66、rogram:
#include
class C{
int d;
static int s;
public:
C(int a=0) {d=a; s++; }
int GetD() {return d;}
int GetS() {return s;}
void SetD(int a) {d=a;}
};
int C::s=0;
void main()
{
C c[5];
for (int i=0; i<5; i++)
c[i].SetD(i+1);
for (i=0; i<5; i++)
cout<<"c["<