Question
C++ Only! Please make a private data! Not a public!! --------------------------------------------------------------------------------------------------------- Lab 4.1 #include #include using namespace std; class Cargo { private: string uldtype; string
C++ Only!
Please make a private data! Not a public!!
---------------------------------------------------------------------------------------------------------
Lab 4.1
#include
class Cargo { private: string uldtype; string abbreviation; string uldid; int aircraft; int weight; string destination; public: Cargo(); Cargo(const string uldtype, const string abbreviation, const string uldid, const int aircraft, const int weight, const string destination); Cargo(const Cargo& c2); ~Cargo(); void setuldtype(string uldt); void setabbreviation(string abb); void setuldid(string uldi); void setaircraft(int airc); void setweight(int w); void setdestination(string des); string getuldtype(); string getabbreviation(); string getuldid(); int getaircraft(); int getweight(); string getdestination(); void input(); void output(); friend int kilotopound(int kilogram); friend bool operator == (const Cargo &, const Cargo &);
}; int kilotopound(int kilogram) { return 2.2 * kilogram; }
bool operator == (const Cargo &c1, const Cargo &c2) { return (c1.abbreviation == c2.abbreviation && c1.uldid == c2.uldid); }
int main() { cout
Cargo unit1("Pallet","PAG","PAG32597IB",737,3321,"SEA"); Cargo unit2 = unit1; Cargo unit3; if (unit1 == unit2) cout
Cargo::Cargo(const Cargo& c2) { uldtype = c2.uldtype; abbreviation = c2.abbreviation; uldid = c2.uldid; aircraft = c2.aircraft; weight = c2.weight; destination = c2.destination; }
Cargo::Cargo() { uldtype = ""; abbreviation = "XXX"; uldid = "xxxxxIB"; aircraft = 700; weight = 0; destination = " "; }
Cargo::Cargo(const string type, const string abb, const string id, const int craft, const int wt, const string dest) { uldtype = type; abbreviation = abb; uldid = id; aircraft = craft; weight = wt; destination = dest; }
Cargo::~Cargo() { cout
void Cargo::setuldtype(string uldt) { uldtype = uldt; }
void Cargo::setabbreviation(string abb) { abbreviation = abb; }
void Cargo::setuldid(string uldi) { uldid = uldi; }
void Cargo::setaircraft(int airc) { aircraft = airc; }
void Cargo::setweight(int w) { weight = w; cout > c; if (c == 'y') weight = kilotopound(w); cout
void Cargo::setdestination(string des) { destination = des; }
string Cargo::getuldtype() { return uldtype; }
string Cargo::getabbreviation() { return abbreviation; }
string Cargo::getuldid() { return uldid; }
int Cargo::getaircraft() { return aircraft; }
int Cargo::getweight() { return weight; }
string Cargo::getdestination() { return destination; }
void Cargo::output() { cout
}
void Cargo::input() { string uldt, uldi, des, abb; int airc, w; cout > uldt; setuldtype(uldt); cout > abb; setabbreviation(abb); cout > uldi; setuldid(uldi); cout > airc; setaircraft(airc); cout > w; setweight(w); cout > des; setdestination(des); }
---------------------------------------------------------------------------------------------------------
Again, please make a private data. Not a public!
Thanks.
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 PAG459821B 737 4978 OAK. Container AYE AYF23409AA 737 2209 LAS. Container AAA AAA89023DL 737 5932 DFW.. All weights are in pounds, don't 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 input file 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 CarStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started