ok basically what my program is about. I am to create a program that allows users to input aircraft/cargo details, add the cargo to the aircraft(up to 20), and a function to display all the cargo on that aircraft. So the main problem i am getting is with the listing of cargo on the aircraft. Since the cargo data is private, I am not sure how the function which is under Aircraft class is able to get the cargo info and display it.
#include <iostream>
#include <cstring>
using namespace std;
const int LIST_SIZE = 20;
/*
Classes
*/
class Cargo
{
public:
Cargo();
void setCargo(string, int, int, int, int, int);
int volWeight;//volumetric weight of cargo
private:
string cargoId;//cargo id
int weight;//cargo weight
int height;//cargo height
int width;//cargo width
int length;//cargo length
};
class Aircraft
{
public:
Aircraft();
void setAircraft(string, int, int);
void listAircraft();
void listCargo(Cargo);
bool addCargo(Cargo);
Cargo cargoList[LIST_SIZE];//array list of cargo
private:
string planeId;//aircraft ID
int weightCap;//weight capacity
int cargoCount;//counter for cargo
};
/*
Constructors
*/
Aircraft::Aircraft ()
{
planeId = "string1" ;
weightCap = 0;
}
Cargo::Cargo ()
{
cargoId = "string2" ;
weight = 0;
height = 0;
width = 0;
length = 0;
volWeight = 0;
}
/*
Initialise Aircraft data
*/
void Aircraft::setAircraft(string pID, int wCap, int)
{
planeId = pID;
weightCap = wCap;
cargoCount = 0 ;
}
/*
Initialise Cargo data
*/
void Cargo::setCargo(string cID, int wt, int h, int w, int l, int vWeight)
{
cargoId = cID;
weight = wt;
height = h;
width = w;
length = l;
volWeight = vWeight;
}
/*
Functions
*/
void createAircraft(Aircraft& air1);
void createCargo(Cargo& cargo1);
/*
MAIN
*/
int main()
{
int menu = 0;
Aircraft air1;
Cargo cargo1;
while (menu != 4)
{
cout << "Enter menu option: " << endl;
cout << "1.Create new aircraft/cargo " << endl;
cout << "2.List aircraft/cargo " << endl;
cout << "3.Add cargo to aircraft " << endl;
cout << "4.Quit " << endl;
cin >> menu;
cin.ignore (100, '\n');
switch (menu)
{
case 1: createAircraft(air1);
createCargo(cargo1);
break;
case 2: air1.listAircraft();
air1.listCargo(cargo1);
break;
case 3: air1.addCargo(cargo1);
if (air1.addCargo(cargo1) == true)
cout << "cargo added" << endl;
else
cout << "cargo cannot be added" << endl;
break;
case 4: exit(1);
default: cout << "Enter 1-4 only" << endl;
}
}
system("pause");
return 0;
}
/*
Create New Aircraft
*/
void createAircraft(Aircraft& air1)
{
string pID;
int wCap;
cout << "Enter aircraft ID: " << endl;
cin >> pID;
cout << "Enter weight capacity: " << endl;
cin >> wCap;
air1.setAircraft(pID, wCap,0 );
}
/*
Create new Cargo
*/
void createCargo(Cargo& cargo1)
{
string cID;
int wt, h, w, l, vWeight;
cout << "Enter cargo ID: " << endl;
cin >> cID;
cout << "Enter cargo weight: " << endl;
cin >> wt;
cout << "Enter height: " << endl;
cin >> h;
cout << "Enter width: " << endl;
cin >> w;
cout << "Enter Length: " << endl;
cin >> l;
vWeight = (h * w * l)/6000;
cargo1.setCargo(cID, wt, h, w, l, vWeight);
}
/*
Add Cargo to Aircraft
*/
bool Aircraft::addCargo (Cargo cargo1)
{
if (cargoCount < LIST_SIZE)
{
if (cargo1.volWeight < weightCap)
{
for (int i = 0; i < LIST_SIZE - 1; i++)
{
cargoList[i] = cargo1;
cargoCount++;
}
return true;
}
}
else
return false;
}
/*
List Aircraft
*/
void Aircraft::listAircraft()
{
cout << "Aircraft ID: " << planeId << endl;
cout << "Weight Capacity: " << weightCap << endl;
}
/*
List Cargo
*/
void Aircraft::listCargo(Cargo cargo1)
{
for (int i = 0; i < cargoCount; i++)
{
cout << cargoList[i].cargoID << endl;
//cout << cargoList[i] << endl;
}
}