?? classheaders.h
字號:
#include <iostream.h>
#include <string.h>
//This is Class for Vehicle Two class will be inherited from this class. Car And Lorry
//-------------------------------------
class Vehicle
{
protected:
char registration[5];
char vehicle_type[1];
static int vehicle_count;
public:
Vehicle();
virtual ~Vehicle();
int getVehicleCount();
};
int Vehicle::vehicle_count;
Vehicle::Vehicle()
{
vehicle_count++;
}
Vehicle::~Vehicle()
{
vehicle_count--;
}
int Vehicle::getVehicleCount()
{
return vehicle_count;
}
//End Of Vehicle Class
//-----------------------------------------
// Class For Car
//-----------------------------------------
class Car : public Vehicle
{
private:
static int car_count;
public:
Car();
virtual ~Car();
static int getCarCount();
};
int Car::car_count;
Car::Car()
{
strcpy(vehicle_type,"C");
car_count++;
}
Car::~Car()
{
car_count--;
}
int Car::getCarCount()
{
return car_count;
}
// End of Car Class
//------------------------------------------
// This is Class for Lorry
//------------------------------------------
class Lorry : public Vehicle
{
private:
static int lorry_count;
public:
Lorry();
virtual ~Lorry();
static int getLorryCount();
};
int Lorry::lorry_count;
Lorry::Lorry()
{
strcpy(vehicle_type,"L");
lorry_count++;
}
Lorry::~Lorry()
{
lorry_count--;
}
int Lorry::getLorryCount()
{
return lorry_count;
}
// End Of Lorry Class
//----------------------------
const int CSIZE=10;
const int LSIZE=5;
const int SIZE=15;
//This is Class for Place. Two classes will be derived from this class CPlace and LPlace
//---------------------------------
class Place
{
private:
Vehicle* park[SIZE];
static int vehicle_in_park;
public:
Place();
~Place();
};
int Place::vehicle_in_park;
Place::Place()
{
for(int i=0;i<SIZE;i++)
{
park[i]=NULL;
}
}
Place::~Place()
{
for(int i=0;i<SIZE; i++)
{
delete park[i];
}
}
//End of Place Class
//-------------------------------------------------
// This is Class for CarPark
//------------------------------------------------------
class CPlace : public Place
{
private:
Car* cpark[CSIZE];
static int car_in_park;
public:
CPlace();
~CPlace();
void CarIn(Car* car_in);
Car* CarOut();
int ShowCarPark();
};
int CPlace::car_in_park;
CPlace::CPlace()
{
for(int i=0;i<CSIZE;i++)
{
cpark[i] = NULL;
}
}
CPlace::~CPlace()
{
for(int i=0;i < CSIZE; i++)
{
delete cpark[i];
}
}
void CPlace::CarIn(Car* car_in)
{
if(car_in_park==CSIZE)
{
cout<<"Car Park is Full"<<endl;
delete car_in;
}
else
{
car_in_park++;
}
}
Car* CPlace::CarOut()
{
if(car_in_park==0)
{
cout<<"No Car In Park"<<endl;
}
else
{
car_in_park--;
}
return 0;
}
int CPlace::ShowCarPark()
{
return car_in_park;
}
//----------------------------------------------------
// This is Class For LorryPark
//----------------------------------------------------
class LPlace : public Place
{
private:
Lorry* lpark[LSIZE];
static int lorry_in_park;
public:
LPlace();
~LPlace();
void LorryIn(Lorry* lorry_in);
Lorry* LorryOut();
int ShowLorryPark();
};
int LPlace::lorry_in_park;
LPlace::LPlace()
{
for(int i=0;i<LSIZE;i++)
{
lpark[i] = NULL;
}
}
LPlace::~LPlace()
{
for(int i=0;i < LSIZE; i++)
{
delete lpark[i];
}
}
void LPlace::LorryIn(Lorry* lorry_in)
{
if(lorry_in_park==LSIZE)
{
cout<<"Lorry Park is Full"<<endl;
delete lorry_in;
}
else
{
lorry_in_park++;
}
}
Lorry* LPlace::LorryOut()
{
if(lorry_in_park==0)
{
cout<<"No Lorry In Park"<<endl;
}
else
{
lorry_in_park--;
}
return 0;
}
int LPlace::ShowLorryPark()
{
return lorry_in_park;
}
//---------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -