Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Design a Ship class that has the following members: - A member variable for the name of the ship (string) - A member variable

1. Design a Ship class that has the following members: - A member variable for the name of the ship (string) - A member variable for the year the ship was built (int) - A default constructor that sets the name to the empty string and the year to zero - An overloaded constructor that accepts values for the name and year and assigns them to the data members - Accessors and mutators for the name and year - A virtual display function displayShip that displays the ship's name and the year it was built Store the declaration for this class in a file called prog7ship.h. Implement functions in .cpp file of same name.

2. Design a CruiseShip class that is derived from the Ship class with: - A member variable for the cruise departure date (string) - A member variable for the maximum number of passengers (int) - A member variable for the number of passengers signed up for the cruise (int) - A default constructor that invokes the Ship default constructor to initialize the inherited data members and sets the CruiseShip fields to zero or the empty string. - A second constructor that accepts a cruise ship's name, year, departure date, maximum number of passengers and number signed up. Pass the first two arguments to the Ship constructor and use the last three to set the CruiseShip's data members. - A member function to calculate the percentage filled for the cruise (number signed up / maximum number of passengers) - A displayShip function that overrides the displayShip function in the base class. It should display the ship's name, year, departure date, maximum number of passengers, passengers signed up for the cruise and the percentage filled for the cruise. Store the declaration for the CruiseShip class in the file prog7cruiseship.h. Implement functions in .cpp file of same name.

3. Design a FerryShip class that is derived from the Ship class with: - A member variable for the maximum number of passengers (int) - A member variable for the maximum number of cars (int) - A default constructor that invokes the Ship default constructor to initialize the inherited data members and sets number of passengers and cars to zero. - A second constructor that accepts a ferry ship's name, year, people and car capacity. Pass the first two arguments to the Ship constructor and use the last two to set the FerryShip's data members. - A displayShip function that overrides the displayShip function in the base class. It should first call the base class's function (to display the ship's name and year) and then display the ship's data members. Store the declaration for the FerryShip class in the file prog7ferryship.h. Implement functions in .cpp file of same name.

4. Write a client program called prog7client.cpp to demonstrate the three ship classes. - Declare a Ship object initializing the data members with "Flying Dutchman" and "1795". - Declare a CruiseShip object with arguments for all data members using the values "Titanic", 1912, 4/10/12, 2200 and 1324. - Declare a FerryShip object initializing the data members with "Barberi" 1981, 6,000 and 0. - Call the displayShip function to display the information about each of these objects.

5. When your program is working correctly, define an array of pointers to Ship objects to store pointers of up to fifteen Ship, CruiseShip or FerryShip objects. Then read in the data from the file prog7.txt. For each set of ship data it contains a code to indicate whether the data that follows is for a "S"hip, "C"ruise ship or "F"erry ship. - If the code is "S" then the code is followed by the ship's name and year. - If the code is "C" then the ships name, year, date of departure, maximum number of passengers and number of passengers signed up for the cruise are also included in the data file. - If the code is "F" then the code is followed by the ship's name, year, people and car capacity. Use the new operator to create either a Ship, CruiseShip or FerryShip object, storing the pointer to the object in the next element of the array.

6. In your header file for the Ship class, make your displayShip function virtual. Then write a loop to display the data for all of the data read in and stored in the array.

FILE TEXT:

C Fascination 2002 5/11/2013 2056 1750 F Alice Austen 1986 1280 0 S Beagle 1820 C Splendor 2006 5/18/2013 3006 2600 S Bounty 1789 F Molinari 2004 4500 40 C Crown Princess 2006 5/22/2013 3080 3000 C Brilliance of Seas 2002 6/5/2013 2501 2400 F John F. Kennedy 1965 3500 40

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions