标题:刚学类,有个题目不懂,请帮忙解决!
取消只看楼主
不走寻常路
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2005-9-26
 问题点数:0 回复次数:1 
刚学类,有个题目不懂,请帮忙解决!

题目是:做一个矩形的类,输入长度和宽度,然后求出面积. #include <iostream> using namespace std; class Rectangle //矩形类 { public: Rectangle(float w,float l);

float Area();

private: float width,length; }; //类的实现

Rectangle::Rectangle(float w,float l) {width=w;length=l;}

float Rectangle::Area() { return width*length; } //主函数实现 void main() { float width,length;

Rectangle a(width,length);

cout<<"please enter the length and width of the rectangle:"<<endl;

cin >> width >> length;

cout<<"The rectangle's area is "<<a.Area()<<endl; } 在用圆类的时候,就是只有一个参数的时候就可以得到结果,但是这有两个参数的时候,编译有两个 warning: local variable'length' used without having been initialized和 local variable 'width' used without having been initialized 不懂这是怎么回事,帮我改正一下吧,谢谢!!!

[此贴子已经被作者于2005-10-18 13:08:36编辑过]

搜索更多相关主题的帖子: float Rectangle length Area 
2005-10-18 13:06
不走寻常路
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2005-9-26
得分:0 
病急乱投医了,作业嘛!呵呵,谢了!!

学C不长,但很喜欢,梦想能成为编程一族! qq: 83461951 欢迎来指教!
2005-10-19 13:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-30519-1-1.html




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

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