/*
建立矩形类rectangle, 有私有数据成员为长方形宽度width
、高度height、面积area;
rectangle的构造函数有两个double型的参数,
分别传递矩形的宽度和高度,
同时,构造函数要完矩形面积的计算并存入area中;
在rectangle中包含一成员函数print(),
用来显示rectangle对象的宽度、高度和面积的值。
*/
#include <iostream>
using namespace std;
class rectangle{
public:
rectangle();
rectangle(double W,double H);
void print();
private:
double width;
double height;
double area;
};
int main()
{
rectangle test(3,2);
test.print();
return 0;
}
rectangle::rectangle(double W,double H){
width=W;
height=H;
area=W*H;
}
void rectangle::print()
{
cout << "Width=" << width << endl;
cout << "Height=" << height << endl;
cout << "Area=" << area << endl;
}
建立矩形类rectangle, 有私有数据成员为长方形宽度width
、高度height、面积area;
rectangle的构造函数有两个double型的参数,
分别传递矩形的宽度和高度,
同时,构造函数要完矩形面积的计算并存入area中;
在rectangle中包含一成员函数print(),
用来显示rectangle对象的宽度、高度和面积的值。
*/
#include <iostream>
using namespace std;
class rectangle{
public:
rectangle();
rectangle(double W,double H);
void print();
private:
double width;
double height;
double area;
};
int main()
{
rectangle test(3,2);
test.print();
return 0;
}
rectangle::rectangle(double W,double H){
width=W;
height=H;
area=W*H;
}
void rectangle::print()
{
cout << "Width=" << width << endl;
cout << "Height=" << height << endl;
cout << "Area=" << area << endl;
}