第十、十一週間プロジェクト五-オートバイは自転車と自動車を継承する
2705 ワード
/*
*Copyright(c)2016,
*All rights reserved
* :123.cpp
* :
* :2016 5 10
* :v1.0
*
* : , , , , ,
*/
#include <iostream>
#include<conio.h>
#include <windows.h>
using namespace std;
enum vehicleStaus {rest, running}; // : 、
class vehicle //
{
protected:
int maxSpeed; //
int currentSpeed; //
int weight; //
vehicleStaus status; //rest- ;running-
public:
vehicle(int maxS, int w); // , , 0
void start(); // rest running, 1
void stop(); // running rest, 5 ,
void speed_up(); // , 1 , 1
void slow_down(); // , 1 , 1, 0 ,
};
class bicycle :virtual public Vehicle //(1)
{
protected:
double height; //
public:
bicycle(int maxS=10, int w=50, int h=0.7); //
};
class motorcar : virtual public Vehicle //(2)
{
protected:
int seatNum; //
int passengerNum; //
public:
motorcar(int maxS=150, int w=1500, int s=5, int p=1); //
void addPassenger(int p=1); // , , ,p 。 1 ( )。 ……
};
class motorcycle: public bicycle, public motorcar //(3)
{
public:
Motorcycle(int maxS=90, int w=100, int s=3, int p=1, int h=0.7); //
void show(); //
};
int main( )
{
motorcycle m;
bool end=false;
while (!end)
{
cout<<" :1- 2- 3- 4- 5- 6- 0- "<<endl;
char keydown= _getch(); //_getch()
switch(keydown)
{
case '1':
cout<<" 1- \t";
m.start();
break;
case '2':
cout<<" 2- \t";
m.speed_up();
break;
case '3':
cout<<" 3- \t";
m.slow_down();
break;
case '4':
cout<<" 4- \t";
m.addPassenger();
break;
case '5':
cout<<" 5- \t";
m.addPassenger(-1);
break;
case '6':
cout<<" 6- \t";
m.stop();
break;
case '0':
end=true;
break;
}
m.show();
cout<<endl;
Sleep(200); // <windows.h>
}
return 0;
}