C++ Assignment need to done in 4 hours

profilechenponlineassighmenthelp
CPP2017AssignmentPartAPartBandPartC.pdf

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 1 of 23

Department of Computer Science and Information Technology

La Trobe University

CSE1CPP 2017 Assignment Part A, Part B and Part C

Due Date: Monday, 16th Oct, at 10.00 a.m.

First and Final date for SUBMISSION Monday 16th Oct at 10.00 am

Delays caused by computer downtime cannot be accepted as a valid reason for a late submission. Students must plan their work to allow for both scheduled and unscheduled downtime. There are no days late or extensions on this assignment as execution test marking will begin on Tuesday 17th October – in your normal lab (Week 12)

This is an individual Assignment. You are not permitted to work as a Pair Programming partnership or any other group when writing this assignment.

Copying, Plagiarism: Plagiarism is the submission of somebody else’s work in a manner that gives the impression that the work is your own. The Department of Computer Science and Information Technology treats academic misconduct seriously. When it is detected, penalties are strictly imposed. Refer to the subject guide for further information and strategies you can use to avoid a charge of academic misconduct.

Assessment Objectives:  to gain practice using virtual functions  to practice STL containers in C++  to practice designing and implementing a solution, in C++, based on a specification

(this document)  to practice using some of the new C++11 features, including override and auto  to practice reading and writing to text files  to practice working with pointers and iterators

Submission Details: Full instructions on how to submit electronic copies of your source code files from your latcs8 account are given at the end. If you have not been able to complete a program that compiles and executes containing all functionality, then you should submit a program that compiles and executes with as much functionality as you have completed. (You may comment out code that does not compile.)

Note you must submit electronic copies of your source code files using the submit command on latcs8. Ensure you submit all required files, one file at a time. For example, the file passenger.cpp would be submitted with the command:

> submit CPP passenger.cpp

PLEASE NOTE: While you are free to develop the code for this progress check on any operating system, your solution must run on the latcs8 system.

Marking Scheme: This assignment (all parts together) is worth 30% of your final mark in this subject.

Do NOT use the LMS to submit your files, use latcs8 only

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 2 of 23

Implementation (Execution of code) 90%, explanation of code 10%

You may be required to attend a viva voce (verbal) assessment (to be used as a weighting factor on the final mark).

Return of Mark sheets: The face to face execution test marking in the lab (Week 12) constitutes a return of the assignment mark, subject to the conditions on page 21.

Please note carefully: The submit server will close at 10:00 am on Monday Oct 16th After the submit server has closed, NO assignments can be accepted. Please make sure that you have submitted all your assignment files before the submit server closes. (see page 21) There can be NO extensions or exceptions. Your assignment will be marked in your normal lab, starting week 12, Tuesday Oct 17th. You should attend your normal lab to have your assignment marked. You may come to any other week 12 lab however if you can't make your normal lab. Non-attendance at any week 12 lab will result in your assignment being awarded 0, except as detailed below. If you cannot attend any of the labs in week 12, please email me ([email protected]) to arrange another time. Marking scheme: 90% for the code executing correctly 10%, you will be asked to explain (and / or alter) parts of your code.

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 3 of 23

Please also note carefully that whilst we encourage innovation and exploring C++ beyond what has been presented in the subject to date, above all, we encourage understanding. All of the Tasks that follow can be solved using techniques that have been presented in lectures, lecture / workshops and labs so far. These are the techniques and knowledge that we will later be examining in the exam (70 marks). Code and techniques that are outside the material presented will not be examined, of course. You are free to solve the problem below in any way, provided that you can fully explain any code that is outside what has been taught.

All assignments in CPP are marked, face to face, in the lab, in an execution test. This means that we mark running code. Your code must compile and display a result to the screen. Regrettably, we don't have the time or resources to look at code. The smallest amount of code that produces and displays a correct result will gain more marks than lots of code that doesn't compile, run or display something to the screen.

Code that you are expected to use - READ THIS

How this assignment is marked

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 4 of 23

Problem Description (for all parts) SpaceWays Inc. is one of the largest companies involved in intra system and deep space transport. They have 2 kinds of space vehicles, those that carry freight and those that carry passengers. Both these space vehicles share some things in common, detailed below, and have specialized differences. Freight space vehicles carry containers known as modules. Freight space vehicles have a maximum capacity, which varies between all freight space vehicles. The maximum capacity is configurable and is set be the user as the freight space vehicle is assembled. Once the maximum capacity is set it may not be altered. Passenger space vehicles carry passengers. Passengers are known as guests. Passenger space vehicles are also completely configurable. There is no limit to the number of guests that a passenger space vehicle can carry. SpaceWays Inc. has commissioned you to write a program, in C++, to manage the basic operations of their fleet of space vehicles. Problem Implementation Part A (20 marks) (Part B see page 21, Part C see page 21) As SpaceWays is in urgent need of this program, some files have been provided for you. These are central.h, central.cpp, freight.h, freight.cpp, guest.h, guest.cpp, module.h, module.cpp, passenger.h, passenger.cpp, spaceVehicle.h, spaceVehicle.cpp and makefile. There is also a sample data file sc01.dat for you to use when testing your program. So long as you use the files provided, then using the makefile will compile all of the files into a C++ program. To run the program, after it successfully compiles, just type spaceWays These files can be copied by typing this command on latcs8 cp ~csilib/cse1cpp/assignABC/* . (don't forget the . (dot) for your current directory) Note: when this document talks about concrete sub classes and concrete functions, it means that they are not abstract, there is actual code (implementation) in the class or function. We should be able to make (construct) an object of a "concrete" class.

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 5 of 23

SpaceVehicle class This is the abstract base class for Freight and Passenger space vehicles. All space vehicles have the following common attributes: id this is a string (text) and is the unique identifier for that SpaceVehicle. This id may

any combination of characters and digits.

For this problem, you may assume that the user always enters a unique identifier, there is no need to check.

type this is a string (text) and is to the value of one of "Freight" or "Passenger", more on this below. The SpaceVehicle class requires the following functionality:  A default constructor  A virtual destructor

 overloaded friend functions to aid in writing to the screen, writing to a text file, reading

in from the keyboard and reading from a text file.  accessor (get) functions as you deem appropriate.

 A display function (abstract, pure virtual)

The display function is a "wrapper" function that simply calls the overloaded ostream friend function of the SpaceVehicle class.

 A file write out function (abstract, pure virtual)

This takes an ofstream object as a parameter. The purpose of this function is also to act as "wrapper" function for the overloaded ofstream friend function of the SpaceVehicle class.

 A keyboard read in function (abstract, pure virtual)

This function is a "wrapper" function for the overloaded istream friend function of the SpaceVehicle class

 A file read in function (abstract, pure virtual)

This function is a "wrapper" function for the overloaded ifstream friend function of the SpaceVehicle class

Why do we need these "wrapper" functions?

We are using inheritance in this problem and only member functions can be part of the inherited, virtual, polymorphic mechanism. Rather than write a lot of if, else if, statements using typeid, we want to be able to get C++ to decide, through the virtual functions, which actual sub class is involved. Making the functions pure virtual in the base class guarantees the sub classes must implement overridden, concrete, functions of the same name in their classes. If the sub class does not implement ALL of the abstract functions of the base class, then the sub class is itself abstract.

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 6 of 23

When we store a sub class object in a vector, for instance, of base class objects or pointers, then we can store the sub class objects in that vector. You can always put a sub class object in to something that expects a base class. However, only the virtual functions of the sub class override the base class functions of the same name. This means that when you access the base class object, you actually use the sub class virtual functions (C++ has their address through the virtual mechanism). This is the point, we can leave it up to C++ to figure out which actual class (base class or sub class) to go into to run the function we just called. This is what the member "wrapper" functions do, they get us into the correct sub class. Once in the correct sub class, then they can call the friend functions of that class. Friend functions cannot be inherited and so cannot be virtual. This means that we would need to explicitly cast the base class objects back to their original sub class objects before we could call them. Much better to let C++ figure out via the "wrapper" virtual member functions. Freight class This is a concrete sub class of the SpaceVehicle class The Freight class has the following attributes: maximum capacity this is an integer and is the maximum number of Modules that the Freight vehicle can accommodate. current modules this is an integer and is the actual number of Modules that the Freight vehicle currently holds. cargo this is a list of Modules (Module objects) that are actually in the Freight vehicle The Freight class requires the following functionality:  A default constructor, actually loading the object with values for its attributes will be

done by the virtual functions.

 A function to add a Module to the cargo list. This function should take an existing Module object as a parameter. Before adding a Module to the list, the program needs to check that adding this Module will not exceed the maximum capacity of the Freight vehicle. This check can be done in the main program (central.cpp) or it can be done in this class. Either way we must not be able to add a Module if it exceeds the maximum capacity of the particular Freight vehicle.

 All of the abstract virtual functions from the base class need actual implementation. As

explained, almost all of these just call the appropriate friend function in the class.  The setType function just sets the base class, protected, type attribute to

"Freight"

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 7 of 23

 This class will need overloaded friend functions for ostream, ofstream, istream and ifstream.

 The ostream overloaded friend function needs to return information about the

Freight space vehicle AND the details of the Modules that are carried in that Freight object, see page 15 for an example of the output.

 This is where you start by using the virtual member function display. This takes us

to the Freight class, where the display function then calls the overloaded ostream operator in the Freight class. This in turns starts by calling the overloaded ostream operator for the base class SpaceVehicle, using dynamic casting as we done before. (Note that static_cast is acceptable here and actually gives better performance)

 The ofstream overloaded friend function needs to write information about the

Freight object back to text file. The format must exactly match the format of the example input text file shown on pages 9 - 10.

 This is where you start by using the virtual member function fileWrite, which takes

an ofstream object as a parameter. Once again, C++ goes to the Freight class and the fileWrite function then calls the overloaded ofstream operator for the Freight class. This in turn starts by calling the overloaded ofstream operator in the base class SpaceVehicle, again using dynamic casting (or static_cast).

 Your output file must be able to be used as an input file, the next time that the program

is executed.  Reading in from the keyboard is the same idea. Call the virtual member function

readIn and that will in turn call the overloaded istream operator for the Freight class, which in turn starts by calling the overloaded istream operator for the base class SpaceVehicle.

 Reading from the file is the same idea, just using the fileReadIn virtual member

function. Since we have made many of the functions in the base class (SpaceVehicle) pure virtual, meaning no implementation, how do we access the friend functions of the base class from the friend functions of the sub class? This is where we use dynamic_cast, which we have seen and used before, to temporarily cast from the sub class back to the base class. Once the base class friend function has been run, then the program will automatically return to the sub class and then we can deal the actual parts of the sub class. Module class This is a concrete, standalone class (no inheritance). Modules are what is carried (stored in) a Freight class object.

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 8 of 23

The Module class has the following attributes: module id this is a string and is the unique id of that Module. It may be any combination

of digits and text and may be more than one word. (For this program you may assume that the user always enters a unique Module id, it is not necessary to have the program check that the id is indeed unique)

contents this is a string (text) and describes the contents of a particular Module, may be more than one word. The Module class needs the following functionality:  overloaded friend functions for ostream, ofstream, istream and ifstream

 a default constructor

 an overloaded constructor that takes a string id and a string contents as

parameters. This will be useful when reading from the text file.  accessor and mutator methods as you deem appropriate, although keep in mind that

the id, once set, should NOT be able to be changed. class Passenger This is a concrete sub class of SpaceVehicle class. The Passenger class has the following attributes: number of guests this is an integer and is the actual number of guests in a particular Passenger object. (Recall that there is no limit to the number of guests that can be in a particular Passenger object) guest list this is a list of the actual guests in the particular Passenger object. The Passenger class requires the following functionality:  A default constructor, actually loading the object with values for its attributes will be

done by the virtual functions.  Implementation of all the pure virtual functions from the SpaceVehicle class.

 overloaded friend functions for ostream, ofstream, istream and ifstream

 concrete implementation of the setType function. This sets the protected

SpaceVehicle class attribute type to "Passenger"  a function to add a guest to the list of guests. This function takes an existing Guest

object as a parameter.  The virtual member functions work the same way as described above in the Freight

class, except we are reading and writing Passenger/Guest information instead of Freight/Module information.

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 9 of 23

class Guest This is a concrete, stand alone class. The Guest class has the following attribute: name this is string and is the name of the Guest, may be more than one word ticket this is string and is the ticket number of the Guest. May be any combination of digits and characters and may be more than one word. The Guest class requires the following functionality:  A default constructor

 An overloaded constructor that takes string name and string ticket as

parameters. This constructor is used when reading from a text file.  Neither name nor ticket can be altered once they are set by the constructor.

 overloaded friend functions for ostream, ofstream, istream and ifstream

Program functionality The program starts by asking the user for the name of an input text file. The format of this file is shown on pages 9 - 10 and is guaranteed to be correct. The file may not exist, if does exist, then it will not be empty. The first line of a record (complete information about a Freight or Passenger object) is the name of the actual, concrete, sub class. File entry Meaning Freight This is the type of the actual sub class HF 002 This is the unique id of the Freight space vehicle 34 This is the maximum number of Modules that can be carried 3 This is the actual number of Modules carried C 001 This is the unique id of the Module CPP Stuff This is the contents of the Module FG 67 This is the unique id of the Module More CPP Stuff This is the contents of the Module N 12 This is the unique id of the Module Stuff for CPP This is the contents of the Module Passenger This is the type of the actual sub class L 21 This is the unique id of the Passenger space vehicle 3 This is the actual number of Guests on board First Pass name of the Guest A 01 ticket number Second Pass name of the Guest A 02 ticket number Third Pass name of the Guest A 03 ticket number Freight This is the type of the actual sub class HF 001 This is the unique id of the Freight space vehicle

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 10 of 23

14 This is the maximum number of Modules that can be carried 0 This is the actual number of Modules carried

Your program must work with input files that contain any number of records, not just the 3 shown in this example. Your program must work with any file in the correct format. You may assume that if a file exists it is in the correct format. For a Freight object, the next 3 lines, after the first line Freight, are the information about the Freight object. The next line after that is the number of actual Module objects stored in the list in the Freight object. Use this number to know how many times to loop through reading Module records, just 2 lines, the id and the contents, creating Module objects and adding them to the list in the Freight object. All this will be in the overloaded ifstream operator of the Freight class. It is this operator which will contain the loop that reads the correct number of Module records. (Remember to write the number of Modules back into the text file in the correct position when you choose the save option). Once this Freight object has been fully instantiated, it is added to the back of the vector in the main driver program, central.cpp For a Passenger object, it is just the next line after the line Passenger, that has the information for a Passenger object, the id. The next line after that is the number of Guest objects that are stored in the list in the Passenger object. As with the Freight class, use this number to loop through reading Guest records, 2 lines, name and ticket, creating Guest objects and adding them to the list in the Passenger object. Once again, this loop will be in the Passenger ifstream overloaded operator (Remember to write the number of Guests back into the text file in the correct position when you choose the save option). The input may contain any number of Freight/Module and Passenger/Guest records in any order. close the file once it has been read in. Then the program shows the menu to the user. NOTE: all menus must be able to handle the user entering data of the wrong type, for example, entering a string where an int was expected, without crashing the program. The menu looks like this CENTRAL SPACEWAYS MAIN MENU 1. Add Menu 2. Display Menu 3. Save 4. Exit Enter choice >>

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 11 of 23

1. Add Menu This menu option displays a sub menu with the following choices: CENTRAL SPACEWAYS ADD MENU 1. Add Freight Vehicle 2. Add Passenger Vehicle 3. Add Module 4. Add Guest 5. Return to main menu Enter choice >> 1. Add Freight Vehicle This sub menu option prompts (asks) the user for the id of a Freight Space Vehicle. Recall that it is assumed that the user always enters a unique id, so it is not necessary for the program to check. The user is then prompted for the maximum capacity of this Freight Space Vehicle NO Module information is added in this menu choice. The Freight object is then added to the back of the vector of SpaceVehicles. 2. Add Passenger Vehicle This sub menu option prompts (asks) the user for the id of a Passenger Space Vehicle. Again, assume that the user always enters a unique id NO Guest information is added in this menu choice The Passenger object is then added to the back of the vector of SpaceVehicles. 3. Add Module This sub menu option prompts (asks) the user for the id of a Freight Space Vehicle. If a Freight Space Vehicle with that id is found in the vector of SpaceVehicles, then the program must check that the Freight object has not

already reached its maximum capacity.

If the Freight object with that id exists and it has not reached maximum capacity, then the user is prompted (asked) to enter the id of the Module and

contents. The Module is then added to the list of Modules for that Freight object. Again, assume that the user enters a unique Module id, it is not necessary for the program to check.

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 12 of 23

If the id entered for the Freight Space Vehicle does not exist, or the Freight Space Vehicle is already at maximum capacity, then appropriate messages

should be displayed to the screen and no further information is to be requested from the user.

4. Add Guest

This sub menu option prompts (asks) the user for the id of a Passenger Space Vehicle. If a Passenger Space Vehicle with that id is found in the vector of SpaceVehicles, then the user is prompted for the name and the ticket number of a Guest. The Guest is added to the back of the list for that Passenger object. If the id entered for the Passenger Space Vehicle does not exist, than an

appropriate message is displayed to the screen and no further information is requested from the user.

5. Return to main menu This sub menu option just returns to the main menu.

2. Display Menu This menu choice displays a sub menu with the following choices: CENTRAL SPACEWAYS DISPLAY MENU 1. Display All 2. Return to main menu Enter choice >>

1. Display All

This sub menu option displays the contents of the entire vector to the screen. See page 15 for an example. The output may be formatted in any way you like, provided that is readable and easy for the user to understand. (Displaying everything on just one line would NOT be an acceptable solution)

2. Return to main menu This sub menu option just returns to the main menu.

3. Save This function prompts (asks) the user for the name of an output text file. All the information in the vector is written into this text file. The information must be written using the format above. Your output file must be able to be used as an input file the next time that the

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 13 of 23

program is run. This function returns to the main menu when all the information is written back to the file. The program does NOT exit. 4. Exit This option just closes the program, without saving anything or prompting the user if they want to save their information Sample run of the program Note that not every condition is shown in the sample below, because a condition is not shown does NOT mean that it must not be implemented, or that it will not be tested and marked. User input is in bold > spaceWays Enter input filename >> sc01.dat CENTRAL SPACEWAYS MAIN MENU 1. Add Menu 2. Display Menu 3. Save 4. Exit Enter choice >> 2 CENTRAL SPACEWAYS DISPLAY MENU 1. Display All 2. Return to main menu Enter choice >> 1 Here is the complete list of Space Vehicles Type: Freight Id: HF 002 Maximum capacity: 34 Current number of modules on board: 3 Module: id : C 001 Contents: CPP Stuff Module: id : FG 67 Contents: More CPP stuff Module: id : N 12 Contents: Even More CPP stuff Type: Freight Id: A 4 WQ Maximum capacity: 3 Current number of modules on board: 2 Module: id : A 4 001 Contents: WQ Stuff Module: id : A 4 002 Contents: Wouldn't you like to know Type: Passenger Id: L 21 Number of guests : 3 Guest: name: First Pass has ticket: A 01 Guest: name: Second Pass has ticket: A 02 Guest: name: Third Pass has ticket: A 03

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 14 of 23

Type: Freight Id: HF 001 Maximum capacity: 14 Current number of modules on board: 0 CENTRAL SPACEWAYS DISPLAY MENU 1. Display All 2. Return to main menu Enter choice >> 2 CENTRAL SPACEWAYS MAIN MENU 1. Add Menu 2. Display Menu 3. Save 4. Exit Enter choice >> 1 CENTRAL SPACEWAYS ADD MENU 1. Add Freight Vehicle 2. Add Passenger Vehicle 3. Add Module 4. Add Guest 5. Return to main menu Enter choice >> 3 Enter Freight Vehicle id >> A 4 WQ Enter module id >> Z 21 Enter contents >> function objects CENTRAL SPACEWAYS ADD MENU 1. Add Freight Vehicle 2. Add Passenger Vehicle 3. Add Module 4. Add Guest 5. Return to main menu Enter choice >> 3 Enter Freight Vehicle id >> A 4 WQ This Freight vehicle is already at capacity CENTRAL SPACEWAYS ADD MENU 1. Add Freight Vehicle 2. Add Passenger Vehicle 3. Add Module 4. Add Guest 5. Return to main menu Enter choice >> 4 Enter Passenger Vehicle id >> AA 23 No Passenger Space Vehicle with that id was found CENTRAL SPACEWAYS ADD MENU 1. Add Freight Vehicle 2. Add Passenger Vehicle 3. Add Module 4. Add Guest 5. Return to main menu Enter choice >> 5

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 15 of 23

CENTRAL SPACEWAYS MAIN MENU 1. Add Menu 2. Display Menu 3. Save 4. Exit Enter choice >> 2 CENTRAL SPACEWAYS DISPLAY MENU 1. Display All 2. Return to main menu Enter choice >> 1 Here is the complete list of Space Vehicles Type: Freight Id: HF 002 Maximum capacity: 34 Current number of modules on board: 3 Module: id : C 001 Contents: CPP Stuff Module: id : FG 67 Contents: More CPP stuff Module: id : N 12 Contents: Even More CPP stuff Type: Freight Id: A 4 WQ Maximum capacity: 3 Current number of modules on board: 3 Module: id : A 4 001 Contents: WQ Stuff Module: id : A 4 002 Contents: Wouldn't you like to know Module: id : Z 21 Contents: function objects Type: Passenger Id: L 21 Number of guests : 3 Guest: name: First Pass has ticket: A 01 Guest: name: Second Pass has ticket: A 02 Guest: name: Third Pass has ticket: A 03 Type: Freight Id: HF 001 Maximum capacity: 14 Current number of modules on board: 0 CENTRAL SPACEWAYS DISPLAY MENU 1. Display All 2. Return to main menu Enter choice >> 2 CENTRAL SPACEWAYS MAIN MENU 1. Add Menu 2. Display Menu 3. Save 4. Exit Enter choice >> 1

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 16 of 23

CENTRAL SPACEWAYS ADD MENU 1. Add Freight Vehicle 2. Add Passenger Vehicle 3. Add Module 4. Add Guest 5. Return to main menu Enter choice >> 2 Enter id >> L 22 CENTRAL SPACEWAYS ADD MENU 1. Add Freight Vehicle 2. Add Passenger Vehicle 3. Add Module 4. Add Guest 5. Return to main menu Enter choice >> 4 Enter Passenger Vehicle id >> L 22 Enter name >> Fourth Pass Enter ticket >> DD 3 CENTRAL SPACEWAYS ADD MENU 1. Add Freight Vehicle 2. Add Passenger Vehicle 3. Add Module 4. Add Guest 5. Return to main menu Enter choice >> 5 CENTRAL SPACEWAYS MAIN MENU 1. Add Menu 2. Display Menu 3. Save 4. Exit Enter choice >> 2 CENTRAL SPACEWAYS DISPLAY MENU 1. Display All 2. Return to main menu Enter choice >> 1 Here is the complete list of Space Vehicles Type: Freight Id: HF 002 Maximum capacity: 34 Current number of modules on board: 3 Module: id : C 001 Contents: CPP Stuff Module: id : FG 67 Contents: More CPP stuff Module: id : N 12 Contents: Even More CPP stuff Type: Freight Id: A 4 WQ Maximum capacity: 3 Current number of modules on board: 3 Module: id : A 4 001 Contents: WQ Stuff Module: id : A 4 002

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 17 of 23

Contents: Wouldn't you like to know Module: id : Z 21 Contents: function objects Type: Passenger Id: L 21 Number of guests : 3 Guest: name: First Pass has ticket: A 01 Guest: name: Second Pass has ticket: A 02 Guest: name: Third Pass has ticket: A 03 Type: Freight Id: HF 001 Maximum capacity: 14 Current number of modules on board: 0 Type: Passenger Id: L 22 Number of guests : 1 Guest: name: Fourth Pass has ticket: DD 3 CENTRAL SPACEWAYS DISPLAY MENU 1. Display All 2. Return to main menu Enter choice >> 2 CENTRAL SPACEWAYS MAIN MENU 1. Add Menu 2. Display Menu 3. Save 4. Exit Enter choice >> hello Please enter an integer CENTRAL SPACEWAYS MAIN MENU 1. Add Menu 2. Display Menu 3. Save 4. Exit Enter choice >> 1 CENTRAL SPACEWAYS ADD MENU 1. Add Freight Vehicle 2. Add Passenger Vehicle 3. Add Module 4. Add Guest 5. Return to main menu Enter choice >> 1 Enter id >> ZX 44 Enter maxCap >> 19 CENTRAL SPACEWAYS ADD MENU 1. Add Freight Vehicle 2. Add Passenger Vehicle 3. Add Module 4. Add Guest 5. Return to main menu

Note that your program is expected to be able to handle incorrect inputs of the wrong type without crashing.

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 18 of 23

Enter choice >> 5 CENTRAL SPACEWAYS MAIN MENU 1. Add Menu 2. Display Menu 3. Save 4. Exit Enter choice >> 2 CENTRAL SPACEWAYS DISPLAY MENU 1. Display All 2. Return to main menu Enter choice >> 1 Here is the complete list of Space Vehicles Type: Freight Id: HF 002 Maximum capacity: 34 Current number of modules on board: 3 Module: id : C 001 Contents: CPP Stuff Module: id : FG 67 Contents: More CPP stuff Module: id : N 12 Contents: Even More CPP stuff Type: Freight Id: A 4 WQ Maximum capacity: 3 Current number of modules on board: 3 Module: id : A 4 001 Contents: WQ Stuff Module: id : A 4 002 Contents: Wouldn't you like to know Module: id : Z 21 Contents: function objects Type: Passenger Id: L 21 Number of guests : 3 Guest: name: First Pass has ticket: A 01 Guest: name: Second Pass has ticket: A 02 Guest: name: Third Pass has ticket: A 03 Type: Freight Id: HF 001 Maximum capacity: 14 Current number of modules on board: 0 Type: Passenger Id: L 22 Number of guests : 1 Guest: name: Fourth Pass has ticket: DD 3 Type: Freight Id: ZX 44 Maximum capacity: 19 Current number of modules on board: 0

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 19 of 23

CENTRAL SPACEWAYS DISPLAY MENU 1. Display All 2. Return to main menu Enter choice >> 2 CENTRAL SPACEWAYS MAIN MENU 1. Add Menu 2. Display Menu 3. Save 4. Exit Enter choice >> 1 CENTRAL SPACEWAYS ADD MENU 1. Add Freight Vehicle 2. Add Passenger Vehicle 3. Add Module 4. Add Guest 5. Return to main menu Enter choice >> 3 Enter Freight Vehicle id >> ZX 44 Enter module id >> 23 E Enter contents >> overloaded functions CENTRAL SPACEWAYS ADD MENU 1. Add Freight Vehicle 2. Add Passenger Vehicle 3. Add Module 4. Add Guest 5. Return to main menu Enter choice >> 3 Enter Freight Vehicle id >> ZX 44 Enter module id >> 23 F Enter contents >> STL components CENTRAL SPACEWAYS ADD MENU 1. Add Freight Vehicle 2. Add Passenger Vehicle 3. Add Module 4. Add Guest 5. Return to main menu Enter choice >> 5 CENTRAL SPACEWAYS MAIN MENU 1. Add Menu 2. Display Menu 3. Save 4. Exit Enter choice >> 2 CENTRAL SPACEWAYS DISPLAY MENU 1. Display All 2. Return to main menu Enter choice >> 1 Here is the complete list of Space Vehicles Type: Freight Id: HF 002 Maximum capacity: 34

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 20 of 23

Current number of modules on board: 3 Module: id : C 001 Contents: CPP Stuff Module: id : FG 67 Contents: More CPP stuff Module: id : N 12 Contents: Even More CPP stuff Type: Freight Id: A 4 WQ Maximum capacity: 3 Current number of modules on board: 3 Module: id : A 4 001 Contents: WQ Stuff Module: id : A 4 002 Contents: Wouldn't you like to know Module: id : Z 21 Contents: function objects Type: Passenger Id: L 21 Number of guests : 3 Guest: name: First Pass has ticket: A 01 Guest: name: Second Pass has ticket: A 02 Guest: name: Third Pass has ticket: A 03 Type: Freight Id: HF 001 Maximum capacity: 14 Current number of modules on board: 0 Type: Passenger Id: L 22 Number of guests : 1 Guest: name: Fourth Pass has ticket: DD 3 Type: Freight Id: ZX 44 Maximum capacity: 19 Current number of modules on board: 2 Module: id : 23 E Contents: overloaded functions Module: id : 23 F Contents: STL components CENTRAL SPACEWAYS DISPLAY MENU 1. Display All 2. Return to main menu Enter choice >> 2 CENTRAL SPACEWAYS MAIN MENU 1. Add Menu 2. Display Menu 3. Save 4. Exit Enter choice >> 3 Enter output file name >> sc03.dat

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 21 of 23

CENTRAL SPACEWAYS MAIN MENU 1. Add Menu 2. Display Menu 3. Save 4. Exit Enter choice >> 4

Part B (5 marks) There are one or two places in the code, particularly adding Freight and Passenger objects in the main driver program, that are the same except for the data types. Pick one of these instances and re-write the code to use a template function (or functions) keep your original non-templated code, just comment it out, so that you can show the difference between the template and non-templated versions

Part C (5 marks) Further enhance the program. Add a feature of your own choosing. It may be adding a function object, or more than one, so that the user could the sort the vector in main so that it had all Freight Space Vehicles at the front, in id order, followed by all Passenger Vehicles, in id order, at the back. Or the vector could be sorted so the objects with the most Modules/Guests were at the front Or the program could check that when the user enters an id (for anything) the program actually checks that that id is unique. These are just a few possibilities, feel free to use one of these or your own idea.

Electronic Submission of the Source Code  Submit all the Java files that you have developed in the tasks above.  The code has to run under Unix on the latcs8 machine.  You submit your files from your latcs8 account. Make sure you are in the same directory

as the files you are submitting. Submit each file separately using the submit command.

submit CPP central.h submit CPP central.cpp submit CPP freight.h submit CPP freight.cpp submit CPP guest.h submit CPP guest.cpp submit CPP module.h submit CPP module.cpp submit CPP passenger.h submit CPP passenger.cpp submit CPP spaceVehicle.h submit CPP spaceVehicle.cpp submit CPP makefile

After submitting the files, you can run the following command that lists the files submitted from your account:

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 22 of 23

verify

You can submit the same filename as many times as you like before the assignment deadline; the previously submitted copy will be replaced by the latest one. Please make sure that you have read page 2 about the submission close off date and time and the compulsory requirement to attend the execution test in Week 12 Failure to do both of these things will result in your assignment be awarded a mark of 0, regardless of the correctness of the program. Execution test marks are provisional and subject to final plagiarism checks and checks on the compliance of your code to this assignment document. As such final assignment marks may be lower or withdrawn completely.

Final Notes: - transferring files between Windows and Unix Be very careful transferring files from Windows to Unix. If you do transfer a file from Windows to Unix open the file, in Unix, using vi. For example, if you transferred a file named b.txt from Windows to Unix open the file in Unix with the command vi –b b.txt you will (might) see a lot of ^M's at the end of each line. These MUST be removed using the command shown below or else your input file will have too many newline characters and will not translate properly. That is, your code will not correctly read the input file. Your code will work on Windows but NOT on Unix. Still in vi, in command mode (press the Esc key first) do the following :%s/ctrl-v ctrl-m//g ctrl-v ctrl-m means hold down the control key and with the control key down press v then press m. Final, final notes

Don't let anyone look at your code and definitely don't give anyone a copy of your code. The plagiarism checker will pick up that the assignments are the same and you will both get 0 (it doesn't matter if you can explain all your code).

CPP Assignment Part A, B, C - due: 10:00 am Mon 16th Oct this is the first and final hand in date p. 23 of 23

There will be consultation sessions for the assignment, the times will be posted on LMS, if you have problems come to consultation. And a final, final, final note, "eat the dragon in little bits". Do a little bit every night; before you know it you will be finished. The assignment is marked with running code, so you are better to have 1 or 2 parts completed that actually compile and run, rather than a whole lot of code that doesn't compile.

The execution test is done on latcs8 so please make sure that your code runs on latcs8 before you submit.