Question: CIS 2 2 B Lab 4 Itty Bitty Airfreight ( IBA ) Lab 4 5 0 0 Points Topics: Overloaded operators Files - - -

CIS 22B Lab 4 Itty Bitty Airfreight (IBA)
Lab 4
500 Points
Topics:
Overloaded operators
Files
-----------------------------------------------------------------------------------------------------------------------------------------
The anti AI constraints:
Any C++ terms, constructs and/or methodologies covered in CIS 22A are available for your use.
You may only use additional C++ constructs or terms covered in lecture or zyBook (ebook) reading
assignments found in In modules 1,2,3,4,5,6,7 and 8. Deviation from these constraints lose points.
Lab 4.1
Utilizing the code from Lab 3, add an overloaded operator == which will be used to compare
two objects to see if they are equal. C++ does not allow a direct comparison of two objects, so we
use an overloaded operator and associated code to perform the comparison. For our purposes,
two objects are equal if their abbreviation and uldid are the same.
Create an object (call it unit1) and load it with this data:
uld Pallet
abbreviation PAG
uldid PAG32597IB
aircraft -737
weight 3321 Pounds
destination SEA
Make a copy of unit1 called unit2 utilizing a copy constructor.
Create a default called unit3.
Test your overloaded == operator 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 classAt 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 file 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 7374978 OAK
Container AYF AYF23409AA 7372209 LAS
Container AAA AAA89023DL 7375932 DFW
* All weights are in pounds, dont worry about kilograms, You may
comment out that code since user interaction with the program
will be limited to file name input.
* In the input function, declare an object of type ifstream named
inputFile, which we will use to read from the file. Ask the user
for the name of the input file, and store it in a string.
* 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 uld.
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)
We will be using a different input technique in lab 5, which will make file reads
easier.
Submit your .cpp files (both 4.1 and 4.2) via Canvas. Late labs lose points.

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 Programming Questions!