Maincpp battleShiph In moodlecscoloradoedu 0 Recitation Acti

Main.cpp
battleShip.h
In moodle.cs.colorado.edu 0 Recitation Activity For today\'s recitation activity you are going to create a class called battleShip. First create the Codeblocks project. Name your project Recitation7.cpp. Now create the class file based on the instructions earlier in the recitation and name the class battleShip. When you create your class, you can set up your constructor and destructor at this time and it will populate these methods for you when it creates your class. The battle Ship.h file has been made available on Moodle. Cut and paste the code from that file into the class you just created. 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 n 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.

Solution

Hi friend you have not given details about implementtion of methods:

void recordHit();
       bool isSunk();

So, I have given dummy implementation

Please replace this implementaion with your actual.

##########   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();
   }


   return 0;
}

Main.cpp battleShip.h In moodle.cs.colorado.edu 0 Recitation Activity For today\'s recitation activity you are going to create a class called battleShip. First
Main.cpp battleShip.h In moodle.cs.colorado.edu 0 Recitation Activity For today\'s recitation activity you are going to create a class called battleShip. First

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site