| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 886 人关注过本帖
标题:求解这个main函数的倒数第一和倒数第三行
取消只看楼主 加入收藏
Sornets
Rank: 2
等 级:论坛游民
帖 子:102
专家分:61
注 册:2012-11-22
结帖率:58.82%
收藏
已结贴  问题点数:19 回复次数:3 
求解这个main函数的倒数第一和倒数第三行
程序代码:
int main()
{
    int num, i;
    Point p(1, -2), q(2, -1), t;
    t.show();
    std::cin>>num;
    Line line[num];
    for(i = 0; i < num; i++)
    {
        line[i].readLine();
        line[i].show();
    }
    Line l1(p, q), l2(p,t), l3(q,t), l4(l1);
    l1.show();
    l2.setLine(l1).show();
    l3.show();
    l4.setLine(t,q).show();
}

这是我们oj上的一个题,大概就是构造类,输入输出点和线的。
但是最后X.f.f这里不明白要怎么实现了。
是要在函数里构造类吗?
PS:下面是我写的代码,还没有通过编译
程序代码:
#include <iostream>

using namespace std;
class Point
{
    public:
    double x,y;
    Point (double xx = 0,double yy = 0)
    {
        x = xx;y = yy;
        cout<<"Point : ("<<x<<", "<<y<<") is created."<<endl;
    }
    void show()
    {
        cout<<"Point : ("<<x<<", "<<y<<')'<<endl;
    }

};
class Line
{
    //double x1,x2,y1,y2;
    Point a,b;
public:
    Line ()
    {
        cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<") is created."<<endl;
    }
    Line (const Point &aa,const Point &bb)
    {
        Point aaa = aa,bbb = bb;
        a = aaa;b = bbb;
        cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<") is created."<<endl;
    }
    Line (const Line &q)
    {
        a = q.a; b = q.b;
        cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<") is created."<<endl;
    }
    void setLine(double x1, double y1, double x2, double y2)
    {
        a.x = x1; a.y = y1; b.x = x2 ;b.y = y2;
        cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<")"<<endl;
    }
    void setLine(const Point &p, const Point &q)
    {
        a.x = p.x; b.x = q.x; a.y = p.y; b.y = q.y;
        cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<")"<<endl;
    }
    void setLine(const Line &q)
    {
        a = q.a; b = q.b;
        cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<")"<<endl;
    }
    void readLine()
    {
        double x,y,xx,yy;
        cin>>x>>y>>xx>>yy;
        a.x = x; a.y = y; b.x = xx; b.y = yy;
        cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<")"<<endl;
    }
    void show()
    {
        cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<")"<<endl;
    }
};
int main()
{
    int num, i;
    Point p(1, -2), q(2, -1), t;
    t.show();
    std::cin>>num;
    Line line[num];
    for(i = 0; i < num; i++)
    {
        line[i].readLine();
        line[i].show();
    }
    Line l1(p, q), l2(p,t), l3(q,t), l4(l1);
    l1.show();
    l2.setLine(l1).show();
    l3.show();
    l4.setLine(t,q).show();
}
搜索更多相关主题的帖子: 倒数 
2013-06-09 17:59
Sornets
Rank: 2
等 级:论坛游民
帖 子:102
专家分:61
注 册:2012-11-22
收藏
得分:0 
程序代码:
#include <iostream>

using namespace std;
class Point
{
public:
    double x,y;
    Point (double xx = 0,double yy = 0)
    {
        x = xx;
        y = yy;
        cout<<"Point : ("<<x<<", "<<y<<") is created."<<endl;
    }
    void show()
    {
        cout<<"Point : ("<<x<<", "<<y<<')'<<endl;
    }

};
class Line
{
    //double x1,x2,y1,y2;
    Point a,b;
public:
    Line ()
    {
        cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<") is created."<<endl;
    }
    Line (const Point &aa,const Point &bb)
    {
        Point aaa = aa,bbb = bb;
        a = aaa;
        b = bbb;
        cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<") is created."<<endl;
    }
    Line (const Line &q)
    {
        a = q.a;
        b = q.b;
        cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<") is created."<<endl;
    }
    void setLine(double x1, double y1, double x2, double y2)
    {
        a.x = x1;
        a.y = y1;
        b.x = x2 ;
        b.y = y2;
        void show()
        {
            cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<")"<<endl;
        }
    }
    void setLine(const Point &p, const Point &q)
    {
        a.x = p.x;
        b.x = q.x;
        a.y = p.y;
        b.y = q.y;
        void show()
        {
            cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<")"<<endl;
        }
    }
    void setLine(const Line &q)
    {
        a = q.a;
        b = q.b;
        void show()
        {
            cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<")"<<endl;
        }
    }
    void readLine()
    {
        double x,y,xx,yy;
        cin>>x>>y>>xx>>yy;
        a.x = x;
        a.y = y;
        b.x = xx;
        b.y = yy;
        cout<<"Line : ("<<a.x<<", "<<a.y<<") to ("<<b.x<<", "<<b.y<<")"<<endl;
    }

};
int main()
{
    int num, i;
    Point p(1, -2), q(2, -1), t;
    t.show();
    std::cin>>num;
    Line line[num];
    for(i = 0; i < num; i++)
    {
        line[i].readLine();
        line[i].show();
    }
    Line l1(p, q), l2(p,t), l3(q,t), l4(l1);
    l1.show();
    l2.setLine(l1).show();
    l3.show();
    l4.setLine(t,q).show();
}

为什么这样就通不过编译了?我在每个setline函数里都加了个show函数,把show函数注释掉就通过编译了,但是好像没有什么语法错误。。
2013-06-09 18:08
Sornets
Rank: 2
等 级:论坛游民
帖 子:102
专家分:61
注 册:2012-11-22
收藏
得分:0 
回复 3楼 ww280666
这不是我写的main函数啊,是题目给的,所以我也是很不明白是怎么用的。
2013-06-15 09:16
Sornets
Rank: 2
等 级:论坛游民
帖 子:102
专家分:61
注 册:2012-11-22
收藏
得分:0 
回复 7楼 代号215
能不能麻烦把代码写一下?我大概明白是怎么个意思了,但是要写出来还是不太可能,百度也没百度到。。
2013-06-16 19:36
快速回复:求解这个main函数的倒数第一和倒数第三行
数据加载中...
 
   



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

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