Code:
#include <iostream>
#include <string>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
using std::string;
class Part
{
public:
Part() = default;
Part(const string& name): mName(name)
{}
friend std::ostream& operator<<(std::ostream& os, const Part& part)
{
os << part.GetPartName() << endl;
return os;
}
string GetPartName() const { return mName; }
private:
string mName{ "Part Name" };
};
class Vehicle
{
public:
Vehicle
(
const string& type,
const string& name,
float maxSpeed,
//In MPH
float maxFuelCapacity,
//In Gallons
float fuelUsedPerMinute,
float maxRange,
Part& engine
) : mType(type),
mName(name),
mMaxSpeed(maxSpeed),
mMaxFuelCapacity(maxFuelCapacity),
mFuelUsePerMinute(fuelUsedPerMinute),
mMaxRange(maxRange),
mEngine(engine)
{}
string GetType() const { return mType; }
string GetName() const { return mName; }
float GetMaxSpeed() const { return mMaxSpeed; }
float GetMaxFuelCapacity() const { return mMaxFuelCapacity; }
float GetFuelUsedPerMinute() const { return mFuelUsePerMinute; }
float GetMaxRange() const { return mMaxRange; }
void StartVehicle();
private:
string mType{ "Vehicle Type" }; //Airplane, automobile, etc.
string mName{ "Vehicle Name" };
float mMaxSpeed{ 0.0 };
float mMaxFuelCapacity{ 0.0 }; //In gallons
float mFuelUsePerMinute{ 0.0 }; //How much fuel is consumed
float mMaxRange{ 0.0 }; //How far this vehicle can travel
Part mEngine;
};
void Vehicle::StartVehicle()
{
cout << "Engine Started" << endl;
}
class Airplane : public Vehicle
{
public:
Airplane
(
const string& type,
const string& name,
float maxSpeed,
float maxFuelCapacity,
float fuelUsedPerMinute,
float maxRange,
Part& engine,
float elevationCeiling
)
: Vehicle
(
type,
name,
maxSpeed,
maxFuelCapacity,
fuelUsedPerMinute,
maxRange,
engine
), mElevationCeiling(elevationCeiling)
{}
using Vehicle::StartVehicle;
void StartVehicle();
float GetelevationCeiling() const { return mElevationCeiling; }
private:
float mElevationCeiling{ 0.0 };
};
void Airplane::StartVehicle()
{
cout << "Perform pre-flight checks" << endl;
cout << "Ready for takeoff" << endl;
}
//If a class like this has no variables is it worth making a class for instead of just doing Airplane Boeing737Max?
class Boeing737Max final : public Airplane
{
public:
Boeing737Max
(
const string& type,
const string& name,
float maxSpeed,
float maxFuelCapacity,
float fuelUsedPerMinute,
float maxRange,
Part& engine,
float elevationCeiling
)
: Airplane
(
type,
name,
maxSpeed,
maxFuelCapacity,
fuelUsedPerMinute,
maxRange,
engine,
elevationCeiling
)
{}
friend std::ostream& operator<<(std::ostream & os, const Boeing737Max& max)
{
os << "Vehicle Name: " << max.GetName() << endl;
os << "Vehicle type: " << max.GetType() << endl;
os << "Max Speed: " << max.GetMaxSpeed() << " MPH" << endl;
os << "Max Fuel Capacity: " << max.GetMaxFuelCapacity() << " gallons" << endl;
os << "Fuel Used Per Minute: " << max.GetFuelUsedPerMinute() << endl;
os << "Max Range: " << max.GetMaxRange() << " Miles" << endl;
//os << static_cast<const Part&>(max);
return os;
}
using Airplane::StartVehicle;
void StartVehicle();
};
void Boeing737Max::StartVehicle()
{
cout << GetName() << " ready for takeoff" << endl;
}
int main()
{
Part LEAP1B("CFM International LEAP-1B");
Boeing737Max Max("Airplane", "Boeing 737 Max", 521.0f, 6875.0f, 0.0f, 3521.0f, LEAP1B, 41000.0f);
cout << Max << endl;
Max.StartVehicle();
}