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

Battleship (C++) Using battleship.cpp you can run the program as it is, and it s

ID: 3694927 • Letter: B

Question

Battleship (C++)

Using battleship.cpp you can run the program as it is, and it should play the game Battleship for just one ship (the length 3 submarine) on a 10x10 board. For testing purposes, it is probably easiest to read from file (so you do not need to guess where the ships are).

The pieces and lengths of pieces for Battleship are: Aircraft carrier = length 5, Battleship = length 4, Submarine = length 3, Cruiser = length 3, Destroyer = length 2.

Currently, we always assume the ship is a submarine (length 3). Modify the code to make all five types of pieces possible. Your piece should always be a battleship (length 4). If the computer generates a random position, it should place a battleship as well. If the computer reads from the file, it should place different pieces based on the first char/string: 'D' for “Destroyer”, 'C' for “Cruiser”, 'S' for “Submarine”, 'B' for “Battleship”, 'A' for “Aircraft carrier”.

The sample file oneShip.txt should place an Aircraft carrier (length 5, denoted with 'A's) in the top left going down, while the fiveShips.txt will put a submarine (length 3, denoted with 'S's) in the top left going down.

battleship.cpp:

oneShip.txt:

fiveShips.txt:

Explanation / Answer

battleship.cpp:

oneShip.txt:

fiveShips.txt:

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