#include<iostream>
using namespace std;
class Point
{
public:
Point()
{
len=0;
width=0;
}
Point(float len,float width):len(len),width(width)
{
}
void printInfor()
{
cout<<"len:"<<len<<endl<<"width:"<<width<<endl;
}
void setLen(float len)
{
this->len=len;
}
void setWidth(float width)
{
this->width=width;
}
float getLen()
{
return len;
}
float getWidth()
{
return width;
}
private:
float len;
float width;
};
class Rectangle
{
private:
float len;
float width;
public:
Rectangle()
{
len=0;
width=0;
}
Rectangle(float len,float width):p(len,width)
{
}
void printInfor()
{
p.printInfor();
}
void Area(float len,float width)
{
float area;
area=len*width;
cout<<"Area:"<<area;
}
~Rectangle()
{
}
void setP(float len,float width)//将值传到point类里
{
p.setLen(len);
p.setWidth(width);
}
void setNewL(float Newlen)
{
len=Newlen;
p.setLen(len);
}
void setNewW(float Newwidth)
{
width=Newwidth;
p.setWidth(width);
}
Point getP()
{
return p;
}
float getNewL()
{
return len;
}
float getNewW()
{
return width;
}
private:
Point p;
};
int main()
{
float len,width;
float a,b;
cout<<"输入长宽:";
cin>>a>>b;
Rectangle r1;
r1.printInfor() ;
r1.setP(a,b);//传值
r1.printInfor() ;
r1.Area(a,b);//求面积
cout<<endl;
cout<<"输入长宽:";
cin>>a>>b;
r1.setNewL(a);
r1.setNewW(b);
r1.printInfor();
r1.Area(a,b);
return 0;
using namespace std;
class Point
{
public:
Point()
{
len=0;
width=0;
}
Point(float len,float width):len(len),width(width)
{
}
void printInfor()
{
cout<<"len:"<<len<<endl<<"width:"<<width<<endl;
}
void setLen(float len)
{
this->len=len;
}
void setWidth(float width)
{
this->width=width;
}
float getLen()
{
return len;
}
float getWidth()
{
return width;
}
private:
float len;
float width;
};
class Rectangle
{
private:
float len;
float width;
public:
Rectangle()
{
len=0;
width=0;
}
Rectangle(float len,float width):p(len,width)
{
}
void printInfor()
{
p.printInfor();
}
void Area(float len,float width)
{
float area;
area=len*width;
cout<<"Area:"<<area;
}
~Rectangle()
{
}
void setP(float len,float width)//将值传到point类里
{
p.setLen(len);
p.setWidth(width);
}
void setNewL(float Newlen)
{
len=Newlen;
p.setLen(len);
}
void setNewW(float Newwidth)
{
width=Newwidth;
p.setWidth(width);
}
Point getP()
{
return p;
}
float getNewL()
{
return len;
}
float getNewW()
{
return width;
}
private:
Point p;
};
int main()
{
float len,width;
float a,b;
cout<<"输入长宽:";
cin>>a>>b;
Rectangle r1;
r1.printInfor() ;
r1.setP(a,b);//传值
r1.printInfor() ;
r1.Area(a,b);//求面积
cout<<endl;
cout<<"输入长宽:";
cin>>a>>b;
r1.setNewL(a);
r1.setNewW(b);
r1.printInfor();
r1.Area(a,b);
return 0;
}