问题 问答题

请使用VC6或使用[答题]菜单打开考生文件夹proj1下的工程proj1,此工程中含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR ****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:
Constructor called.
The value is 10
Copy constructor called.
The value is 10
Destructor called.
Destructor called.
注意:只修改注释“//ERROR ****found****”的下一行语句,不要改动程序中的其他内容。
//proj1.cpp
#include <iostream>
using namespace std;
class MyClass
public:
//ERROR **********found**********
MyClass(int i)
value=i;cout<<"Construc-tor called."<<endl;
//ERROR **********found**********
MyClass(const MyClass p)

value=p.value;
cout<<"Copy constructorcalled."<<endl;

void Print ()
cout<<"The value is"<<value<<endl;
//ERROR **********found**********
void ~MyClass()
cout<<"Destructor called."
<<endl;
private:
int value;
;
int main()

MyClass obj1;
obj1.Print();
MyClass obj2(obj1);
obj2.Print();
return 0;

答案

参考答案:(1)MyClass(int i=10)
(2)MyClass(const MyClass&D)
(3)~MyClass()

解析: 本题考查MyClass类,其中涉及构造函数、复制构造函数、成员函数和析构函数。复制构造函数的参数一般都是引用调用,并且不能改变参数值,因此要在参数前加上const来限制。析构函数一般会考查delete语句,同时要注意析构函数的语法,即函数名前不能有任何类型。
(1)考查构造函数参数默认值,题目要求输出语句:Thevalue is 10,从主函数中可以看出,obj1并没有初始化,但是obj1调用Print()函数时它的值为10,由此可知构造函数的形参有默认值,且值为10,因此得出语句MyClass(int i=10)。
(2)主要考查考生对复制构造函数的掌握,复制构造函数的形参都为引用,同时为了不改变形参的值要加上const.因此得出语句MyClass(const MyClass&p)。
(3)主要考查考生对析构函数的掌握,析构函数和构造函数一样,前面不能添加任何类型,要把void去掉。
主要考查考生对构造函数、复制构造函数和析构函数的掌握。特别要注意析构函数和构造函数一样前面不能添加任何类型。

阅读理解

Father Maurice Chase used a special way to celebrate his 90th birthday. The Catholic priest(神父) took $ 15,000 in cash to Los Angeles’ Skid Row (贫民区) and gave it away. Twenty wheelchair – bound people received $100 bills, while the rest received $1to $ 3 each.

“I come out here to tell them that God loves them and I love them and that some one is concerned about them,” Chase said.

Chase has given away cash and blessings every Sunday at the same corner for 24 years.Several hundred people wait for him every week.

He makes a point of coming on Thanksgiving and Christmas, too, but this is the first year he spent his birthday in the downtown neighborhood where people live mainly in shelters and on dirty sidewalks.

“ It’s the place that makes me the happiest.I just love it,” said Chase. “I look forward to coming here.”

The money comes from donations he receives from rich and famous people he met during his work as assistant to the president of Loyola Marymount University.

The crowd broke into choruses of “Happy Birthday” several times. Some people presented him birthday cards, to his delight.

Travis Kemp, a 51 – year – old disabled man with long black hair, was one of the lucky 20 to receive $ 100. He said he had no special plans for spending the money. “He has a lot of respect from me,” Kemp said. “I know I couldn’t do it.”

小题1:On his 90 th birthday, Chase      

A.handed out cash to the needy

B.collected money for poor people

C.visited poor people’s homes with gifts

D.held a party at Los Angeles’ Skid Row小题2:Which of the following makes Chase feel the happiest?

A.Celebrating his birthday with his neighbours.

B.Working in Loyola Marymount University.

C.Celebrating Christmas with the people he has helped.

D.Going to Los Angeles’ Skid Row to help people there.小题3:What’s the source of the money Chase used to help people?

A.All his savings.

B.His earnings as a Catholic priest.

C.Donations from the wealthy and celebrities(名人).

D.Donations from Loyola Marymount University.小题4:Travis Kemp is mentioned in the text to show .

A.he was the luckiest person on that day

B.the disabled need to be taken care of

C.Chase is greatly appreciated by the needy

D.even old people came to celebrate Chase’s birthday小题5:Which statement is CORRECT according to the passage?

A.Every recipient could get $100 in cash from Father Maurice Chase.

B.Father Maurice Chase gave the cash away not only on his birthday but also on other occasions.

C.Although Father Maurice Chase gave the cash away on his birthday, he didn’t receive anything in return.

D.Father Maurice Chase earned a lot of money as assistant to the president of Loyola Marymount University.

单项选择题