编写一个类Rectangle,有长itsLength,宽itsWidth等数据成员,有重载的构造函数Rectangle()、Rectangle(int width,int length)。

#include
using namespace std;

class Rectangle
{
public:
   Rectangle() {itsLength=10,itsWidth=5;}
   Rectangle(int length ,int width) {itsLength=length;itsWidth=width;}
   ~Rectangle() {}
   int GetLength() {return itsLength;}
   int GetWidth() {return itsWidth;}
private:
   int itsLength,itsWidth;
};

int main()
{
  Rectangle rect1;
  cout<<"Length: "<  cout<<"Width: "<     int length,width;
     cout<<"Enter the length:"<     cin>>length;
     cout<<"Enter the width:"<     cin>>width;
     Rectangle rect2(length,width);
     cout<<"The Length: "<     cout<<"The Width: "<}

你可能感兴趣的:(编写一个类Rectangle,有长itsLength,宽itsWidth等数据成员,有重载的构造函数Rectangle()、Rectangle(int width,int length)。)