Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C++ THANK YOU! Lab 4.1 Utilizing the code from Lab 3.2 , add an overloaded operator == which will be used to compare two

IN C++ THANK YOU!

Lab 4.1 Utilizing the code from Lab 3.2, 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 Kilograms 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 ";

------------------------------------------------------------

Lab 3.2 code

//

// main.cpp

// Lin_Wenqi_Lab3.2_

//

// Created by Connie Lin on 2/17/23.

//

#include

#include

#include

using namespace std;

class Cargo

{

private:

string uldtype;

string abbrev;

string uldid;

int aircraft;

double weight; // change from int to double

string destination;

public:

Cargo();

Cargo(const string uldtype,

const string abbrev,

const string uldid,

const int aircraft,

const double weight,

const string destination);

Cargo(const Cargo& ); // copy constructor prototype/declaration

~Cargo();

void setuldtype(string);

void setabbrev(string);

void setuldid(string);

void setaircraft(int);

void setweight(double);

void setdestination(string);

string getuldtype() const;

string getabbrev() const;

string getuldid() const;

int getaircraft() const;

double getweight() const;

string getdestination() const;

void input();

void output();

friend void kilotolb(double &); //prototype for friend kilotolb

friend bool operator == (const Cargo &left, const Cargo &right);

};

void kilotolb(double &); //prototype for friend kilotolb

bool operator == (const Cargo &left, const Cargo &right);

int main(){

Cargo unit1; //built on the stack

unit1.input(); //built on the stack, takes user input

Cargo unit2(unit1);

Cargo unit3;

cout << "unit1 ";

unit1.output();

cout <<"unit2 ";

unit2.output();

cout <<"unit 3 ";

unit3.output();

//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 sae as unit3 ";

//else

// cout << "unit2 is not the same as unit3 ";

return 0;

}

Cargo::Cargo()

{

uldtype = "XXX";

abbrev = " ";

uldid = "XXXXXIB";

aircraft = 700;

weight = 0.0;

destination = "None";

}

Cargo::Cargo(const string type,

const string abrv,

const string id,

const int craft,

const double wt,

const string dest)

{

uldtype = type;

abbrev = abrv;

uldid = id;

aircraft = craft;

weight = wt;

destination = dest;

}

Cargo::Cargo(const Cargo &rhs) //copy constructor

{

uldtype = rhs.uldtype;

abbrev = rhs.abbrev;

uldid = rhs.uldid;

aircraft = rhs.aircraft;

weight = rhs.weight;

destination = rhs.destination;

}

Cargo::~Cargo()

{

cout << " Cargo destructor called ";

}

void Cargo::setuldtype(string type)

{

uldtype = type;

}

void Cargo::setabbrev(string abrv)

{

abbrev = abrv;

}

void Cargo::setuldid(string id)

{

uldid = id;

}

void Cargo::setaircraft(int air)

{

aircraft = air;

}

void Cargo::setweight(double wt)

{

char ans;

cout <<"is weight in kilos(K) or pounds(P)? ";

cin >> ans;

weight = wt;

if (ans == 'K' || ans == 'k')

kilotolb(weight);

}

void Cargo::setdestination(string dest)

{

destination = dest;

}

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;

}

void Cargo::output()

{

cout << fixed << showpoint << setprecision(2);

cout << setw(19) << "Unit load type: " << getuldtype() << endl;

cout << setw(19) << "Unit abbreviation: " << getabbrev() << endl;

cout << setw(19) << "Unit identifier: " << getuldid() << endl;

cout << setw(19) << "Aircraft type: " << getaircraft() << endl;

cout << setw(19) << "Weight: " << getweight() << endl;

cout << setw(19) << "Destination code: " << getdestination() << endl;

}

void Cargo::input()

{

string type;

string abrv;

string id;

int air;

int wt;

string dest;

cout << " Input load information ";

cout << "Container or Pallet? ";

cin >> type;

setuldtype(type);

cout << " Input Unit abbreviation: ";

cin >> abrv;

setabbrev(abrv);

cout << " Input Unit id: ";

cin >> id;

setuldid(id);

cout << " Input Aircraft type: ";

cin >> air;

setaircraft(air);

cout << " Input loaded weight: ";

cin >> wt;

setweight(wt);

cout << " Input destination: ";

cin >> dest;

setdestination(dest);

cout << endl;

}

void kilotolb(double &weight)

{

weight = weight * 2.2;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Evaluate the impact of unions on nurses and physicians.

Answered: 1 week ago

Question

Describe the impact of strikes on patient care.

Answered: 1 week ago

Question

Evaluate long-term care insurance.

Answered: 1 week ago