Question: * * It seems that I cannot directly access the private data in the input function definition. The program cannot run. ( I need to
It seems that I cannot directly access the private data in the input function definition. The program cannot run. I need to use getters or setters but I have difficulty doing so The code is below:
#include
#include
using namespace std;
class Cargo
private:
string uldtype;
string abbrev;
string uldid;
int aircraft;
double weight;
string destination;
public:
Constructors
Cargo : aircraft weight
Cargoconst string& uldtype,
const string& abbrev,
const string& uldid,
int aircraft,
double weight,
const string& destination
: uldtypeuldtype
abbrevabbrev
uldiduldid
aircraftaircraft
weightweight
destinationdestination
Destructor
~Cargo
cout "Cargo destructor called" endl;
Setters
void setuldtypeconst string& uldtype thisuldtype uldtype;
void setabbrevconst string& abbrev thisabbrev abbrev;
void setuldidconst string& uldid thisuldid uldid;
void setaircraftint aircraft thisaircraft aircraft;
void setweightdouble weight thisweight weight;
void setdestinationconst string& destination thisdestination
destination;
Getters
string getuldtype const return uldtype;
string getabbrev const return abbrev;
string getuldid const return uldid;
int getaircraft const return aircraft;
double getweight const return weight;
string getdestination const return destination;
Overloaded operator
friend bool operatorconst Cargo& c const Cargo& c
return cabbrev cabbrev && culdid culdid;
;
Function prototypes
void inputCargoCargo& cargo;
void outputCargoconst Cargo& cargo;
Input function definition
void inputCargoCargo& cargo
cout "Enter unit load type: ;
cin cargo.uldtype;
cout "Enter unit load abbreviation: ;
cin cargo.abbrev;
cout "Enter unit identifier: ;
cin cargo.uldid;
cout "Enter aircraft type: ;
cin cargo.aircraft;
cout "Enter unit weight in pounds: ;
cin cargo.weight;
cout "Enter destination code: ;
cin cargo.destination;
Output function definition
void outputCargoconst Cargo& cargo
cout endl;
cout "Unit load type: cargo.getuldtype endl;
cout "Unit load abbreviation: cargo.getabbrev endl;
cout "Unit identifier: cargo.getuldid endl;
cout "Aircraft type: cargo.getaircraft endl;
cout "Unit weight: cargo.getweight pounds" endl;
cout "Destination code: cargo.getdestination endl;
cout endl;
int main
Cargo unitPAG "PAGIB "SEA";
Cargo unit unit; Copy constructor
Cargo unit; Default constructor
cout "Unit : endl;
outputCargounit;
cout "Unit : endl;
outputCargounit;
cout "Unit default: endl;
outputCargounit;
if unit unit
cout "unit is the same as unit endl;
else
cout "unit is not the same as unit endl;
Test if unit is equal to unit
if unit unit
cout "unit is the same as unit endl;
else
cout "unit is not the same as unit endl;
return ;
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
