65,186
社区成员




#include<iostream>
using namespace std;
class Ellipse
{
private:
int a,b;
public:
Ellipse(int _a,int _b):a(_a),b(_b){ //使用构造函数对类的成员进行初始化
};
float Area1() //应该放回float变量
{
return 3.14*a*b;
};
};
class Rectangle
{
private:
int x,y;
public:
Rectangle(int _x,int _y):x(_x),y(_y) { //使用构造函数对类的成员进行初始化
};
int Area2()
{
return x*y;
};
};
int main()
{
float f,i,j;
Ellipse m(50,75);
Rectangle n(200,150);
i=m.Area1();
j=n.Area2();
f=2*i*250+(j-i)*0.5;
cout<<"总费用为:"<<f<<endl;
return 0;
}
int Area1(int,int)//函数定义的时候必须带上变量名,不然怎么用??声明可以不用
{
return 3.14*a*b;
};
#include<iostream>
using namespace std;
class Ellipse
{
private:
int a,b;
public:
Ellipse(int _a,int _b):a(_a),b(_b){ //使用构造函数对类的成员进行初始化
};
int Area1()
{
return 3.14*a*b;
};
};
class Rectangle
{
private:
int x,y;
public:
Rectangle(int _x,int _y):x(_x),y(_y) { //使用构造函数对类的成员进行初始化
};
int Area2()
{
return x*y;
};
};
int main()
{
float f,i,j;
Ellipse m(50,75);
Rectangle n(200,150);
i=m.Area1();
j=n.Area2();
f=2*i*250+(j-i)*0.5;
cout<<"总费用为:"<<f<<endl;
return 0;
}