Question: (Inheritance and Polymorphism) Notes: 1)Any function that can be declared constant should be done so. 2)Make any necessary validations to inputs 3)Clean the heap as
(Inheritance and Polymorphism) Notes: 1)Any function that can be declared constant should be done so.
2)Make any necessary validations to inputs
3)Clean the heap as often as necessary
In your Holidays system, Flights can be categorised into: Outbound and Inbound.
Date class has int attributes for Day, Month and Year.
All Flight objects have attributes:
const int FlightNumber; // drawn from a static serial number starting from 1.
string Destination;
Date *Flight_Date; //from Date class Use Heap to store it and clean it in the destructor
double *Take-Off-Weight; //Use heap to store it and clean in in the destructor
Flight.h is given here:
//=================
#include
using namespace std;
#include "Date.h"
class Flight {
static int serial;
protected:
int Passengers;
const int FlightNumber;
string Destination;
Date *Flight_Date;
double *Take-Off-Weight;
public:
Flight();
Flight(string dest, Date fdate, double weight, int pass);
virtual void SetValues(string dest, Date fdate, double weight, int pass);
virtual double Calaculate_Cost() = 0;
virtual void PrintDetails() = 0;
virtual ~Flight();
};
//=================
Outbound Flights have the additional attributes:
double* Tax; //Use heap to store it and clean in in the destructor
string* Stop-Over; //(e.g., Doha, Madrid, Istanbul), Use heap to store it and clean in the destructor
Inbound Flights have the additional attributes:
Double *Fuel-Load; //Use heap to store it and clean in in the destructor
string *Bound-To; //(e.g., Doha, Madrid, Istanbul) - Use heap to store it and clean in in the destructor
***Requirements***
Part 1
1) Code all classes
2) Declare as many attributes as private as possible
3) Pass parameters as const as much as possible
4) Separate class interface and implementation
5) You can use String library
6) Do NOT create pointers of type Inbound or Outbound. All pointers must be of type Flight
7) Use Dynamic Memory where possible
8) Create the base class Flight as above, note:
a) Pure virtual function to print details
b) Pure virtual function Calaculate_Cost as follows:
Inbound: weight *0.4 + Fuel-Load * 3.25 * Passengers * 100;
Outbound: weight *0.38 + Tax * 1.5 *
Passengers * 100;
9) Create derived classes Inbound + Outbound as above with the following functionalities:
a) Constructors to initialize the data members
b) Destructors to perform garbage collection and resets
c) Functions to print details including those inherited from base class
d) Functions to calculate Cost
Part 2
Write a program to test drive your classes.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
