云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 面向对象程序设计复习试题(答案)

面向对象程序设计复习试题(答案)

  • 62 次阅读
  • 3 次下载
  • 2025/6/15 6:11:11

word完美格式

}

(1)输出结果为: Instrument::Print Instrument::Print (2)输出结果为: Guitar::Print Piano::Print 10、 对虚函数使用对象指针或引用调用,系统使用__动态__联编:使用对象调用时,系统使用__静态__联编。

11、 将下列程序补充完整。 #include class convert {

public:

convert(double I){va11=I;}

____ virtual void compute()=0; ____ protected: double val1; double va12: };

//liters to gallons

class l_to_g:public convert {

public:

__ l_to_g(double I):convert(I){} ____ void compute() {

va12=va11/3.7854;

cout<

//Fahrenheit to Celsius class f_to_c:public convert {

public:

f_to_c(double I):convert(I){} void& compute() {

va12=(va11-32)*5/9;

cout<

精心整理 学习帮手

word完美格式

void fun(__convert& f____) {

f.compute(); }

void main() {

l_to_g lgobj(4); f_to_c fcobj(70); fun(lgobj); fun(fcobj); }

12、 下列程序的运行结果如下: Derive1's Print() called. Derive2's Print() caIIed. 根据结果将程序补充完整。 #include class Base {

public:

Base(int I){b=I;}

__ virtual Print()=0; ____ protected: int b; }

class Derive1:public Base {

public:

__ Derive1(int& I):Base(I){} ___ void Print() {

cout<<\ } };

class Derive2:public Base {

public:

Derive2(int I):Base(I){}

void Print(){cout<<“Derive2’s Print() called.”<

void fun(__Base *obj ____) {

obj->Print(); };

精心整理 学习帮手

word完美格式

void main() {

Derive1 *d1=new Derive1(1); Derive2 *d2=new Derive2(2); fun(d1); fun(d2); }

13、 在一个成员函数内调用一个虚函数时,对该虚函数的调用进行_动态__联编。 14、 带有__纯虚函数__的类称为抽象类,它只能作为__基类__来使用。

4.3简答题

A、成员函数重载与虚函数的区别 B、静态联编和动态联编的含义

C、纯虚函数和抽象类的定义及其关系 D、抽象类的特点

4.4读程序题

1、写出下列程序的运行结果。 #include class Base {

public:

Base(int i){x=i;cout<<\ virtual ~Base(){cout<<\private: int x; };

class Derived :public Base {

public:

Derived(int i,int j):Base(i){y=j;cout<<\ ~Derived(){cout<<\private: int y; };

void main() {

Base *b1=new Base(15); delete b1;

Base *b2=new Derived(20,25); delete b2;

精心整理 学习帮手

word完美格式

}

答案 Base:15 ~Base:15 Base:20 Derived:25 ~Derived:25 ~Base:20

2、 阅读下列程序,回答后面提出的问题。 #include class Base {

public:

Base():x(0),y(0){}

Base(int I,int j):x(I),y(j){} int GetX() const{return x;} int GetY() const{return y;}

virtual void Print() const{cout<<\ virtual ~Base(){Print();} private: int x,y; };

class Derived :public Base {

public:

Derived():z(0){}

Derived(int I,int j,int k):Base(I,j),z(k){} void Print() const

{cout<<\ ~Derived(){Print();} private: int z; };

void main() {

Base *d1=new Derived; d1->Print();

Base *d2=new Derived(10,20,30); d2->Print(); delete d2; delete d1; }

精心整理 学习帮手

搜索更多关于: 面向对象程序设计复习试题(答案) 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

word完美格式 } (1)输出结果为: Instrument::Print Instrument::Print (2)输出结果为: Guitar::Print Piano::Print 10、 对虚函数使用对象指针或引用调用,系统使用__动态__联编:使用对象调用时,系统使用__静态__联编。 11、 将下列程序补充完整。 #include class convert { public: convert(double I){va11=I;} ____ virtual void compute()=0; ____ protected: double val1; double va12: }; //liters to gallons clas

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com