c++设计一个车辆类,该类有两个派生类 客车和货车 求助 60
展开全部
//vs2010编译通过
#include <iostream>
class Mam
{
public:
// void speak(); //没有定义virtual(虚)
virtual void speak();
};
void Mam::speak()
{
std::cout << "发声!" << std::endl;
}
class Human : public Mam
{
public:
void speak();
};
void Human::speak()
{
std::cout << "说话!" << std::endl;
}
class Cat : public Mam
{
public:
void speak();
};
void Cat::speak()
{
std::cout << "喵!" << std::endl;
}
class Dog : public Mam
{
public:
void speak();
};
void Dog::speak()
{
std::cout << "汪!" << std::endl;
}
int main()
{
Cat ca;
Mam *mp = &ca;
mp->speak();
Human man;
Mam &ma = man;
ma.speak();
system("pause");
return 0;
}
展开全部
只做第一题,对吧
更多追问追答
追问
是的
追答
class Vehicle{
private:
Color color;
float outputVolume;
std::string manufacture;
DateTime outputTime;
float price;
static int _count;
public:
Vehicle() {_count++;}
void setColor(Color c) { color = c;}
void setPrice(float p) { price = p;}
float getCc() { return outputVolume;}
float getPrice() { return price;}
int numberOfVehicle() { return _count;}
};
int Vehicle::_count = 0;
class Truck : public Vehicle{
private:
float loading;
public:
void setLoading(float l) { loading = l;}
};
class Car : public Vehicle{
private:
int passengerNumber;
public:
void setPassengerNumber(int pn) { passengerNumber= pn;}
};
class Sedan : public Car{
private:
float weight;
public:
void setWeight(float w) { weight=w;}
};
class Van : public Car{
private:
int seats;
public:
void setSeats(int s) { seats = s;}
};
class Bus : public Car{
private:
int length;
public:
void setLength(int l) { length = l;}
};
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询