悬赏 求一个C++编程题!

来源:百度知道 编辑:UC知道 时间:2024/09/24 18:26:39
定义并实现一个矩形类,有长、宽两个属性,用成员函数计算其面积

#include <iostream>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
class Rectangle
{
private:
double Length;
double Width;
public:
double Area(double ,double);

};
double Rectangle::Area(double a,double b)
{
return (a*b);
}

void main()
{
double len;
double width;
cout<<"输入长:";
cin>>len;
cout<<"输入宽:";
cin>>width;
Rectangle Rtg;
cout<<"面积为:"<<Rtg.Area(len,width)<<endl;
}

#include <iostream>

class Rancle
{
private:
float length;
float width;
public:
Rancle(float l,float w)
{
length=l;
width=w;
}
float area()
{
return width*length;
}
};

void main()
{
float l,w;
printf("请输入长与宽:\n"