Question: IN C++ Please Lab 4.1 Utilizing the code from Lab 3.2, add an overloaded operator == which will be used to compare two objects to

IN C++ Please

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 4.2 Using the code from lab 4.1, add the ability to read from a file. Modify the input function: * Move the input function out of the Cargo class to just below the end of the Cargo class * At the bottom of the input function, declare a Cargo object named temp using the constructor that takes the six parameters. * Use the Cargo output function to print the Cargo object. * Call the input function from the main function with no arguments. Remove the rest of the code from main

3. Create a file and use it for input. This is good because you will be using the input many times. * Create a file named cardata4.txt (or use the one provided), containing the following three lines of data. If you create your own, make sure to follow the format below: Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW * All weights are in pounds, dont worry about kilograms. You may comment out that code. * In the input function, declare an object of type ifstream named inputFile, which we will use to read from the file. * At the beginning of the code for the input function, open the file. If the open fails, send a message to stderr and exit the program. * In all the reads within the input function, remove the user prompt and read from the inputFile object, rather than reading from the stdin object. * Hint: We need to use getline when reading the strings. using >> skips leading white space before reading the data. getline does not skip this leading whitespace. So, before using getline use the following code: while(inputFile.peek() == ' ') inputFile.get(); peek looks at the next character you are about to read. If it is a space, get is used to read the space character, to get it out of the way. Your output will then be much neater. * Use a loop to read each line from the file. To do this use a while loop including all the reading in the input function, as well building and output of the Car. Hint: you can do this with the following while statement: while(inputFile.peek() != EOF) or use this form while(inputFile >> type) The peek function will return EOF if there is no next character. * At the bottom of the input function, close the file. Put an eye catcher before the beginning of each function, class, and the global area: // class name function name comment(if any) *************************************************

Lab 3.2

#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

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!