class,用于保存2个表示x和y坐标的double值 [英] class to hold 2 double values representing the x and y coordinates

查看:80
本文介绍了class,用于保存2个表示x和y坐标的double值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的论文中有一个问题,我没有正确的答案,所以在这里我问任何可以提供帮助的人,给我一个合适的答案。

-------- ---------------------------

写一个名为Point的类,它包含两个表示x和y的double值图上点的坐标。提供以下内容:


1.一个合适的默认构造函数,它也可以将2个值中的一个或两个作为参数。默认值应为0.


2.成员函数get_x和get_y获取每个值。


3. Memeber函数set_x和set_y设置每个值。


4.重载输出运算符以格式输出Point:

(1.2,3.4)


5.成员函数长度返回点与原点的距离,即(0,0)。公式是sqrt(x2 + y2)。 (2是x和y的超级对象)

-----------------------------


这是我到目前为止完成的代码,但我可以完成函数长度(),我不确定我编码的所有内容是否正确。所以请帮助我.....

i have a question from my paper, which i dont have the correct answer, so here i asking anyone who can help, provide me the appropriate answer.
-----------------------------------
Write a class called Point that holds two double values representing the x and y coordinates of a point on graph. Provide the following:

1. A suitable default constructor that can also take one or both of the 2 values as arguments. Default values should be 0.

2. Member function get_x and get_y to get each of the values.

3. Memeber function set_x and set_y to set each of the values.

4. An overloaded output operator to output the Point in the format:
(1.2, 3.4)

5. A member function "length" to return the distance of the point from the origin, i.e.(0,0). The formula is the sqrt(x2 + y2). (2 is the supercase to x and y)
-----------------------------

Here is my code that i done so far, but i could finish the function length(), and i''m not sure everything i coded is correct. So please help me.....

展开 | 选择 | Wrap | 行号

推荐答案

讲师为您提供了公式用于计算距离。如果你假设你有有效的输入,你所要做的就是取y坐标this。点和另一个点并使用公式返回结果。
The instructor has provided you with the formula for calculating the distance. If you assume that you have valid input all you have to do is take the y coordinates of "this" point and another point and use the formula to return the result.


展开 | 选择 | 换行 | 行号


if function" length"是从原点返回点的距离,即(0,0)它应该返回一个double而不是一个Point ??,例如
if function "length" is to return the distance of the point from the origin, i.e.(0,0) it should return a double not a Point??, e.g.
展开 | 选择 | 换行 | 行号


这篇关于class,用于保存2个表示x和y坐标的double值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆