问题 单项选择题

有以下程序: #include 〈iostream〉 using namespace std; class A { public:virtual void setx(int i,int j=0){ x=i; y=j;}virtual void print()=0; protected:int x,y; }; class B : public A { public:void print(){ cout〈〈x*x〈〈", ";} }; class C : public A { public:void print(){ cout〈〈x*x*x〈〈end1;} }; int main() {A *pa;B b;C c;pa=&b;pa->setx(5);pa->print ();pa=&c;pa->setx(2);pa->print();return 0; } 程序运行后的输出结果是( )。

A.25,8

B.2,5

C.5,2

D.8,25

答案

参考答案:A

解析: 该程序中定义了A类、B类和C类共3个类。其中,类A是抽象类,它的类体内有一个纯虚函数pnnt()。抽象类不可以定义对象,但可以定义指向对象的指针。类B和类C都是类A的公有派生类,这些类是具体类,它们对A类中纯虚函数都有不同的实现。该程序的主函数中,定义一个指向类A对象的指针pa,又定义了类B和类C的2个对象,并使指针pa分别指向这些对象。这里,采用动态联编,在运行时选择print()函数。所以,执行语句序列“pa=&b;pa->setx(5);pa->print();”后,系统调用类B的print()函数,输出25;执行语句序列“pa=&c;pa->setx(2);pa->prim();”后,系统调用类C的prim()函数,输出8。

判断题
阅读理解

阅读理解。

     Almost all people like flowers. Some people like flowers because of their smells, shapes, colors and so

on. Others like flowers because they think different flowers mean different things. Flowers have their own

language. For example, red roses mean"love" and sunflowers mean "loyalty" (忠诚). So people in more than

100 countries have chosen their own national flowers which say something about their countries' spirit.

In 1994, China talked about choosing a national flower. Some people liked the peony (牡丹) but others liked

the plum blossom (梅花). They couldn't agree with each other. So it has not been decided yet.

     People like to buy different flowers in different seasons. Where do all the beautiful flowers in shops come

from? They may come from far away, so their price is higher.

    a. Farmers grow flowers in their fields.

    b. Planes or trains or buses take the flowers to different places.

    c. Flower shopkeepers buy flowers from the flower markets. They look at the flowers and throw away

the broken or bad ones. They cut the flowers to make them more beautiful. 

    d. You go to buy the flowers in the shops. When you buy a flower, you're paying lots of people: the farmer,

the driver of the plane or train or bus. The seller in the flower market and the flower shopkeeper.

     So you'd better keep your flowers from far away for a long time. But how? Why not dry them? It's easy!

Sand drying is a way. Dry, clean sand is one of the oldest things for drying flowers. And it's one of the

cheapest. 

     ● Fill a box half-way with sand. 

     ● Put the flowers on top of the sand. 

     ● Put the box in a warm, dry place.

     ● Leave the flowers there for one to three weeks.

     ● Take them out and they will be dry.

1. The underlined words "national flowers" most probably means ________.

A. the flowers of the country

B. the flowers of the season

C. the most beautiful flowers

D. the strongest flowers

2. People usually choose their own "national flower" according to the flower's ________.

A. smell

B. shape

C. color

D. meaning

3. The Chinese national flower has not been decided yet, because ________.

A. no flower can show China's spirit

B. China hasn't talked about choosing one

C. nobody agrees to choose the national flower

D. people can't agree to choose the same flower

4. You'd better keep your flowers for a long time, because ________.

A. the flowers are easy to dry

B. the farmer will also ask you to pay

C. the flowers are expensive to buy

D. the shopkeeper has made them more beautiful

5. According to the passage, we know ________ stand for "love".

A. peony

B. red roses

C. plum blossom

D. sunflowers