There are 3 types of planes.
- A nA321 which has a max capacity of 10 containers
- nB777 which has a max capacity of 32 containers
- nB787 which has a max capacity of 40 containers
I want to index through the list and create an Airplane object and store the respective value. My for loop will create a new Airplane object that is set to 10. How can I dynamically set the respective plane types to the corresponding max capacity? The code currently outputs the address, for example:
Airplane 1 maximum load 0xffe
I am trying to print the following:
Airplane 1 maximum load 10
Airplane 2 maximum load 10
Airplane 3 maximum load 10
Airplane 4 maximum load 10
Airplane 5 maximum load 32
Airplane 6 maximum load 32
Airplane 7 maximum load 40
My code
#include <iostream>
using namespace std;
class Airplane
{
public:
Airplane(int n); // the maximum capacity of the airplane
int maxLoad(void) const;
int currentLoad(void) const;
bool addContainers(int n);
private:
const int maxContainers;
int numContainers;
};
Airplane::Airplane(int n):maxContainers(n){
n = maxContainers;
}
int Airplane::maxLoad(void) const{
return maxContainers;
}
int Airplane::currentLoad(void) const{
return numContainers;
}
class Airline
{
public:
Airline(int nA321, int nB777, int nB787);
~Airline(void);
void addShipment(int size);
void printSummary(void) const; // prints a list of airplanes with their current and maximum load.
private:
const int nAirplanes; // total # of airplanes used by airline
Airplane** airplaneList; // array of pointers to Airplane objects
};
Airline::Airline(int nA321, int nB777, int nB787):nAirplanes(nA321 + nB777 + nB787){
airplaneList = new Airplane*[nAirplanes];
for ( int i = 0; i < this->nAirplanes; i++ ){
airplaneList[i] = new Airplane(10);
airplaneList[i] -> maxLoad();
cout << "Airline " << i+1 << " maximum load " << airplaneList[i] << endl;
}
}
Airline::~Airline(void){}
int main(void)
{
// create an Airline with 4 A321, 2 B777 and 1 B787
Airline airline(4,2,1);
cout << "Assignment complete" << endl;
}