修改一段小代码

chenShuyuNO1 2008-11-15 02:48:26
#include<iostream>
using namespace std;
class Rectangle
{
public :
Rectangle(double NewL,double NewW);
double Area();
private:
double Lenth;
double Width;
}
Rectangle::Rectangle(double NewL=0,double NewW=0)
{
Lenth=NewL;
Width=NewW;
}
double Rectangle::Area()
{
return Lenth*Width;
}
int main()
{
double Lenth;double Width;
cout<<"请输入矩形的长:";
cin>>Lenth;
cout<<"请输入矩形的宽:";
cin>>Width;
Rectangle mytangle(0, 0);
mytangle.Area();
cout<<"矩形的面积为:"<<mytangle.Area()<<endl;
return 0;
}我调试的时候总是出现'Rectangle::Rectangle' : error in function definition or declaration; function not called,这条语句帮忙修改一下.谢谢各位拉
...全文
73 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cui22698 2008-11-15
  • 打赏
  • 举报
回复
楼上几位的做法是对的,
1、要记住在定义类或者结构结束时不要忘记“;”
2、Rectangle mytangle(0, 0)=》Rectangle mytangle(Lenth, Width);
jia_xiaoxin 2008-11-15
  • 打赏
  • 举报
回复
#include <iostream> 
using namespace std;
class Rectangle
{
public :
Rectangle(double NewL=0,double NewW=0); //只能在声明中使用默认参数
double Area();
private:
double Lenth;
double Width;
}; //少了;号
Rectangle::Rectangle(double NewL,double NewW)
{
Lenth=NewL;
Width=NewW;
}
double Rectangle::Area()
{
return Lenth*Width;
}
int main()
{
double Lenth;double Width;
cout <<"请输入矩形的长:";
cin>>Lenth;
cout <<"请输入矩形的宽:";
cin>>Width;
Rectangle mytangle(0, 0);
mytangle.Area();
cout <<"矩形的面积为:" <<mytangle.Area() <<endl;
return 0;
}
zzq0406 2008-11-15
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;
class Rectangle
{
public :
Rectangle(double NewL=0,double NewW=0); //带默认值只能在类声明中使用
double Area();
private:
double Lenth;
double Width;
} ;
Rectangle::Rectangle(double NewL,double NewW)
{
Lenth=NewL;
Width=NewW;
}
double Rectangle::Area()
{
return Lenth*Width;
}
int main()
{
double Lenth;double Width;
cout <<"请输入矩形的长:";
cin>>Lenth;
cout <<"请输入矩形的宽:";
cin>>Width;
Rectangle mytangle(0, 0);
mytangle.Area();
cout <<"矩形的面积为:" <<mytangle.Area() <<endl;
return 0;
}
/////////////////////////////
1.带默认值只能在类声明中使用
2 .类后要带“;”。
zzq0406 2008-11-15
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;
class Rectangle
{
public :
Rectangle(double NewL=0,double NewW=0); //带默认值只能在类声明中使用
double Area();
private:
double Lenth;
double Width;
} ;
Rectangle::Rectangle(double NewL,double NewW)
{
Lenth=NewL;
Width=NewW;
}
double Rectangle::Area()
{
return Lenth*Width;
}
int main()
{
double Lenth;double Width;
cout <<"请输入矩形的长:";
cin>>Lenth;
cout <<"请输入矩形的宽:";
cin>>Width;
Rectangle mytangle(0, 0);
mytangle.Area();
cout <<"矩形的面积为:" <<mytangle.Area() <<endl;
return 0;
}
/////////////////////////////
1.带默认值只能在类声明中使用
2 .类后要带“;”。
太乙 2008-11-15
  • 打赏
  • 举报
回复
#include <iostream> 
using namespace std;
class Rectangle
{
public :
Rectangle(double NewL,double NewW);
double Area();
private:
double Lenth;
double Width;
} ;
Rectangle::Rectangle(double NewL=0,double NewW=0)
{
Lenth=NewL;
Width=NewW;
}
double Rectangle::Area()
{
return Lenth*Width;
}
int main()
{
double Lenth;double Width;
cout <<"请输入矩形的长:";
cin>>Lenth;
cout <<"请输入矩形的宽:";
cin>>Width;
Rectangle mytangle(0, 0);
mytangle.Area();
cout <<"矩形的面积为:" <<mytangle.Area() <<endl;
return 0;
}
weiyanno1 2008-11-15
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
class Rectangle
{
public :
Rectangle(double NewL,double NewW);
double Area();
private:
double Lenth;
double Width;
};
Rectangle::Rectangle(double NewL,double NewW)
{
Lenth=NewL;
Width=NewW;
}
double Rectangle::Area()
{
return Lenth*Width;
}
int main()
{
double Lenth;double Width;
cout<<"请输入矩形的长:";
cin>>Lenth;
cout<<"请输入矩形的宽:";
cin>>Width;
Rectangle mytangle(Lenth, Width);
mytangle.Area();
cout<<"矩形的面积为:"<<mytangle.Area()<<endl;
return 0;
}
weiyanno1 2008-11-15
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
class Rectangle
{
public :
Rectangle(double NewL,double NewW);
double Area();
private:
double Lenth;
double Width;
};
Rectangle::Rectangle(double NewL,double NewW)
{
Lenth=NewL;
Width=NewW;
}
double Rectangle::Area()
{
return Lenth*Width;
}
int main()
{
double Lenth;double Width;
cout<<"请输入矩形的长:";
cin>>Lenth;
cout<<"请输入矩形的宽:";
cin>>Width;
Rectangle mytangle(Lenth, Width);
mytangle.Area();
cout<<"矩形的面积为:"<<mytangle.Area()<<endl;
return 0;
}
tangshuiling 2008-11-15
  • 打赏
  • 举报
回复
类定义少个分号!
{
};

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧