Battleship Lab Using Classes

I have no idea what I'm doing when it comes to classes. I coded this lab using structures but classes has me stumped. If anyone can help, I can post my battleship program using structures if that would help you, but here is the header file I have been given to code using classes. Any help is greatly appreciated!


// coordinates (location) of the ship and shots
class location{
location(void); // void constructor, assigns -1 to X
void pick(void); // picks a random location
void fire(void); // asks the user to input the
// coordinates of the next shot
void print(void) const; // prints location in format "a1"

// returns true if the two locations match
friend bool compare(location, location);

static const int fieldSize=5; // the field (ocean) is fieldSize X fieldSize
int x; // 1 through fieldSize
char y; // 'a' through fieldSize

// contains ship's coordinates (location) and whether is was sunk
class ship{
ship(void); // void constructor, sets sunk=false
bool match(location) const; // returns true if this location matches
// the ship's location
bool isSunk(void) const {return(sunk);}; // checks to see if the ship is sunk
void sink(void); // sets "sunk" member variable of the ship to true
void setLocation(location); // deploys the ship at the specified location
void printShip(void) const; // prints location and status of the ship

location loc;
bool sunk;

// contains the fleet of the deployed ships
class fleet{
void deployFleet(void); // deploys the ships in random locations
// of the ocean
bool operational(void) const; // returns true if at least
// one ship in the fleet is not sunk
bool isHitNSink(location); // returns true if there was a deployed
// ship at this location (hit) and sinks it
// otherwise returns false (miss)
void printFleet(void) const; // prints out locations of ships in fleet

static const int fleetSize=5; // number of battleships
int check(location); // returns index of the element of array ships
// that matches location, returns -1 if
// none match
ship ships[fleetSize]; // battleships of the fleet

#endif /* BATTLESHIP_H_ */
Topic archived. No new replies allowed.