怎么用C++编程长方形面积,要求用类编?
#include <iostream.h>
class cfx
{
float s,a,b;
public:
cfx(float x, float y)
{
s=0;
a=x;
b=y;
}
void mianji()
{
s=a*b;
}
void display()
{
cout<<"长方形的面积是:"<<s<<endl;
}
};
void main()
{
float x,y;
cout<<"输入长和宽:";
cin>>x;
cin>>y;
cfx obj(x ,y);
obj.mianji();
obj.display();
}