#include<iostream>
using namespace std;
class Rectangle
{
private:
double length;
double width;
public:
Rectangle(double l, double w)
{
this->length = l;
this->width = w;
}
Rectangle(Rectangle & r)
{
cout << "拷贝构造函数:";
length = r.length;
width = r.width;
}
~Rectangle()
{
cout << "析构函数" << "\n";
}
void get();
void input();
double RArea();
double RCircumference();
};
void Rectangle::input()
{
double l, w;
cout << "请分别输入矩形的长和宽:";
cin >> l >> w;
length = l;
width = w;
}
void Rectangle::get()
{
cout << "长为" << length << "\t宽为" << width << "的矩形\n";
}
double Rectangle::RArea()
{
double area = 0;
area = length * width;
return area;
}
double Rectangle::RCircumference()
{
double Circumference = 0;
Circumference = 2 * (length + width);
return Circumference;
}
void main()
{
Rectangle r1(6.7, 8.6);
Rectangle r2(12.13,13.14);
r1.get();
cout << "面积为:" << r1.RArea() << "\n";
cout << "周长为:" << r1.RCircumference() << "\n";
r2.input();
r2.get();
cout << "面积为:" << r2.RArea() << "\n";
cout << "周长为:" << r2.RCircumference() << "\n";
system("pause");
}
Last modification:December 5th, 2018 at 07:04 pm
© 允许规范转载