Description

在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。现在我们封装一个“Point类”来实现平面上的点的操作。

根据“append.cc”,完成Point类的构造方法和接口描述中的方法和函数。

接口描述:
showPoint()函数:按输出格式输出Point对象。
Point::show()方法:按输出格式输出Point对象。
Point::showSumOfPoint()方法:按格式输出程序运行至当前存在过的Point对象总数。
Point::x()方法:取x坐标。
Point::y()方法:取y坐标。
Point::x(double)方法:传参数设置x坐标并返回。
Point::y(double)方法:传参数设置y坐标并返回。
Point::setPoint(double,double)方法:设置Point对象的x坐标(第一个参数)和y坐标(第二个参数)并返回本对象。
Point::isEqual()方法:判断传入的参数与对象的坐标是否相同,相同返回true。
Point::copy()方法:传参数复制给对象。
Point::inverse()方法,有两个版本:不传参数则将对象自身的x坐标和y坐标互换;若将Point对象做参数传入,则将传入对象的坐标交换复制给对象自身,不修改参数的值。

Input

输入多行,每行为一组坐标“x,y”,表示点的x坐标和y坐标,x和y的值都在double数据范围内。

Output

用ShowPoint()函数来输出(通过参数传入的)Point对象的值或坐标值:X坐标在前,Y坐标在后,Y坐标前面多输出一个空格。每个坐标的输出精度为最长16位。
对每个Point对象,调用show()方法输出其值,输出格式与ShowPoint()函数略有不同:“Point[i] :”,i表示这是程序运行过程中第i个被创建的Point对象。
调用showSumOfPoint()输出Point对象的计数统计,输出格式见sample。

C语言的输入输出被禁用。

Sample Input

1,2
3,3
2,1

Sample Output

Point[3] : (1, 2)
Point[1] : (2, 1)
Point[4] : (3, 3)
Point[1] : (3, 3)
Point[5] : (1, 2)
Point[1] : (1, 2)
Point[2] : (0, 0)
==========gorgeous separator==========
Point[2] : (-7, 5)
Point[3] : (1, 2)
Point[4] : (3, 3)
Point[5] : (1, 2)
Point[6] : (-7, 5)
==========gorgeous separator==========
Point[63] : (3, 3)
Point : (3, 3)
Point : (3, 3)
Point : (3, 3)
In total : 64 points.

HINT

给函数正确的返回值。注意常量对象调用的函数。

Append Code

int main()
{
    int l(0);
    char c;
    double a, b;
    Point p, q, pt[60];
    while(std::cin>>a>>c>>b)
    {
        if(a == b)
            p.copy(pt[l].setPoint(a, b));
        if(a > b)
            p.copy(pt[l].setPoint(a, b).inverse());
        if(a < b)
            p.inverse(pt[l].setPoint(a, b));
        if(a < 0)
            q.copy(p).inverse();
        if(b < 0)
            q.inverse(p).copy(pt[l]);
        pt[l++].show();
        p.show();
    }
    q.show();
    cout<<"==========gorgeous separator=========="<<endl;
    double x(0), y(0);
    for(int i = 0; i < l; i++)
        x += pt[i].x(), y -= pt[i].y();
    pt[l].x(y), pt[l].y(x);
    q.copy(pt[l]).show();
    for(int i = 0; i <= l; i++)
        pt[i].show();
    cout<<"==========gorgeous separator=========="<<endl;
    const Point const_point(3, 3);
    const_point.show();
    for(int i = 0; i <= l; i++)
    {
        if(const_point.isEqual(pt[i]))
        {
            ShowPoint(const_point);
            ShowPoint(const_point.x(), const_point.y());
            ShowPoint(Point(const_point.x(), const_point.y()));
        }
    }
    const_point.showSumOfPoint();
}
 
代码
#include <iostream>
#include <iomanip>
using namespace std;
class Point
{

double m,n;
    int count;
    static int sum;
public :

friend void ShowPoint(Point);
    friend void ShowPoint(double, double);

void show()const
    {
        cout<<setprecision(16)<<"Point["<<count<<"] : ("<<m<<", "<<n<<")"<<endl;
    }
    double x(double a)
    {
        m = a;
        return a;

}
    double y(double b)
    {
        n = b;
        return b;
    }
    double x()const
    {
        return m;
    }
    double y()const
    {

return n;
    }
    Point  &setPoint(double a,double b)
    {
        m=a;
        n=b;
        return *this;
    }void showSumOfPoint()const
    {
        cout << "In total : " <<sum << " points." << endl;
    }
    Point(double a,double b)
    {

m = a;
        n = b;
        sum++;
        count =sum;
    }
    Point():m(0),n(0)
    {
        sum++;
        count =sum;
    }
    Point (Point p)
    {
        setPoint(p.getx(),p.gety());
        return *this;
    }
    Point& inverse()
    {
        double temp=m;
        m=n;
        n=temp;
        return *this;
    }
    Point& inverse(Point p)
    {

m=p.n;
        n=p.m;
        return *this;
    }
    double getx()
    {
     return this->m;
    }
    double gety()
    {
     return this->n;
    }

bool isEqual(const Point &p)const
    {
        if(p.m == m && p.n == n)
            return true;
        return false;
    }

};
void ShowPoint(Point p)
{
    cout<<std::setprecision(16)<<"Point : ("<< p.x() <<", "<< p.y() <<")"<<endl;
}
void ShowPoint(double a,double b)
{
    cout<<std::setprecision(16)<<"Point : ("<<a<<", "<<b<<")"<<endl;
}
int Point::sum = 0;
int main()
{
    int l(0);
    char c;
    double a, b;
    Point p, q, pt[60];
    while(std::cin>>a>>c>>b)
    {
        if(a == b)
            p.copy(pt[l].setPoint(a, b));
        if(a > b)
            p.copy(pt[l].setPoint(a, b).inverse());
        if(a < b)
            p.inverse(pt[l].setPoint(a, b));
        if(a < 0)
            q.copy(p).inverse();
        if(b < 0)
            q.inverse(p).copy(pt[l]);
        pt[l++].show();
        p.show();
    }
    q.show();
    cout<<"==========gorgeous separator=========="<<endl;
    double x(0), y(0);
    for(int i = 0; i < l; i++)
        x += pt[i].x(), y -= pt[i].y();
    pt[l].x(y), pt[l].y(x);
    q.copy(pt[l]).show();
    for(int i = 0; i <= l; i++)
        pt[i].show();
    cout<<"==========gorgeous separator=========="<<endl;
    const Point const_point(3, 3);
    const_point.show();
    for(int i = 0; i <= l; i++)
    {
        if(const_point.isEqual(pt[i]))
        {
            ShowPoint(const_point);
            ShowPoint(const_point.x(), const_point.y());
            ShowPoint(Point(const_point.x(), const_point.y()));
        }
    }
    const_point.showSumOfPoint();
}

Problem F: 平面上的点——Point类 (VI)的更多相关文章

  1. Problem E: 平面上的点和线——Point类、Line类 (V)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...

  2. Problem D: 平面上的点和线——Point类、Line类 (IV)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...

  3. Problem C: 平面上的点和线——Point类、Line类 (III)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...

  4. Problem B: 平面上的点和线——Point类、Line类 (II)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...

  5. Problem A: 平面上的点和线——Point类、Line类 (I)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...

  6. Problem E: 平面上的点——Point类 (V)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...

  7. Problem D: 平面上的点——Point类 (IV)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...

  8. Problem C: 平面上的点——Point类 (III)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...

  9. Problem B: 平面上的点——Point类 (II)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...

随机推荐

  1. ASP.NET页面之间传值的方式之QueryString(个人整理)

    QueryString Querystring也叫查询字符串,这种页面间传递数据是利用网页地址URL.如果要从A页面跳转到B页面,则可以用Request.Redirect(”B.aspx?参数名=参数 ...

  2. Windbg程序调试系列1-常用命令说明&示例

    Windbg程序调试是.Net高级开发需要掌握的必备技能,分析内存泄露.分析高CPU.分析线程阻塞.分析内存对象.分析线程堆栈.Live Dedugging.这个领域可以说一个技能+场景化应用的结合, ...

  3. PHP函数------parse_ini_file()

    1.parse_ini_file()函数用于解析一个配置文件,并以数组的形式返回其中的设置. 举例说明:group.ini文件,文件内容如下: 0 = "Hleducation" ...

  4. spring quartz执行两次问题

    解决quartz定时任务被触发两次的问题: 其中<Host/>告诉tomcat,在启动的时候加载webapps下的所有项目工程文件,<Context/>又让tomcat再加载了 ...

  5. Docker Kubernetes 命令行创建容器

    Docker Kubernetes 命令行创建容器 环境: 系统:Centos 7.4 x64 Docker版本:18.09.0 Kubernetes版本:v1.8 管理节点:192.168.1.79 ...

  6. linux的必知必会规则

  7. 剑指offer(35)数组中的逆序对

    题目描述 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数P.并将P对1000000007取模的结果输出. 即输出P%1000 ...

  8. flask --- 03 .特殊装饰器, CBV , redis ,三方组件

    一.特殊装饰器(中间件) 1.before_request 在请求进入视图函数之前 @app.before_request def look(): 2. after_request 在结束视图函数之后 ...

  9. strcpy函数解析

    char * strcpy( char *strDest, const char *strSrc ) { assert((strDest != NULL)&&(strSrc != NU ...

  10. mac系统删除.DS_Store文件

    查找某目录下某类文件 find . -name ".DS_Store" -type f -print # find: 主命令 # . : 当前目录下(可变) # -name: 通过 ...