C Class help Cut and paste the code from battleshiph below i
C++ Class help
Cut and paste the code from battleship.h below into a battleship class in a new .cpp file You will then create your class file with a number of methods. (Remember: methods define what your object does). How many methods do you see in your header file? It will be your job to fill in these methods so that they work. In battleShip.cpp you will define the methods.The constructor always has the same name as your class file, and it never has a data type. Make sure to import the proper class file and libraries in the header of your battleShip.cpp file. You will also be given the main.cpp. Cut and paste the code from that file into the class you just created. Make sure to include the appropriate headers. See the main.cpp for further instructions. You will need to create 3 instances of your class, set up some of the methods, and expand on the logic of the while loop.
Will give thumbs up for comiling code and a good explanation of said code.
main:
battleship.h:
Solution
Hi, friend can you plaese tell me : what these two methods does (details):
I have given dummy implementation because from question i am not getting details about these methods.
########## battleShip.h ################
#ifndef BATTLESHIP_H
#define BATTLESHIP_H
#include <iostream>
using namespace std;
class battleShip{
public:
battleShip(string);
~battleShip();
void setShipName(string);
string getShipName();
void setSize(int);
int getSize();
void recordHit();
bool isSunk();
private:
string name;
int size;
int hits;
};
#endif
############## battleShip.cpp ####################
#include <iostream>
#include \"battleShip.h\"
using namespace std;
battleShip::battleShip(string n){
name = n;
}
battleShip::~battleShip(){
}
void battleShip::setShipName(string n){
name = n;
}
string battleShip::getShipName(){
return name;
}
void battleShip::setSize(int s){
size = s;
}
int battleShip::getSize(){
return size;
}
void battleShip::recordHit(){
hits = hits + 1;
}
bool battleShip::isSunk(){
// there is no hits/details in question about this implementation
return false; // dummy
}
################ main.cpp ##################
#include <iostream>
#include \"battleShip.h\"
using namespace std;
int main(){
// declaring three vaariables
battleShip Destroyer(\"Destroyer-0\");
battleShip Carrier(\"Carrier-0\");
battleShip Cruiser(\"Cruiser-0\");
// setting the ship size
Destroyer.setSize(3);
Carrier.setSize(10);
Cruiser.setSize(2);
while(Destroyer.isSunk() == false){
Destroyer.recordHit();
}
while(Carrier.isSunk() == false){
Carrier.recordHit();
}
while(Cruiser.isSunk() == false){
Cruiser.recordHit();
}
return 0;
}
THis code will compile but since I have given dummy implementation of two methods you will get output nothing.
Pleae give details about these two methods i will add it


