Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Battleship game The game is played on a board consisting of 100 cells arranged a

ID: 3567595 • Letter: B

Question

Battleship game
The game is played on a board consisting of 100 cells arranged as a 10x10 square. Ten ships are
placed on the board. There are four kinds of ships. Each ship occupies a number of cells that
depends on the size of the ship. The ship types are
1) Aircraft carrier, size=5
2) Battleship, size=4
3) Cruiser, size=3
4) Destroyer, size=2


A ship occupies contiguous cells arranged as a rectangle of width=1 and height=size, or
width=size and height=1, i.e. the orientation of the rectangle can be horizontal or vertical. Ships
cannot overlap and cannot touch each other (either sideways or diagonally).

Assignment

The goal is to implement classes representing ships. These classes will be later used to implement the full battleship board game.

The class Ship is an abstract base class from which four classes are derived:

AircraftCarrier, BattleShip, Cruiser and Destroyer. A detailed specification of
the class Ship is given below. You are given the header file Ship.h. Your task is to write the
implementation file Ship.cpp containing the implementation of all classes. You are not
allowed to modify the file Ship.h (Do not insert your SID in it since we will use the cmp
command to check that the file is the same as the original). Your class implementation file
Ship.cpp should compile without warning using the command
$ g++ -Wall

Explanation / Answer

/* #include #include #include #include #include using namespace std; const int GRIDSIZE = 10; enum direction {EXPAND_ROW, EXPAND_COL}; // Function Prototypes int GetPlayers(); void SetComputerBoats(char [GRIDSIZE][GRIDSIZE]); void PrintBoard(char [GRIDSIZE][GRIDSIZE]); string GetRank(int); int PlaySingleMode(char [GRIDSIZE][GRIDSIZE]); void SetParticularBoat(char [GRIDSIZE][GRIDSIZE], int, char); void main() { //Just For Fun!> system("color 02"); int numOfPlayers, moves=99; //char player1Boats[GRIDSIZE][GRIDSIZE]; char player2Boats[GRIDSIZE][GRIDSIZE]; // Print Title, seed RNG and get # of players cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote