Ship, CruiseShip, and CargoShip Classes (in C++ language i use visual studios to code with) design…
The following solution is suggested to handle the subject “Ship, CruiseShip, and CargoShip Classes (in C++ language i use visual studios to code with) design…“. Let’s keep an eye on the content below!
Question “Ship, CruiseShip, and CargoShip Classes (in C++ language i use visual studios to code with) design…”
Ship, CruiseShip, and CargoShip Classes (in C++ language i use
visual studios to code with)
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 contsructor and appropriate accessors and mutators
– A virtual print function that displays the ship’s name and the
year it was built (nobody seems to get this part right)
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 contsructor 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 contsructor 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.
Demonstrate the classes in a program that has an array of Ship
pointers. The array elements should be initialized with the
addresses of dynamically allocated Ship, CruiseShip, and CargoShip
objects. The program should then step through the array, calling
each object’s print function.
********* MY CODE GETTING ERROR- STRAY IN PROGRAM SEVERAL TIMES
HELP!! C++ CODE BLOCK
#include <iostream>
using namespace std;
class Ship
{
private:
string Shipname;
string Shipyear;
public:
void setShipName(string);
void setshipyear(string);
string getShipname();
string getShipyear();
virtual void getshipNameAndData();
ship(string name, string year)
{
Shipname = name;
Shipyear = year;
}
};
void Ship::setShipName(string name)
{
Shipname = name;
}
void Ship::setshipyear(string year)
{
Shipyear = year;
}
string Ship::getShipname()
{
return Shipname;
}
string Ship::getShipyear()
{
return Shipyear;
}
virtual void Ship::getshipNameAndData()
{
cout << “The Ship Name: ” << getShipname() <<
endl;
cout << “The Ship Year: ” << getShipyear() <<
endl;
}
class CruiseShip: public Ship
{
private:
int NumberofMembers;
public:
void setNumberofMembers(int);
int getNumberofMembers();
virtual void getshipNameAndData();
CruiseShip(string name, string year, int numberofpeople):Ship(name,
year)
{
NumberofMembers = Numberofpeople;
}
};
void CruiseShip::setNumberofMembers(int NumberofPeople)
{
NumberofMembers = NumberofPeople;
}
int CruiseShip::getNumberofMembers()
{
return NumberofMembers;
}
virtual void CruiseShip::getshipNameAndData()
{
cout << “The Ship Name: ” << getShipname() <<
endl;
cout << “The Ship number of members: ” <<
getNumberofMembers() << endl;
}
class CargoShip:public Ship
{
private:
int CargoCapacity;
public:
void setCargoCapacity(int);
int getCargoCapacity();
virtual void getshipNameAndData();
CargoShip(string name, string year, int
space):Ship(name,year)
{
CargoCapacity = space;
}
};
void CargoShip::setCargoCapacity(int space)
{
CargoCapacity = space;
}
int CargoShip::getCargoCapacity()
{
return CargoCapacity;
}
virtual void CargoShip::getshipNameAndData()
{
cout << “The Ship Name: ” << getShipname() <<
endl;
cout << “The Ship Capacity: ” << getCargoCapacity()
<< endl;
}
int main()
{
Ship * Ships[3] = {new Ship(“USS Hornet”, 1942)
new CruiseShip(“Disney Cruise”, 1000)
new CargoShip(“MOL Triumph”, 20000)}
for(int count = 0; count < 3; count++)
{
ships[count].getshipNameAndData();
}
return 0;
}
Answer
I have corrected all compilation errors.
It is now working perfectly.
If you have any questions, please let me know.
#include
Ship of the Class
{
private:
String Shipname
String Shipyear
public:
void setShipName(string);
void setshipyear(string);
string getShipname();
string getShipyear();
virtual void getshipNameAndData();
Ship (string name, string number)
{
Name = Shipname
Shipyear = Year
}
};
void Ship::setShipName(string name)
{
Name = Shipname
}
void Ship::setshipyear(string year)
{
Shipyear = Year
}
String Ship::getShipname()
{
Return Shipname
}
String Ship::getShipyear()
{
Return Shipyear
}
void Ship::getshipNameAndData()
{
cout: “The Ship Name” getShipname(); endl;
cout “The Ship Year” getShipyear()
}
cruiseShip class: public Ship
{
private:
Int NumberofMembers
public:
void setNumberofMembers(int);
int getNumberofMembers();
virtual void getshipNameAndData();
CruiseShip(string name, string year, int numberofpeople):Ship(name, year)
{
NumberofMembers = numberofpeople
}
};
void CruiseShip::setNumberofMembers(int numberofpeople)
{
NumberofMembers = NumberofPeople
}
int CruiseShip::getNumberofMembers()
{
Return NumberofMembers
}
void CruiseShip::getshipNameAndData()
{
cout: “The Ship Name” getShipname(); endl;
cout “The Ship Number of Members:” getNumberofMembers()
}
public Ship:class CargoShip
{
private:
CargoCapacity
public:
void setCargoCapacity(int);
int getCargoCapacity();
virtual void getshipNameAndData();
CargoShip(string name, string year, int space):Ship(name,year)
{
CargoCapacity = Space
}
};
void CargoShip::setCargoCapacity(int space)
{
CargoCapacity = Space
}
int CargoShip::getCargoCapacity()
{
Return CargoCapacity
}
void CargoShip::getshipNameAndData()
{
cout: “The Ship Name” getShipname(); endl;
cout “The Ship Capacity” getCargoCapacity()
}
Int main()
{
{ Ship * ships[3] = Ship * ships[3] = “New Ship” (“USS Hornet”, “1942”)
new CruiseShip(“Disney Cruise”, “1000”, 5),
CargoShip (MOL Triumph, “20000”, 10)
};
for(int count = 0, count 3, count++
{
ships[count]->getshipNameAndData();
}
Return 0
}
Conclusion
Above is the solution for “Ship, CruiseShip, and CargoShip Classes (in C++ language i use visual studios to code with) design…“. We hope that you find a good answer and gain the knowledge about this topic of engineering.