问题 填空题

有如下程序: #include<iostream> using namespace std; class Pet{char name[10]; public:Pet(char*name){strcpy(this->name,name);}const char*getName()const {return name;}virtual void call()const=0; }; class Dog:public Pet{ public:Dog(char*name):Pet(name){}void call()const{cout<<"汪汪叫":} }; class Cat:public Pet{ public:Cat(char*name):Pet(name){}void call()const{cout<<"喵喵叫";} }; int main(){Pet*pet1=new Dog("哈克"),*pet2=new Cat("吉米");cout<<pet1->getName();pet1->call();cout<<end1;cout<<pet2->getName();pet2->call();cout<<end1;return 0; } 程序的输出结果是______。

答案

参考答案:哈克汪汪叫

解析:吉米喵喵叫 此题考查的是虚函数与多态性。在成员函数的声明前面加上virual关键字,即可把函数声明为虚函数;在C++中,一个基类指针可以用于指向它的派生类对象,而且通过这样的指针调用虚函数时,被调用的是该指针实际所指向的对象类的那个重定义版本。即若基类和派生类中存在一模一样的成员函数,通过该基类指针调用这样的成员函数时,若这个成员函数被定义成虚函数,那么就调用派生类中的;否则就调用基类中的。本题中,在f()函数中,此题中,void call()在基类中被声明为虚函数,在主函数中,语句Pet*pet1=new Dog("哈克"),*pet2=new Cat("吉米");定义了基类的指针per1和pet2,并让它们分别指向派生类对象Dog和Cat。所以通过该指针调用call()时运行的是派生类的版本,分别输出哈克和吉米;而通过该指针调用 getName()运行的是基类的版本,分别输出汪汪叫和喵喵叫。

单项选择题

The Intergovernmental Panel on Climate Change (IPCC) was set up in 1988 to assess information on climate change and its impact. Its Third Assessment Report predicts global temperature rises by 2100 of between 1.4°C and 5.8°C. Although the issue of the changing climate is very complex and some changes are uncertain, temperature rises are expected to affect countries throughout the world and have a knock-on effect with sea-level rises.Scientists have argued about whether temperature rises are due to human activities or due to natural changes in our environment. The IPCC announced in 2001 that "most of the warming observed over the last 50 years is likely to be attributable to human activities". This was a more forceful statement than in 1996 when the Second Assessment Report stated that there was a "discernible human influence on the climate" which was the first time they had concluded such a link. Many experts believe the faster the climate changes, the greater the risk will be.Key points of the projections for climate change globally include that by the second half of the 21st century, wintertime rainfall in the northern mid to high latitudes and Antarctica will rise, that meanwhile Australia, Central America and southern Africa are likely to see decreases in autumn precipitation, that some land areas in the tropics will see more rainfall, and that there will generally be more hot days over land areas.

According to the passage, a Chinese city that recorded 45 degrees Celsius at noon on August 4,2004, will most probably witness a temperature measuring ________at 12:00 sharp in the year of 2100.

A.46.1°C

B.1.4°C

C.5.8°C

D.a number that I do not know

问答题 简答题