Question

In: Computer Science

Design a Ship class that has the following members: • A member variable for the name...

Design a Ship class that has the following members:

• A member variable for the name of the ship (a string)
• A member variable for the year that the ship was built (a string)
• A constructor and appropriate accessors and mutators
• A virtual print function that displays the ship’s name and the year it was built.

Design a CruiseShip class that is derived from the Ship class. The CruiseShip class
should have the following members:

• A member variable for the maximum number of passengers (an int )
• A constructor and appropriate accessors and mutators
• A print function that overrides the print function in the base class. The CruiseShip class’s print function should display only the ship’s name and the maximum number of passengers.

Design a CargoShip class that is derived from the Ship class. The CargoShip class
should have the following members:

• A member variable for the cargo capacity in tonnage (an int ).
• A constructor and appropriate accessors and mutators.
• A print function that overrides the print function in the base class. The CargoShip class’s print function should display only the ship’s name and the ship’s cargo capacity.

After you have created these classes, create a driver program that defines an array pointers to your abstract base class Ship. It should present a menu to allow the user to enter a Cruise Ship or a Cargo Ship. When the user selects cruise ship, it should prompt them for the name, year built, and the number of passengers. When the user selects cargo ship, it should prompt them ffor the name, year built, and the maxium cargo load (in tons). Each selection should create an object that can be stored into your array of pointers. When the program exits, it should display the history of the session which includes each of the objects the user created which will be a combination of cruise ships and cargo ships. An example output is shown here:

Menu

1. Cruise Ship
2. Cargo Ship
3. Quit
Please make your selection: 2

Please enter the name of the ship: Big Bertha
Please enter the year the ship was built: 1975
Please enter the capacity (tons): 50000

Menu

1. Cruise Ship
2. Cargo Ship
3. Quit
Please make your selection: 1

Please enter the name of the ship: Disney Magic
Please enter the year the ship was built: 1998
Please enter the capacity (passengers): 2400

Menu

1. Cruise Ship
2. Cargo Ship
3. Quit
Please make your selection: 3

The history of your session is

Selected Cargo Ship

Name: Big Bertha
Year: 1975
Capacity (tons): 50000

Selected Cruise Ship

Name: Disney Magic
Year: 1998
Capacity (passengers): 2400

Solutions

Expert Solution

Ship.h

#ifndef SHIP_H
#define SHIP_H

//using namespace std;


class Ship
{
    public:
        Ship();
        std::string getName();
        void setName(std::string name);
        std::string getYearBuilt();
        void setYear(std::string yar);
        std::string printNameAndYear();
        ~Ship();
    private:
        std::string name;
        std::string year;
};

#endif // SHIP_H 

Ship.cpp

#include <iostream>
#include "Ship.h"


Ship::Ship()
{
    name = "";
    year = "";
}

std::string Ship::getName() {
    return name;
}

void Ship::setName(std::string nameIn) {
    name = nameIn;
}

std::string Ship::getYearBuilt() {
    return year;
}

void Ship::setYear(std::string yearIn) {
    //std::string yar;
    year = yearIn;
}

std::string Ship::printNameAndYear() {
    return "The " + name + " was built in " + year + "\n";
}

Ship::~Ship()
{
    //dtor
}

Main function:

#include <iostream>
#include "Ship.h"

using namespace std;

int main()
{
    Ship *santaMariaPtr = new Ship;
    santaMariaPtr->setName("Santa Maria");
    santaMariaPtr->setYear("1763");
    cout << santaMariaPtr->printNameAndYear();

    cout << "Press and key and return to exit ";
    char c;
    cin >> c;

    return 0;
}

CruiseShip.h

#ifndef CRUISESHIP_H
#define CRUISESHIP_H
#include "Ship.h"

//using namespace std;


class CruiseShip : public Ship
{
    public:
        CruiseShip();
        ~CruiseShip();
    protected:
    private:
};

#endif // CRUISESHIP_H 

CruiseShip.cpp

#include "CruiseShip.h"
#include<string.h>
CruiseShip::CruiseShip()
{
    //ctor
}

CruiseShip::~CruiseShip()
{
    //dtor
}

Related Solutions

Design a Ship class that the following members: A field for the name of the ship...
Design a Ship class that the following members: A field for the name of the ship (a string). A field for the year that the ship was built (a string). A constructor and appropriate accessors and mutators. A toString method that displays the ship’s name and the year it was built. Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members: A field for the maximum number of passengers (an int). A constructor...
Design a ship class that has the following data fields: A data field for the name...
Design a ship class that has the following data fields: A data field for the name of the ship (a string). A data field for the year that the ship was built (a String). A constructor and appropriate accessors and mutators. A toString method that displays the ship’s name and the year it was built. Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following member: A field for the maximum number of passengers...
1.   Design a class called BankAccount. The member fields of the class are: Account Name, Account...
1.   Design a class called BankAccount. The member fields of the class are: Account Name, Account Number and Account Balance. There are also other variables called MIN_BALANCE=9.99, REWARDS_AMOUNT=1000.00, REWARDS_RATE=0.04. They look like constants, but for now, they are variables of type double Here is the UML for the class:                                                         BankAccount -string accountName // First and Last name of Account holder -int accountNumber // integer -double accountBalance // current balance amount + BankAccount()                     //default constructor that sets name to “”,...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member Functions void withdraw(double amount): function which withdraws an amount from accountBalance void deposit(double...
This question demonstrates the use of inheritance and polymorphism. Design a Ship class that has the...
This question demonstrates the use of inheritance and polymorphism. Design a Ship class that has the following members: • A field for the name of the ship (a string). • A field for the year that the ship was built (a string). • A constructor and appropriate accessors and mutators. • A toString method that overrides the toString method in the Object class. The Ship class toString method should display the ship’s name and the year it was built. Design...
This question demonstrates the use of inheritance and polymorphism. Design a Ship class that has the...
This question demonstrates the use of inheritance and polymorphism. Design a Ship class that has the following members: • A field for the name of the ship (a string). • A field for the year that the ship was built (a string). • A constructor and appropriate accessors and mutators. • A toString method that overrides the toString method in the Object class. The Ship class toString method should display the ship’s name and the year it was built. Design...
Using C++ programming. Thank you. Money class has the following member variables and functions. -member variable...
Using C++ programming. Thank you. Money class has the following member variables and functions. -member variable : dollar, cent -member function : setMoney(int dollar, int cent), printMoney(), operator overloading(+) Program the Money class so that the following function can be performed. int main(){ Money a, b, c; A.setMoney(10, 60); B.setMoney(20, 70; (a+b).printMoney(); c = a + b; c.printMoney(); }
/*Design and code a class Calculator that has the following * tow integer member variables, num1...
/*Design and code a class Calculator that has the following * tow integer member variables, num1 and num2. * - a method to display the sum of the two integers * - a method to display the product * - a method to display the difference * - a method to display the quotient * - a method to display the modulo (num1%num2) * - a method toString() to return num1 and num2 in a string * - Test your...
c++ Design the Weather class that contains the following members: Data members to store: -a day...
c++ Design the Weather class that contains the following members: Data members to store: -a day (an integer) -a month (an integer) -a year (an integer) -a temperature (a float) -a static data member that stores the total of all temperatures (a float) Member functions: -a constructor function that obtains a day, month, year and temperature from the user. This function should also accumulate/calculate the total of all temperatures (i.e., add the newly entered temperature to the total). -a static...
C++ Assignment. Design the Weather class that contains the following members: Data members to store: -...
C++ Assignment. Design the Weather class that contains the following members: Data members to store: - a day (an integer) - a month (an integer) - a year (an integer) - a temperature (a float) - a static data member that stores the total of all temperatures (a float) Member functions: - a constructor function that obtains a day, month, year and temperature from the user. This function should also accumulate/calculate the total of all temperatures (i.e., add the newly...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT