Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

here is the data Need help with c++ Here is my code from 4.1 Thank you! #include #include using namespace std; class Lab { private:

image text in transcribedimage text in transcribed

image text in transcribedhere is the data

Need help with c++

Here is my code from 4.1

Thank you!

#include #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: * 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) ************* *********** ******* Pallet Container Container PAG AYF AAA PAG459821B AYF23409AA AAA8 902 3DL 737 737 737 4978 2209 5932 OAK LAS DEW

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

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions