1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
#include <iostream>
#include <string>
using namespace std;
class Aircraft
{
public:
Aircraft() : MPrice(0), LPrice(0), BPrice(0), PPrice(0), TotalPrice(0) , Stars(0) {cout<<"aircraft constructor"<<endl;}
virtual ~Aircraft(){cout<<"aircraft destructor"<<endl;}
protected:
string Missile;
string Laser;
string Bomb;
string Propulsion;
int MPrice, LPrice, BPrice, PPrice, TotalPrice;
int Stars;
};
class Jet : public Aircraft
{
public:
string GetMissile() {return Missile;}
int MissilePrice() {return MPrice;}
string GetLaser() {return Laser;}
int LaserPrice() {return LPrice;}
string GetBomb() {return Bomb;}
int BombPrice() {return BPrice;}
string GetPropulsion() {return Propulsion;}
int PropulsionPrice() {return PPrice;}
void SetMissile(int MissileChoice)
{
switch(MissileChoice)
{
case 0: Missile = "Air-to-air missile";
MPrice = 300;
break;
case 1: Missile = "Air-to-surface missile";
MPrice = 700;
break;
case 2: Missile = "Air-to-ship missile";
MPrice = 600;
break;
case 3: Missile = "Air-to-tank missile";
MPrice = 400;
break;
}
}
void SetLaser(int LaserChoice)
{
switch(LaserChoice)
{
case 0: Laser = "Hydrogen Fluoride Laser";
LPrice = 100;
break;
case 1: Laser = "Deuterium Fluoride Laser";
LPrice = 250;
break;
case 2: Laser = "Chemical Oxygen-Iodine Laser";
LPrice = 200;
break;
case 3: Laser = "All Gas-phase Iodine Laser";
LPrice = 125;
break;
}
}
void SetBomb(int BombChoice)
{
switch(BombChoice)
{
case 0: Bomb = "Cluster Bomb";
BPrice = 600;
break;
case 1: Bomb = "Concrete Bomb";
BPrice = 700;
break;
case 2: Bomb = "Incendiary Bomb";
BPrice = 850;
break;
case 3: Bomb = "General-purpose Bomb";
BPrice = 600;
break;
}
}
void SetPropulsion(int PropulsionChoice)
{
//Jet.Propulsion
switch(PropulsionChoice)
{
case 0: Propulsion = "Solid-fuel Propulsion";
PPrice = 750;
break;
case 1: Propulsion = "Liquid Rocket Propulsion";
PPrice = 900;
break;
case 2: Propulsion = "Electric Propulsion";
PPrice = 450;
break;
case 3: Propulsion = "Nuclear Propulsion";
PPrice = 650;
break;
}
}
int GetTotalPrice() {TotalPrice = MPrice+LPrice+BPrice+PPrice;
return TotalPrice;}
int GetStars(int (*pGTPrice)() )//accepts as argument a pointer (pStars) to 'int GetTotalPrice()'
{if (pGTPrice()>=2400)
{Stars = 12;
return Stars;}
if (pGTPrice()>=2300 && pGTPrice()<2400)
{Stars = 11;
return Stars;}
if (pGTPrice()>=2200 && pGTPrice()<2300)
{Stars = 10;
return Stars;}
if (pGTPrice()>=2100 && pGTPrice()<2200)
{Stars = 9;
return Stars;}
if (pGTPrice()>=2000 && pGTPrice()<2100)
{Stars = 8;
return Stars;}
if (pGTPrice()>=1900 && pGTPrice()<2000)
{Stars = 7;
return Stars;}
if (pGTPrice()>=1800 && pGTPrice()<1900)
{Stars = 6;
return Stars;}
if (pGTPrice()>=1700 && pGTPrice()<1800)
{Stars = 5;
return Stars;}
if (pGTPrice()>=1600 && pGTPrice()<1700)
{Stars = 4;
return Stars;}
if (pGTPrice()>=1500 && pGTPrice()<1600)
{Stars = 3;
return Stars;}
if (pGTPrice()>=1400 && pGTPrice()<1500)
{Stars = 2;
return Stars;}
if (pGTPrice()<1400)
{Stars = 1;
return Stars;}
};
};
int main()
{
Jet You;
int MissileChoice, LaserChoice, BombChoice, PropulsionChoice;
cout<<"choose the missile, laser, bomb, propulsion of the jet"<<endl;
cin>>MissileChoice;
cin>>LaserChoice;
cin>>BombChoice;
cin>>PropulsionChoice;
You.SetMissile(MissileChoice);
You.SetLaser(LaserChoice);
You.SetBomb(BombChoice);
You.SetPropulsion(PropulsionChoice);
cout<<"you chose "<<endl;
cout<<You.GetMissile()<<endl;
cout<<You.GetLaser()<<endl;
cout<<You.GetBomb()<<endl;
cout<<You.GetPropulsion()<<endl;
cout<<"Thus, total price is "<<You.GetTotalPrice();
int (Aircraft::*pPrice) () = 0;
Aircraft* ptr=0;
ptr=new Jet;
pPrice=Aircraft::GetTotalPrice;
cout<<"You have produced a "<<ptr->*GetStars(pPrice())<<"-starred JET!";
delete ptr;
cin.ignore();
cin.ignore();
return 0;
}
|