| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1759 人关注过本帖
标题:[求助]请高手运行一下看看这个程序错在哪里
只看楼主 加入收藏
好学
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
帖 子:622
专家分:318
注 册:2004-5-4
结帖率:50%
收藏
 问题点数:0 回复次数:2 
[求助]请高手运行一下看看这个程序错在哪里
class point{ float x,y; public: Point(float a=0,float b=0){x=a;y=b} void SetP(float a=0,float b=0){x=a;y=b} void Display(){cout<<"位置是:("<<x<<","<<y<<")\n";} }; class Circle:public Point{ float r; public: Circle(float z=1,float x=0,float y=0){r=z;} void SetC(float z=1,float x=0,float y=0){r=z;SetP(x,y);} void Print() { cout<<"圆的"; Display(); cout<<"圆的半径是:"<<r<<endl; } }; void main() { Circle a(3.2); a.Print(); a.SetC(6,8,2); a.Print(); }
搜索更多相关主题的帖子: float void 
2004-06-16 21:02
C++大粉丝
Rank: 4
等 级:贵宾
威 望:10
帖 子:477
专家分:0
注 册:2004-4-23
收藏
得分:0 

.....好多错误

#include <iostream> using std::cout; using std::endl; class Point{ float x,y; public: Point(float a=0,float b=0) { x=a; y=b; } void SetP(float a=0,float b=0){x=a,y=b;} void Display(){cout<<"位置是:("<<x<<","<<y<<")\n";} }; class Circle:public Point{ float r; public: Circle(float z=1,float x=0,float y=0){r=z;} void SetC(float z=1,float x=0,float y=0){r=z;SetP(x,y);} void Print() { cout<<"圆的"; Display(); cout<<"圆的半径是:"<<r<<endl; } }; void main() { Circle a(3,2); a.Print(); a.SetC(6,8,2); a.Print(); }


I am a big fan of c plus plus.
2004-06-16 21:39
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 

我想提个建议,把代码写在一行,我认为是个不好的习惯,造成检查错误的困难。

虽然这样可以使代码看上去短一些,通常在一些书籍中会这样打印,他们这样做的目的是使代码尽可能的在一叶內打印完,使得读者看代码有一个连续性。

不过我们就没必要这样做。请每行只写一句语句,也就是说,分号之后一定换行。这样做的好处是调试时,在每一句执行后都可有停顿,这样每个变量都可互不影响的观察到。

#include <iostream> using namespace std;

class Point { float x,y; public: Point(float a=0,float b=0) { x=a; y=b; } void SetP(float a=0,float b=0) { x=a; y=b; } void Display() { cout<<"λÖÃÊÇ£º£¨"<<x<<"£¬"<<y<<"£©\n"; } }; class Circle:public Point { float r; public: Circle(float z=1,float x=0,float y=0) { r=z; } void SetC(float z=1,float x=0,float y=0) { r=z; SetP(x,y); } void Print() { cout<<"Ô²µÄ"; Display(); cout<<"Ô²µÄ°ë¾¶ÊÇ£º"<<r<<endl; } }; int main() { Circle a(3.2f); a.Print(); a.SetC(6,8,2); a.Print(); return 0; }


自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2004-06-17 23:37
快速回复:[求助]请高手运行一下看看这个程序错在哪里
数据加载中...
 
   



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

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