Question: Topics: Inheritance Virtualization Error Handling Linked List - - - - - - - - - - - - - - - - - -

Topics:
Inheritance
Virtualization
Error Handling
Linked List
-----------------------------------------------------------------------------------------------------------------------------------------
Lab 5
Utilizing the code from Lab 4.2, replace your Cargo class with a new base class. This will be the base for two classes
created through inheritance. The rewritten Cargo class will need to have a pure virtual function to have it redefined in
the child classes. This means that the Cargo class will become an abstract class. You will be able to use many parts of
the new Cargo class in the child classes since they will have the same arguments/parameters and the same functionality.
Child class Boeing737 will have the information for our 737 aircraft, with the addition of maxload.
Unit and type: Container, Pallet or Combo Flat: AYF, AYK, AAA, AYY Containers, PAG, PMC, PLA Pallets or CFE, CFK, CFM
Combo Flats.
Maxload: 737 max load is 46000 pounds
Child class Boeing767 will have the information for our new 767 aircraft, which has the following specifications:
Unit and type: Container, Pallet or Combo Flat: AKE, APE, AKC, AQP, AQF, AAP Containers, P1P, P6P Pallets or CFQ,
CFX, CFP Combo Flats.
Maxload: 767-300 max load is 116000 pounds
Change private to protected in the Cargo class only.
Create two classes which inherit from the Cargo class: Boeing737 and Boeing767.
Each class will need to inherit a default constructor, a copy constructor, a constructor that has six parameters and all the
getters and setters. Only one more function will be built in each class, the max weight function; all the rest will be
inherited.
The unit and type data are different for each class as is the aircraft type. Maxload is provided for both aircraft. Our 737
can hold up to 46000 pounds, and our 767 can hold up to 116000 pounds.
The main function needs to call the input function and do nothing else except return to end the program.
The data file lab5data.txt is provided in Canvas for your use. Your program will be tested with different data, but the
format Is guaranteed to be correct, and not to exceed 20 lines.
In the input function loop read one line from the file each time through the loop, make sure that each piece of data is
valid; only Containers, Pallets and Combo Flat. Unit Load Abbreviations must agree with the plane type, the plane type
must be 737 or 767, and weight must be within the limits for each plane. Look at the aircraft field in the record and call
the corresponding build function to build that type of unit. Ensure that the weight totals for both types of aircraft are
not exceeded by the units assigned to them. Check to ensure that another unit would not put them over the weight
limit, if it would, then reject the unit and move on to the next unit in the file.
Store each unit object as a node in the appropriate linked list.
Once input has completed, you will have a number of objects of two different types stored in two different linked lists.
Use output to send the nodes to the screen, taking care to output all the 737 nodes together, and all the 767 nodes
together. Output the total weight of all the 737 nodes and the total weight of all the 767 nodes.
* Use the lab5data.txt file which will contain data like
the following three lines of data; lab5data.txt will have no
more than 20 lines of data
Pallet PAG PAG45982IB 7374978 OAK
Container AYF AYF23409AA 7672209 LAS
Combo Flat CFX CFX89023DL 7675932 DFW
* All weights are in pounds, dont worry about kilograms.
* 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, tell the user that the file name is
not valid and give the user another opportunity to enter a correct file name..
* In all other reads within the input function, remove the user prompt and read from the inputFile object, rather than
reading from the stdin object; that is, use >>.
This is good code for reading data from a file and parsing the data into the
appropriate variables for use in object creation. You will want to use a try
block for exception handling to get a correct file name.
while(getline(inputFile, cargostring))///read in one line of data, six or seven pieces
{
istringstream cargoISS(cargostring); ///place line in the input string stream
cargoISS >> type1;
if ((type1.compare("Combo"))==0)///looking for Combo
{
cargoISS >> type2>> abrv >> uld >> plane >> weight >> dest;///seven pieces of data
type1= type1+""+ type2;///valid Combo Flat, maybe
}
else
{
cargoISS >> abrv >> uld >> plane >> weight >> dest;///six pieces of data

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!