Question: CIS 2 2 B Lab 4 Itty Bitty Airfreight ( IBA ) Lab 4 5 0 0 Points Topics: Overloaded operators Files - - -
CIS B Lab Itty Bitty Airfreight IBA
Lab
Points
Topics:
Overloaded operators
Files
The anti AI constraints:
Any C terms, constructs andor methodologies covered in CIS A 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 and Deviation from these constraints lose points.
Lab
Utilizing the code from Lab 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 unit and load it with this data:
uld Pallet
abbreviation PAG
uldid PAGIB
aircraft
weight Pounds
destination SEA
Make a copy of unit called unit utilizing a copy constructor.
Create a default called unit
Test your overloaded operator with code like this in main:
if unit unit
cout
unit is the same as unit
;
else
cout
unit is not the same as unit
;
if unit unit
cout
unit is the same as unit
;
else
cout
unit is not the same as unit
;
Lab
Using the code from lab 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
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 cardatatxt 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 PAGIB OAK
Container AYF AYFAA LAS
Container AAA AAADL 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:
whileinputFilepeek
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:
whileinputFilepeek EOF or use this form whileinputFile 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 commentif any
We will be using a different input technique in lab which will make file reads
easier.
Submit your cpp files both and via Canvas. Late labs lose points.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
