Implementation of all the pure virtual functions
Order ID 53563633773 Type Essay Writer Level Masters Style APA Sources/References 4 Perfect Number of Pages to Order 5-10 Pages
Implementation of all the pure virtual functions
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 (firstname.lastname@example.org) 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
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
Tired of getting an average grade in all your school assignments, projects, essays, and homework? Try us today for all your academic schoolwork needs. We are among the most trusted and recognized professional writing services in the market.
We provide unique, original and plagiarism-free high quality academic, homework, assignments and essay submissions for all our clients. At our company, we capitalize on producing A+ Grades for all our clients and also ensure that you have smooth academic progress in all your school term and semesters.
High-quality academic submissions, A 100% plagiarism-free submission, Meet even the most urgent deadlines, Provide our services to you at the most competitive rates in the market, Give you free revisions until you meet your desired grades and Provide you with 24/7 customer support service via calls or live chats.