| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 696 人关注过本帖
标题:新手C++求助,此程序有点错误求,高手帮忙改下或者帮忙写个,小弟在这感激不尽 ...
取消只看楼主 加入收藏
chenbccn
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-6-26
结帖率:100%
收藏
已结贴  问题点数:16 回复次数:3 
新手C++求助,此程序有点错误求,高手帮忙改下或者帮忙写个,小弟在这感激不尽啊...
题目要求:
       用c++建立一个二维坐标系的类TwoCoor,用x、y表示坐标值,实现两坐标点的加、减运算,计算两坐标点间的距离,并重载输入/输出运算符,使之能够直接输入/输出坐标点的坐标值.
运行环境VC6.0或CodeBlocks
下面是我在网上找的代码,有几个错误,但不会修改.......
程序代码:
#include<iostream>
#include<cmath>
using namespace std;
class TwoCoor
{
private:
    double x,y;
public:
    TwoCoor(double X=0,double Y=0):x(X),y(Y) {};
    friend TwoCoor operator+(TwoCoor p1,TwoCoor p2);
    friend TwoCoor operator-(TwoCoor p1,TwoCoor p2);
    friend       double  dist(TwoCoor p1,TwoCoor p2);
    friend TwoCoor &operator<<(ostream &os,TwoCoor &t);
    friend TwoCoor &operator>>(istream &is,TwoCoor &t);
};
TwoCoor operator+(TwoCoor p1,TwoCoor p2)
{
    return TwoCoor(p1.x+p2.x,p1.y+p2.y);
}
TwoCoor operator-(TwoCoor p1,TwoCoor p2)
{
    return TwoCoor(p1.x-p2.x,p1.y-p2.y);
}
double  dist(TwoCoor p1,TwoCoor p2)
{
    double x=(p1.x-p2.x);
    double y=(p1.y-p1.y);
    return sqrt(x*x+y*y);
}
TwoCoor &operator<<(ostream &os,TwoCoor &t)
{
    os<<"\t"<<t.x<<"\t";
    os<<t.y<<endl;
    return t;
}
TwoCoor &operator>>(istream &is,TwoCoor &t)
{
    cout<<"坐标点的横坐标:";
    is>>t.x;
    cout<<"坐标点的纵坐标:";
    is>>t.y;
    return t;
}
int main()
{
    TwoCoor t1,t2;
    char select;
    while(1)
    {
        cout<<"------------------坐标点计算系统-----------------------"<<endl;
        cout<<"         0            计算两坐标点对应坐标之和         "<<endl;
        cout<<"         1            计算两坐标点对应坐标之差         "<<endl;
        cout<<"         2            计算两坐标点的距离               "<<endl;
        cout<<"         3            退出系统                         "<<endl;
        cout<<"*******************************************************"<<endl;
        cout<<"请输入你的选择:";
        cin>>select;
        if(select=='0')
        {
            cout<<"请输入坐标点1的坐标:"<<endl;
            cin>>t1;
            cout<<"---------------------------------------"<<endl;
            cout<<"\t"<<"横坐标"<<"\t"<<"纵坐标"<<endl;
            cout<<"点1";
            cout<<t1;
            cout<<"---------------------------------------"<<endl;
            cout<<"请输入坐标点2的坐标:"<<endl;
            cin>>t2;
            cout<<"---------------------------------------"<<endl;
            cout<<"\t"<<"横坐标"<<"\t"<<"纵坐标"<<endl;
            cout<<"点2";
            cout<<t2;
            cout<<"---------------------------------------"<<endl;
            cout<<"\t"<<"\t"<<"\t"<<"\t"<<"横坐标"<<"\t"<<"纵坐标"<<endl;
            cout<<"两坐标点的对应坐标相加为:"<<operator+(t1,t2);
        }
        else if(select=='1')
        {
            cout<<"请输入坐标点1的坐标:"<<endl;
            cin>>t1;
            cout<<"---------------------------------------"<<endl;
            cout<<"\t"<<"横坐标"<<"\t"<<"纵坐标"<<endl;
            cout<<"点1";
            cout<<t1;
            cout<<"---------------------------------------"<<endl;
            cout<<"请输入坐标点2的坐标:"<<endl;
            cin>>t2;
            cout<<"---------------------------------------"<<endl;
            cout<<"\t"<<"横坐标"<<"\t"<<"纵坐标"<<endl;
            cout<<"点2";
            cout<<t2;
            cout<<"---------------------------------------"<<endl;
            cout<<"\t"<<"\t"<<"\t"<<"\t"<<"横坐标"<<"\t"<<"纵坐标"<<endl;
            cout<<"两坐标点的对应坐标相减为:"<<operator-(t1,t2);
        }
        else if(select=='2')
        {
            cout<<"请输入坐标点1的坐标:"<<endl;
            cin>>t1;
            cout<<"---------------------------------------"<<endl;
            cout<<"\t"<<"横坐标"<<"\t"<<"纵坐标"<<endl;
            cout<<"点1";
            cout<<t1;
            cout<<"---------------------------------------"<<endl;
            cout<<"请输入坐标点2的坐标:"<<endl;
            cin>>t2;
            cout<<"---------------------------------------"<<endl;
            cout<<"\t"<<"横坐标"<<"\t"<<"纵坐标"<<endl;
            cout<<"点2";
            cout<<t2;
            cout<<"---------------------------------------"<<endl;
            cout<<"两坐标点的距离为:"<<dist(t1,t2)<<endl;
        }
        else if(select=='3')
            exit(0);
        else
        {
            cout<<"输入错误,请重新输入"<<endl;
            continue;
        }

    }
}


求哪位好心人帮忙改一下,或者帮忙写一个,小弟在这感激不尽啊.......
水贴的就不要来了。。。。。。。
搜索更多相关主题的帖子: 运行环境 坐标系 网上 
2013-06-29 22:33
chenbccn
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-6-26
收藏
得分:0 
回复 2楼 peach5460
你又来水贴了........
2013-06-30 08:30
chenbccn
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-6-26
收藏
得分:0 
回复 5楼 peach5460
下面是我上次发帖时他来水,我回复的
回复 3楼 peach5460
不知者无罪,作为新人第一次发帖,难免出错,而你身为资深版主却不依不饶,我只能说国人的道德因你倒退了20年
上次帖子的地址:https://bbs.bccn.net/thread-416118-1-1.html
虽然我初次来次论坛,但不能不说peach5460就是水贴的,,
阿弥陀佛,罪过罪过,我不想骂人,所以请你peach5460注意一下你的言行!!!!!
2013-06-30 22:18
chenbccn
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-6-26
收藏
得分:0 
回复 8楼 peach5460
如你所愿,此论坛,我将永久退出,别的我也不多说了。。。。。。
2013-07-03 13:28
快速回复:新手C++求助,此程序有点错误求,高手帮忙改下或者帮忙写个,小弟在这感 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015608 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved