class cuboid
{
public:
cuboid(int len, int wid, int hig)
{
m_len = len;
m_wid = wid;
m_hig = hig;
}
~cuboid() {};
void getVolume()
{
cout << "体积为:" << m_len * m_wid * m_hig << endl;
}
private:
int m_len, m_wid, m_hig;
};
class Animal
{
public:
Animal(string name, int weight)
{
m_name = name;
m_weight = weight;
}
~Animal() {};
void who()
{
cout << "name = " << m_name << " weight = " << m_weight << endl;
}
private:
string m_name;
int m_weight;
};
class Lion :public Animal
{
public:
Lion(string name, int weight) :Animal(name, weight)
{
}
~Lion() {};
};
class Crocodile :public Animal
{
public:
Crocodile(string name, int weight) :Animal(name, weight)
{
}
~Crocodile() {};
};
class rect
{
public:
rect(int len, int wid)
{
m_len = len;
m_wid = wid;
}
~rect() {};
void getArea()
{
cout << "面积为:" << m_len * m_wid << endl;
}
private:
int m_len, m_wid;
};
int main()
{
//第一问
cuboid cub(5, 4, 3);
cub.getVolume();
//第二问
Lion lion("Leo", 400);
Crocodile cor("Algernon", 50);
lion.who();
cor.who();
//第三问
rect rec(10, 20);
rec.getArea();
return 0;
}
不过看你应该还是学生,建议你遇到问题还是需要自己多想一想。