65,211
社区成员
发帖
与我相关
我的任务
分享#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;
}#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;
}
#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;
}