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...
/*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...
I. Design and code a class Rectangle that has the following properties: Two private members double...
I. Design and code a class Rectangle that has the following properties: Two private members double length and width A constructor that accepts two parameters for the private members Default constructor that sets both members to 0 Setters/getters for each private member Method area() that returns the area of the rectangle Method Perim() that returns the perimeter of the rectangle Method toString that return the param as a String Method Add that accepts a Rectangle and returns a rectangle with...
Write a class called Person that has two private data members - the person's name and...
Write a class called Person that has two private data members - the person's name and age. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Write a separate function (not part of the Person class) called std_dev that takes as a parameter a list of Person objects and returns the standard deviation of all their ages (the population standard deviation that uses a denominator...
write the code in python Design a class named PersonData with the following member variables: lastName...
write the code in python Design a class named PersonData with the following member variables: lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData , which is derived from the PersonData class. The CustomerData class should have the following member variables: customerNumber mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool ....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT