Question: Lab 4 . 1 Utilizing the code from Lab 3 , add an overloaded operator = = which will be used to compare two objects
Lab
Utilizing the code from Lab add an overloaded operator which will be used to compare two objects to see if they are equal. For our purposes, two objects are equal if their abbreviation and uldid are the same. Youll need to make your overloaded operator a friend of the Cargo class.
Create a unit object and load it with this data:
uld Pallet
abbreviation PAG
uldid PAGIB
aircraft
weight Pounds
destination SEA
Make a copy of unit called unit utilizing a copy constructor.
Create a default unit
Test with code like this in main:
if unit unit
cout
unit is the same as unit
;
else
cout
unit is not the same as unit
;
if unit unit
cout
unit is the same as unit
;
else
cout
unit is not the same as unit
;
CODE FROM LAB
#include
#include
using namespace std;
class Cargo
private:
string uldtype;
string abbrev;
string uldid;
int aircraft;
double weight;
string destination;
public:
Default constructor
Cargo;
Parameterized constructor
Cargoconst string uldtype, const string abbrev, const string uldid, const int aircraft, const double weight, const string destination;
Destructor
~Cargo;
Setters
void setuldtypestring uldtype;
void setabbrevstring abbrev;
void setuldidstring uldid;
void setaircraftint aircraft;
void setweightdouble weight;
void setdestinationstring destination;
Getters
string getuldtype const;
string getabbrev const;
string getuldid const;
int getaircraft const;
double getweight const;
string getdestination const;
Input and Output functions
friend void inputCargoCargo& cargo;
friend void outputCargoconst Cargo& cargo;
;
Function prototypes for input and output functions
void inputCargoCargo& cargo;
void outputCargoconst Cargo& cargo;
Default constructor definition
Cargo::Cargo
uldtype ;
abbrev ;
uldid ;
aircraft ;
weight ;
destination ;
Parameterized constructor definition
Cargo::Cargoconst string uldtype, const string abbrev, const string uldid, const int aircraft, const double weight, const string destination
thisuldtype uldtype;
thisabbrev abbrev;
thisuldid uldid;
thisaircraft aircraft;
thisweight weight;
thisdestination destination;
Destructor definition
Cargo::~Cargo
cout "Cargo destructor called" endl;
Setters definitions
void Cargo::setuldtypestring uldtype
thisuldtype uldtype;
void Cargo::setabbrevstring abbrev
thisabbrev abbrev;
void Cargo::setuldidstring uldid
thisuldid uldid;
void Cargo::setaircraftint aircraft
thisaircraft aircraft;
void Cargo::setweightdouble weight
thisweight weight;
void Cargo::setdestinationstring destination
thisdestination destination;
Getters definitions
string Cargo::getuldtype const
return uldtype;
string Cargo::getabbrev const
return abbrev;
string Cargo::getuldid const
return uldid;
int Cargo::getaircraft const
return aircraft;
double Cargo::getweight const
return weight;
string Cargo::getdestination const
return destination;
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.uldtype endl;
cout "Unit load abbreviation: cargo.abbrev endl;
cout "Unit identifier: cargo.uldid endl;
cout "Aircraft type: cargo.aircraft endl;
cout "Unit weight: cargo.weight pounds" endl;
cout "Destination code: cargo.destination endl;
cout "Cargo destructor called" endl;
cout endl;
int main
Cargo myCargo;
inputCargomyCargo;
outputCargomyCargo;
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
