C++题目,希望高手帮忙

来源:百度知道 编辑:UC知道 时间:2024/09/23 12:09:41
1. 定义一个哺乳动物类Mammal, 有体重weight和年龄age两个成员变量, 再由此派生出狗类Dog, 有新成员color, 定义有参数的基类和派生类的构造函数,在main中使用Dog类。

希望高手写的时候不是只能运行就可以了,而是能按照题目要求写,非常感谢! 好的一定加分!
2. 定义一个车辆(vehicle)基类,具有MaxSpeed等成员变量,Run和Stop等成员函数,由此派生出自行车(bicycle)类、汽车(motorcar)类。自行车类有高度(height)等属性,汽车类有座位数(Seat)等属性。从bicycle和motorcar派生出摩托车(motorcycle)类。在main中使用这三个类,注意使用虚基类。

这是2道题目,请分别写,要完整哦,我是初学者,什么都不懂,请帮忙写完好吗?谢谢了,写完整了一定给分!!!

#include <cstdlib>
#include <iostream>

#include<string>
using namespace std;
class Mammal
{
public:
Mammal(int wt,int ag):weight(wt),age(ag)
{
}
virtual void printFeatr();
int getwt();
int getage();
private:
int weight;
int age;
};
void Mammal::printFeatr()
{
cout<<"the weight and age are:\n"
<<weight<<" "<<age<<endl;
}
int Mammal::getwt()
{
return weight;
}
int Mammal::getage()
{
return age;
}
class Dog:public Mammal
{
public:
Dog(int wt,int ag,string str):Mammal(wt,ag),color(str)
{}
void printFeatr();
private:
string color;
};