当前位置:首页 >> 其它课程 >> 2008-2009试卷A参考答案

2008-2009试卷A参考答案


Anhui University OF Architecture

Semester 2 ,2008-2009 Final Examination(A) Subject Title: Object-Oriented Programming

Part One Fill in the blanks (3 ?10=30 marks)

1. 2. 3. 4. 5. 6. 7. 8. 9. If int b[][3]={{1},{3,2},{6,5,4},{0}};then b[2][2]= 4 If int b []={1,2,3,4,5};then * b= 1 The main characteristics of OOP are encapsulation, inheritance and polymorphism Constructor\destructor\ \copy constructor, which one is not method in class friend function Virtual base class can prevent data redundance(冗余) in derived class. constructor Not all function have return type, for example: -> 、 :: . 2 (idea\7person\s-d\private\Only123)

Not all Operator can be changed through overloading. for example:.* 、 . 、 How many identifiers(标识符) are legal:

Part Two Error Correction. Maybe there are several mistakes, please modify them (6?3=18 marks)
1. #include <iostream.h> class A {A ( ){cout<<”hello” ;} } int main() {A a; return 0;} 2. #include <iostream> #include <string.h> Using name space; class Animal {private: int age; public:

// {A ( ){ public:cout<<”hello” ;} // };

// public: Animal(){}

Animal(int n){ age = n;} ~Animal(){} }; class Dog : public Animal { public: Dog(int m,string newname){ age = m;name= newname;} // Dog(int m,string newname): Animal(m){ name= newname;} ~Dog(){} private: string name; }; void main() { Dog a; Dog b(2,”huahua”); } 3. #include <iostream > //#include <iostream > using namespace std; class point { public: virtual void m()=0; // virtual void m(){}; point(){} } void main() {point A; }

Part Three

What is the output ( 10*3=30 )
5 5 10 10 15 15 15 20

1. int * p1,a=5,b=20; p1=&a; cout<<a<<“ ”<<*p1<<endl; a=10; cout<<a<<“ ”<<*p1<<endl; *p1=15; cout<<a<<“ ”<<*p1<<endl; p1=&b; cout<<a<<“ ”<<*p1<<endl;

2. class A {

use 2 3 4 5

int a,b; public : A() { a=b=0; cout<<”use”<<endl;} A(int aa,int bb) { a=aa; b=bb; cout <<a<<“ ” <<b<<endl; } ~ A(){cout<<a+b<<”end”;} }; void main() { A x,y(2,3),z(4,5); } 3. #include <iostream.h> class BaseClass { public: BaseClass() { cout << "构造基类对象!" << endl;} ~BaseClass() { cout << "析构基类对象!" << endl;} };
构造基类对象! 构造派生类对象! 析构派生类对象! 析构基类对象!

class DerivedClass : public BaseClass { public: DerivedClass() {cout << "构造派生类对象!" << endl;} ~DerivedClass() {cout << "析构派生类对象!" << endl;} };

void main() { DerivedClass }

d;

Part

Four Answer the following question (9 marks)

When is the copy constructor called automatically? Solution: ?When a class object is defined and initialized by an object of the same class ?When a function returns a value of the class type ?When an argument of the class type is plugged in for a call-by-value parameter

Part

Five programming

( 14 marks)

Circle is a base class and Cylinder is inherited from it.They all have function getArea().Besides Cylinder have function getVolume to figure out Cylinder’s volume(体积) and print it, try to compile the program Solution: #include <iostream > using namespace std; const double pi =3.14; class Circle { public: Circle(int r) { r0=r;} float getr(){return r0;} double getArea(){return pi*r0*r0;} ~Circle() { } private: int r0; }; class Cylinder : public Circle { public: Cylinder(int r,int h): Circle(r){h1=h;} double getArea(){return 2*pi*getr()*h1;} double getVolume(){return Circle::getArea()*h1;} void Volumedisplay(){cout<<getVolume()<<endl;} ~Cylinder(){} private: int h1; }; void main() { Cylinder d(5,2); d.Volumedisplay(); }


更多相关文档:

2008-2009国际私法A试卷以及答案_图文

系主任 出卷人 6 2008-2009 学年第一学期《国际私法》期终试卷 A 卷答案一、单项选择题(15×1 分,共 15 分) 1.C 2.A 3.B 4.B 5.A 6.D 7.C ...

2008-2009有机化学试卷A-答案

2008-2009有机化学试卷A-答案_化学_自然科学_专业资料。河南农业大学 2008-2009 学年第二学期课头号 《有机化学》期末考试试卷 A 答案题 分号数一二三四五六...

2008-2009学年第一学期A答案

《毛泽东思想、邓小平理论和“三个代表”重要思想概论》考试卷(A) (2008-2009 学年第一学期)参考答案 一、单项选择题(本大题共 25 小题,每小题 1 分,共 ...

2008-2009社会调查试题A答案

内蒙古师范大学科学史与科技管理系 2008-2009 学年第 2 学期 课程 社会调查的原理和方法 期末考试卷(A)答案 课程性质 专业限选 任课教师 聂馥玲 本试卷满分 ...

2008-2009第一学期试卷A参考答案

( )参考答案: 期末考试试卷(A)参考答案: 答案一、名词解释:(每小题 3 分,共计 18 分) 名词解释:(每小题 :( 1、人生的自我价值 人生的自我价值就是个人"n tdge-03v class="detail lh21">32013-06-18 |&n6sp;共2页 | 5次下载 |  0下载券 salaj 贡献者:20091103529

2008-2009第一学期试卷A参考答案 ch">质="[7.0>更多_图文 ib s/p> 暂无评分

更多相关标签:

文档资料共享网 nexoncn.com copyright ©right 2010-2020。
文档资料共享网内容来自网络,如有侵犯请联系客服。email:zhit325@126.com