试题与答案

有如下程序: #include <iostream> using namespa

题型:填空题

题目:

有如下程序:
#include <iostream>
using namespace std;
class AA

public:
virtual void f()

cout << "AA";

;
class BB : public AA

public:
BB()

cout<<"BB";

;
class CC : public BB

public:
virtual void f()

BB::f();
cout << "CC";

;
int main()

AA aa,*p; BB bb; CC cc;
p=&cc;
p->f();
return O;

运行后的输出结果 【14】

答案:

参考答案:BBBBAACC

解析: 本题中,函数f()在基类AA中派生类CC中都声明为虚函数,所以采用动态联编。主函数首先定义类AA的对象aa和指针对象p,然后定义了类BB的对象bb,此时调用了类BB的构造函数输出BB。再定义类CC的对象 cc,由于类CC是类BB的派生类,所以此时又调用类BB的构造函数输出BB。最后执行语句“p=&cc;p->f();”,输出AA和CC。

试题推荐
题型:完形填空
完形(15%)
Albert Einstein said, “In the middle of every difficulty lies opportunity.” Once __41 __, such opportunities are like valuable diamonds hidden in the sand.
Several years ago, I spoke at a school about how we were surrounded by “___42___  ” if we could only recognize them. A man stopped by to see me, and I remembered him as somebody who had suffered through a(n) ___43___ divorce (离婚) and was examining what was most important to him. He took a small ___44___ out of his pocket. Here is what he said to me that day.
“I ___45___ on this stone when I was leaving church last Sunday. You had spoken about  ___46___ opportunities—diamonds. I put the stone in my ___47___ to remind me to look for those “diamonds” that I need. I have been trying to sell my business . On Monday morning, a man who seemed interested in ___48___ some of my stock (股票) stopped by. I thought, ‘Here’s my diamond—don’t let it ___49___!’ I sold the entire stock to him by noon. Now my next diamond is to find a new ___50___  !”
Not long afterward, he did find a new and better job. From then on, he decided to keep his stone with him all the time as a ___51___ to look for “diamonds” as he dug through the ___52___ of life.
Richard DeVos is right when he points out. “This is an exciting world. It is filled with opportunities. Great moments wait around every corner.” Those moments are diamonds that,   ___53___ left unrecognized, will be forever lost.
Are you looking for “diamonds” every day? If not, you may ___54___ pass them by! Perhaps there is a diamond of opportunity hidden in the difficulty you’re ___55___ now.
小题1:
A.givenB.discoveredC.sentD.made
小题2:
A.opportunitiesB.dangersC.diamondsD.chances
小题3:
A.painfulB.stupidC.normalD.original
小题4:
A.ballB.stoneC.paperD.flower
小题5:
A.steppedB.dependedC.foughtD.based
小题6:
A.stealingB.acceptingC.recognizingD.realizing
小题7:
A.purseB.pocketC.bagD.house
小题8:
A.sellingB.buyingC.huntingD.casting
小题9:
A.go offB.give inC.stay up D.watch out
小题10:
A.buyerB.jobC.stockD.rock
小题11:
A.sceneB.prizeC.reminderD.power
小题12:
A.difficultiesB.hopesC.charactersD.cases
小题13:
A.unlessB.thoughC.forD.if
小题14:
A.happilyB.easilyC.luckilyD.dangerously
小题15:
A.expressingB.satisfyingC.breakingD.experiencing
查看答案
微信公众账号搜索答案