Question: Lab 4 . 1 Utilizing the code from Lab 3 , add an overloaded operator = = which will be used to compare two objects

Lab 4.1
Utilizing the code from Lab 3, 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 unit1 object and load it with this data:
uld Pallet
abbreviation PAG
uldid PAG32597IB
aircraft -737
weight 3321 Pounds
destination SEA
Make a copy of unit1 called unit2 utilizing a copy constructor.
Create a default unit3.
Test with code like this in main:
if (unit1== unit2)
cout <<"
unit1 is the same as unit2
";
else
cout <<"
unit1 is not the same as unit2
";
if (unit2== unit3)
cout <<"
unit2 is the same as unit3
";
else
cout <<"
unit2 is not the same as unit3
";
CODE FROM LAB 3
#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
Cargo(const string uldtype, const string abbrev, const string uldid, const int aircraft, const double weight, const string destination);
// Destructor
~Cargo();
// Setters
void setuldtype(string uldtype);
void setabbrev(string abbrev);
void setuldid(string uldid);
void setaircraft(int aircraft);
void setweight(double weight);
void setdestination(string 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 inputCargo(Cargo& cargo);
friend void outputCargo(const Cargo& cargo);
};
// Function prototypes for input and output functions
void inputCargo(Cargo& cargo);
void outputCargo(const Cargo& cargo);
// Default constructor definition
Cargo::Cargo(){
uldtype ="";
abbrev ="";
uldid ="";
aircraft =0;
weight =0.0;
destination ="";
}
// Parameterized constructor definition
Cargo::Cargo(const string uldtype, const string abbrev, const string uldid, const int aircraft, const double weight, const string destination){
this->uldtype = uldtype;
this->abbrev = abbrev;
this->uldid = uldid;
this->aircraft = aircraft;
this->weight = weight;
this->destination = destination;
}
// Destructor definition
Cargo::~Cargo(){
cout << "Cargo destructor called" << endl;
}
// Setters definitions
void Cargo::setuldtype(string uldtype){
this->uldtype = uldtype;
}
void Cargo::setabbrev(string abbrev){
this->abbrev = abbrev;
}
void Cargo::setuldid(string uldid){
this->uldid = uldid;
}
void Cargo::setaircraft(int aircraft){
this->aircraft = aircraft;
}
void Cargo::setweight(double weight){
this->weight = weight;
}
void Cargo::setdestination(string destination){
this->destination = 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 inputCargo(Cargo& 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 outputCargo(const 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;
inputCargo(myCargo);
outputCargo(myCargo);
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!