问题 问答题

【说明】
①在类体中添加函数move(double ax,double ay)的定义,使得点的坐标x和y分别移动 ax和ay个单位。
②在类定义外完成重载的两个构造函数CPosition()和CPosition(double dx,double dy),其中前者为不带参数的构造函数,使CPosition对象的默认值为x=0,y=0,后者为带参数的构造函数,把数据成员x和y分别初始化为参数dx和dy的值。
③完成函数double distance(double bx,double by)的定义,该函数返回*this和点(bx, by)的距离。
注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。
源程序文件test5.cpp清单如下:
#include<iostream.h>
#include<math.h>
class CPosition

public:
CPosition();
CPosition(double dx,double dy);
double getx();
double gety();
(1)
double distance(double bx,double by);
private:
double x;
double y;

(2)

x=0;y=0;

CPosition::CPosition(doub,e dx,doub,e dy)

x=dx; y=dy;

double CPosition::getx()

return x;

double CPosition::gety()

return y;

double CPosition::distance(double bx,double by)

(3)

vold main()

double a,b;
cout<<"|nput x,y position of a point:";
cin >> a >> b;
CPosition psA(a,b);
cout<<"Input x,y position of another point:";
cin >>a >> b;
cout <<"The distance is" <<psA.distance(a,b) <<end1;

答案

参考答案:(1)void move(double ax,double ay){x+=ax;y+ =ay;};
(2)CPosition::CPosition() (3)return sqrt(pow(x-bx, 2)+pow(y-by,2));

解析: 本题主要考查考生对于类的定义和重载构造函数的掌握情况。在(3)中使用了基本的数学函数sqrt(x)求x的开方,pow(x,n)函数是求x的n次方。

阅读理解

Elephants are famous for their supposedly excellent memory. Now it seems that they are good at simple math too.

Researchers at the University of Tokyo have found an Asian elephant named Ashya can add small quantities together and correctly identify(识别)which is larger.

For example ,when researcher Naoko dropped three apples into one bucket and one apple into a second, then four more apples into the first and five into the second, Ashya correctly identified that the first bucket contained more apples and began munching(嚼)on her tasty prize.

Ashya chose the correct bucket 74% of the time "I even get confused when "I'm dropping the apple," Naoko told New Scientist magazine.

Elephants' counting abilities are far from unique. Chimps, pigeons(鸽子)and dolphins have shown the same abilities in lab tests, but what is more impressive for Elephants is that their ability to tell between two figures does not get worse when those numbers are more similar.

The elephants that Naoko tested were as good at telling the difference between five and six as they were at telling between five and one.

Naoko presented her findings last week at the International Society annual meeting in New York.

It is not obvious why elephants should need this mathematical ability in the wild." It is really tough to figure out why elephants would need to count," said Mya, a professor at Cornell University who studies elephants.

One possibility is that they use it to keep track of other members of their herd(兽群)so that no one is left behind. Asian elephants live in groups of six to eight." You really don't want to lose your group members," said Mya.

Another possibility is that the ability for simple math might be a by-product(副产品)of natural selection for a larger brain.

68.The experiments researchers have done recently show that elephants can____.

A. memorize things correctly      B. munch on apples

C. do some simple math          D. change small quantities into larger ones

69.What does the underlined word" tough" in Paragraph 8 mean?

A. Difficult        B. Impossible     C. Easy      D. Useful

70.The reason why elephants need to count is possibly that_____.

A. they want to exercise their brains

B .they often count the members of their herd

C. they hope to stay in groups

D. they have taken regular training

单项选择题