问题 填空题

使用VC6打开考生文件夹下的工程test6_1,此工程包含一个源程序文件test6_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:
Constructor2
Constructor1
i=0
i=10
Destructor
源程序文件test6_1.cpp清单如下:
#include<iostream.h>
class CSample

int i;
public;
CSample()cout<<"Constructorl"<<endl;i=0;)
CSample(int val)cout<<"Constructor2"<<endl;i=val;
~CSample()(cout<<"Destructor"<<endl;)
void disp();
;
/**********found********/
void disp()

cout<<"i=”<<i<<endl;

void main()

CSample *a,b(10);
/**********found*********/
a->disp();
/**********found*********/
b->disp();

答案

参考答案:(1)错误:void disp()
正确:void CSample::disp()
(2)错误:a->disp();
   正确:a=new CSample;  
a->disp();
(3)错误:b->disp();
正确:b.disp();

解析:
(1)主要考查考生对于类的成员函数定义格式的熟练掌握,对于类体外函数的实现,应该使用作用域符“::”,按照返回值类型 类名::函数名(参数列表)的形式进行说明;
(2)主要考查考生对于动态存储分配的掌握,根据前面的定义,a是一个指针类型的变量,指向一个对象,但是并没有被初始化,此时a中的数据无任何意义,应该使用动态存储分配new生成一个新的对象,并将返回的指针赋值给a;
(3)主要考查对象指针与对象在调用成员函数时格式的不同,b是一个对象变量,使用b调用成员函数应该用“.”运算符。

阅读理解

Now throwing shoes at President Bush is a popular game on the Internet. It turns out that there are times when it’s good to throw shoes.

After leaving his office in the center of the city, a young man bought a new car and drove it from the city to his home. He was very happy and the car ran very fast. Suddenly, a shoe hit the car door . The man got very angry. He jumped out of the car and caught a boy who still had a shoe in his hand.

“Who are you? Why did you do that?” the young man shouted at the boy.

“I’m sorry. But I don’t know what else to do. My sister has been hurt. I cried for help but nobody stopped,” the boy said.

The man looked around and saw a girl by the road. Her leg was bleeding(流血).

“She is my sister. She wanted to cross the road but fell out of her wheelchair. She is too heavy for me. I can’t get her back into the wheelchair. ”The man was moved. He helped the bleeding girl back into her wheelchair.

“Thank you. You’re so kind,” said the little boy. Life speaks to our hearts. Sometimes we don’t have time to listen and it will throw a shoe at us.

小题1:The young man drove his new car ______.

A.to the city

B.home

C.to his office

D.to his school小题2:Who threw a shoe at the car?

A.A small boy

B.A bleeding girl

C.A young man

D.An old lady小题3:The underlined word “wheelchair” means ______ in this passage.

A.自行车

B.电动车

C.手推车

D.轮椅小题4:Why did the boy throw the shoe?

A.Because he liked the car.

B.Because her sister was hurt.

C.Because he was hurt.

D.Because he was naughty.小题5:What can we learn from the story?

A.We should be kind and helpful.

B.We should drive slowly and safely.

C.Life always throws shoes at our cars.

D.Nobody wants to be hit by a shoe.

单项选择题