1个回答
展开全部
#include<iostream>
using namespace std;
class Vehicle{
public:
virtual void Run(){cout<<"Vehicle::Run called\n";}
virtual void Stop(){cout<<"Vehicle::Stop called\n";}
};
class motorcar:public Vehicle{
public:
void Run(){cout<<"motorcar::Run called\n";}
virtual void Stop(){cout<<"motorcar::Stop called\n";}
};
class bicycle :public Vehicle{
public:
virtual void Run(){cout<<"bicycle::Run called\n";}
void Stop(){cout<<"bicycle::Stop called\n";}
};
class motorcycle:public bicycle,public motorcar{
public:
void Run(){cout<<"motorcycle::Run called\n";}
void Stop(){cout<<"mototrcycle::Stop called\n";}
};
void main(){
Vehicle ve;
bicycle bi;
motorcar mo;
motorcycle mocy;
Vehicle *pclass=&ve;
pclass->Run();
pclass->Stop();
pclass=&bi;
pclass->Run();
pclass->Stop();
pclass=&mo;
pclass->Run();
pclass->Stop();
}
using namespace std;
class Vehicle{
public:
virtual void Run(){cout<<"Vehicle::Run called\n";}
virtual void Stop(){cout<<"Vehicle::Stop called\n";}
};
class motorcar:public Vehicle{
public:
void Run(){cout<<"motorcar::Run called\n";}
virtual void Stop(){cout<<"motorcar::Stop called\n";}
};
class bicycle :public Vehicle{
public:
virtual void Run(){cout<<"bicycle::Run called\n";}
void Stop(){cout<<"bicycle::Stop called\n";}
};
class motorcycle:public bicycle,public motorcar{
public:
void Run(){cout<<"motorcycle::Run called\n";}
void Stop(){cout<<"mototrcycle::Stop called\n";}
};
void main(){
Vehicle ve;
bicycle bi;
motorcar mo;
motorcycle mocy;
Vehicle *pclass=&ve;
pclass->Run();
pclass->Stop();
pclass=&bi;
pclass->Run();
pclass->Stop();
pclass=&mo;
pclass->Run();
pclass->Stop();
}
三益精密
2024-11-05 广告
2024-11-05 广告
功能需求与材料选择:设计机械零部件时,首先需要明确其功能需求,如强度、耐腐蚀性、轻量化等。根据这些需求选择合适的材料是至关重要的,因为不同的材料具有不同的物理、化学和机械性能。例如,高强度材料可以提高零部件的承载能力,而轻质材料则有助于减轻...
点击进入详情页
本回答由三益精密提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询