#include<iostream>
using namespace std;
class Rectangle
{
private:
double len,wid;
public:
Rectangle()
{
len=10;
wid=10;
}
double circ()
{
return (len+wid)*2;
}
double area()
{
return len*wid;
}
void display()
{
cout<<"周长是:"<<circ()<<"\n"<<"面积是:"<<area()<<endl;
}
};
void main()
{
Rectangle r1,r2;
r1.display();
r2.display();
}
using namespace std;
class Rectangle
{
private:
double len,wid;
public:
Rectangle()
{
len=10;
wid=10;
}
double circ()
{
return (len+wid)*2;
}
double area()
{
return len*wid;
}
void display()
{
cout<<"周长是:"<<circ()<<"\n"<<"面积是:"<<area()<<endl;
}
};
void main()
{
Rectangle r1,r2;
r1.display();
r2.display();
}
无参构造函数,由类生成对象时不用设定实参