I am writing a battleship program that uses classes. I don't entirely understand classes, so there are a few errors, but I do not know what to do. I'm not exactly sure how to use different variables and functions from different classes, either. Help fixing program would be greatly appreciated.
#ifndef BATTLESHIP_H_
#define BATTLESHIP_H_
// coordinates (location) of the ship and shots
class location{
public:
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
friendbool compare(location, location);
private:
staticconstint 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{
public:
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
private:
location loc;
bool sunk;
};
// contains the fleet of the deployed ships
class fleet{
public:
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
private:
staticconstint fleetSize=5; // number of battleships
bool check(location); // returns true if one of the ship's locations
// matches the ship, returns false
// if none-match
ship ships[fleetSize]; // battleships of the fleet
};
#endif /* BATTLESHIP_H_ */