Question
here will be the code from 4.1 please help! thank you! #include #include using namespace std; class Lab { private: string uId; string abbreviation; string
here will be the code from 4.1 please help! thank you!
#include
using namespace std;
class Lab {
private:
string uId; string abbreviation; string uIdid; int aircraft; float weight; string destination;
public:
Lab() { uId = ""; abbreviation = ""; uIdid = ""; aircraft = 0; weight = 0; destination = ""; }
Lab(string uid, string abb, string uidid, int ac, float w, string d) { uId = uid; abbreviation = abb; uIdid = uidid; aircraft = ac; weight = w; destination = d; weightMutator(); }
Lab(const Lab& l1) { uId = l1.uId; abbreviation = l1.abbreviation; uIdid = l1.uIdid; aircraft = l1.aircraft; weight = l1.weight; destination = l1.destination; }
void weightMutator() { string w; cout>w; transform(w.begin(), w.end(), w.begin(), ::tolower); if(w == "kg" || w == "kilograms") { weight = kilotopound(*this); } }
void printData() { cout
friend float kilotopound(Lab l1);
friend bool operator==(const Lab& l1, const Lab& l2);
};
float kilotopound(Lab l1) { return l1.weight*2.2; }
bool operator==(const Lab& l1, const Lab& l2) { return((l1.abbreviation == l2.abbreviation) && (l1.uIdid == l2.uIdid)); }
int main() {
Lab unit1("Pallet", "PAG", "PAG32597IB", 737, 3321, "SEA");
Lab unit2(unit1), unit3;
if(unit1 == unit2) cout
if(unit2 == unit3) cout
string abbreviation;
string uIdid;
int aircraft;
float weight;
string destination;
cout
cout
cin>>uId;
cout
cin>>abbreviation;
cout
cin>>uIdid;
cout
cin>>aircraft;
cout
cin>>weight;
cout
cin>>destination;
Lab l(uId, abbreviation, uIdid, aircraft, weight, destination);
cout
l.printData();
Lab l2(l); cout
return 0; }
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 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.peekl) != EOF) or use this form while(inputFile >> type) 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)| *********** ***************************Step 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