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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
|
#include <iostream>
#include <string>
#include <vector>
#include <memory>
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::unique_ptr;
using std::make_unique;
class Aircraft
{
public:
Aircraft() = default;
string GetName() const { return mName; }
string GetOrigin() const { return mOrigin; }
float GetMaxSpeed() const { return mMaxSpeed; }
double GetUnitCost() const { return mUnitCost;}
float GetWeight() const { return mWeight; }
int GetYearProduced() const { return mYearProduced; }
int GetNumberBuilt() const { return mNumberBuilt; }
virtual void SetSprite() = 0;
//We dont want the user making a generic aircraft, only making a specific one for this project.
protected:
Aircraft
(
const string& name,
const string& origin,
float maxSpeed,
double unitCost,
float weight,
int yearProduced,
int numberBuilt
) : mName(name),
mOrigin(origin),
mMaxSpeed(maxSpeed),
mUnitCost(unitCost),
mWeight(weight),
mYearProduced(yearProduced),
mNumberBuilt(numberBuilt)
{}
private:
string mName{};
string mOrigin{}; //Country of origin
float mMaxSpeed{};
double mUnitCost{};
float mWeight{};
int mYearProduced{};
int mNumberBuilt{};
};
class Fighter : public Aircraft
{
public:
Fighter() = default;
void SetSprite() override
{
cout << "Fighter Aircraft Sprite Set" << endl;
}
string GetPrimaryWeaponName() const { return mPrimaryWeaponName; }
string GetSecondaryWeaponName() const { return mSecondaryWeaponName; }
int GetPayload() const { return mPayload; }
//Maybe could make a bool that says hasCountermeasure? Not all aircraft have countermeasures so this
//Shoudnt go in aircraft but military planes have it so a militaryAircraft class could probably
//ber made and put in there along with other things specific to military aircraft.
void DeployChaffCountermeasure()
{
cout << "Chaff Countermeasure deployed" << endl;
}
virtual void Eject() const = 0;
virtual void FirePrimaryWeapon() const = 0;
virtual void FireSecondaryWeapon() const = 0;
protected:
Fighter
(
const string& name,
const string& origin,
float maxSpeed,
double unitCost,
float weight,
int yearProduced,
int numberBuilt,
const string& primaryWeaponName,
const string& secondaryWeaponName,
int payload
) : Aircraft{ name, origin, maxSpeed, unitCost, weight, yearProduced, numberBuilt }, mPrimaryWeaponName(primaryWeaponName),
mSecondaryWeaponName(secondaryWeaponName),
mPayload(payload)
{}
private:
string mPrimaryWeaponName{};
string mSecondaryWeaponName{};
int mPayload{};
};
class F35Lightening2 : public Fighter
{
public:
F35Lightening2() = default;
F35Lightening2
(
const string& name,
const string& origin,
float maxSpeed,
double unitCost,
float weight,
int yearProduced,
int numberBuilt,
const string& primaryWeaponName,
const string& secondaryWeaponName,
int payload
) : Fighter{ name, origin, maxSpeed, unitCost, weight, yearProduced, numberBuilt, primaryWeaponName, secondaryWeaponName, payload }
{}
void SetSprite() override
{
cout << "F-35 Lightening II sprite set" << endl;
}
void Eject() const override
{
cout << "Ejected out of canopy" << endl;
}
void FirePrimaryWeapon() const override
{
cout << "Firing 25mm GAU-22 cannons" << endl;
}
void FireSecondaryWeapon() const override
{
cout << "Firing Air-to-air missiles" << endl;
}
};
class Cargo : public Aircraft
{
public:
Cargo() = default;
float GetMaxTakeoffWeight() const { return mMaxTakeoffWeight; }
virtual void LoadCargo() = 0;
protected:
Cargo
(
const string& name,
const string& origin,
float maxSpeed,
double unitCost,
float weight,
int yearProduced,
int numberBuilt,
float maxTakeoffWeight
) : Aircraft{ name, origin, maxSpeed, unitCost, weight, yearProduced, numberBuilt }, mMaxTakeoffWeight(maxTakeoffWeight)
{}
private:
float mMaxTakeoffWeight{};
};
class C17Globemaster : public Cargo
{
public:
C17Globemaster() = default;
C17Globemaster
(
const string& name,
const string& origin,
float maxSpeed,
double unitCost,
float weight,
int yearProduced,
int numberBuilt,
float maxTakeoffWeight
) : Cargo{ name, origin, maxSpeed, unitCost, weight, yearProduced, numberBuilt, maxTakeoffWeight}
{}
void SetSprite() override
{
cout << "C-17 Globemaster III Aircraft Sprite Set" << endl;
}
void LoadCargo() override
{
cout << "Loading cargo through back ramp" << endl;
}
};
int main()
{
unique_ptr<Fighter> fighter = make_unique<F35Lightening2>("F-35 Lightening II", "United States", 1200, 94000000.000, 29300.00, 2006, 625, "25mm Canon", "Air-to-air Missiles", 2000);
cout << "Name: " << fighter->GetName() << endl;
cout << "Country of origin: " << fighter->GetOrigin() << endl;
cout << "Max Speed: " << fighter->GetMaxSpeed() << endl;
cout << std::fixed << "Unit cost: $" << fighter->GetUnitCost() << endl;
cout << "Weight: " << fighter->GetWeight() << endl;
cout << "Year Produced: " << fighter->GetYearProduced() << endl;
cout << "Number Built: " << fighter->GetNumberBuilt() << endl;
cout << "Primary Weapon: " << fighter->GetPrimaryWeaponName() << endl;
cout << "Number Built: " << fighter->GetSecondaryWeaponName() << endl;
cout << "Payload: " << fighter->GetPayload() << endl;
cout << "\n\n";
fighter->SetSprite();
fighter->FirePrimaryWeapon();
fighter->FireSecondaryWeapon();
fighter->DeployChaffCountermeasure();
fighter->Eject();
unique_ptr<Cargo> cargo = make_unique<C17Globemaster>("C-17 Globemaster", "United States", 590, 200000000, 282400, 1980, 279, 585000);
cout << "\n------------------------\n" << endl;
cout << "Name: " << cargo->GetName() << endl;
cout << "Country of origin: " << cargo->GetOrigin() << endl;
cout << "Max Speed: " << cargo->GetMaxSpeed() << endl;
cout << "Unit cost: $" << cargo->GetUnitCost() << endl;
cout << "Weight: " << cargo->GetWeight() << endl;
cout << "Year Produced: " << cargo->GetYearProduced() << endl;
cout << "Number Built: " << cargo->GetNumberBuilt() << endl;
cout << "Max Takeoff Weight: " << cargo->GetMaxTakeoffWeight() << endl;
cout << "\n\n";
cargo->SetSprite();
cargo->LoadCargo();
return 0;
}
|