This is in C++ Now we\'ll write another class battleShip. If you\'re not familia
ID: 3730661 • Letter: T
Question
This is in C++
Now we'll write another class battleShip. If you're not familiar with the game, it might helpful to go read up on it before doing this question. https://en.wikipedia.org/wiki/Battleship_(game) class battleShipt public: battleShip(string): battleShip); void setShipName(string): string getShipName); void setSize(int); int getSize); void recordHit; bool isSunk; // returns true if hits is greater than equal to size / Increments the hits data member private: string name; int size; int hits; d: For this question, we've provided a complete class definition in the coderunner box. Write the function definitions for all 8 member functions of the battleShip class. The constructor battleShip(string) takes the ship name and should set all the data members of the ship to the correct value. The default size of a ship should be -1. What should hits be set to for a new ship? The function recordHit() should print" has been hit times." For example, if a ship named "Carrier" with size 5 had 4 hits, I would expect the output "Carrier has been hit 4 times." The function isSunk0 should print " has been sunk." For example, if a ship named "Destroyer" has sunk, I would expect the output Destroyer has been sunk"Explanation / Answer
battleShip::battleShip(string s) {
name = s;
}
battleShip::~battleShip() {
cout<<"Destroper has been sunk"<<endl;
}
void battleShip::setShipName(string n) {
name = n;
}
string battleShip::getShipName() {
return name;
}
void battleShip::setSize(int n){
size = n;
}
int battleShip::getSize() {
return size;
}
void battleShip::recordHit() {
hits++;
cout<<name<<" has been hit "<<hits<<" times"<<endl;
}
bool battleShip::isSunk() {
cout<<name<<" has been sunk"<<endl;
return hits >= size;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.