Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this project, your program is to read an input file that contains information on the placement of 4 boats into a 10x10 character array.

For this project, your program is to read an input file that contains information on the placement of 4 boats into a 10x10 character array. Each boat consists of three locations that must be hit (three elements of an array), and each boat is placed vertically or horizontally only. After placing the boats on the game board, the user is prompted for a row and column number to see if it is a hit on one of the 4 boats or a miss. Play continues until the user sinks all 4 boats. After sinking the last boat, the percentage of shots that were hits is displayed followed by the final game board. Run the sample solution using the first input file to see how the program runs. For the game board, use a 10x10 character array. This array is to be initialized to all periods (.). After initializing the array, open an input file and use the contents of the file to place the boats into the array. The input file contains 2 integer values and then a character on each line. The first integer is the row index value, the second integer is the column index value. The character is the boat number (1,2,3 or 4). Note: the third value on the line is an integer representing the boat number; however, it should be read into a character variable. The boat number read is then placed into the array at the row and column index specified. After the entire input file has been read and all the boats placed, the user is prompted for a guess on which row and column to fire at. If a boat is present at the spot selected, then the phrase ......Hit!!! is printed out followed by the board with an H present in the spot hit. If a boat is not present at the spot selected, then the phrase ......Miss!!! is printed out followed by the board with an X present in the spot selected. Each boat has three parts in three positions. After all three parts of a boat have been hit, the message to the screen indicates the third hit and the phrase You sank boat #X where X will be 1, 2, 3 or 4. After all 4 boats have been sunk; the congratulation message and statistic message on the percentage of shots that were hits are printed followed by the game board. Requirement: You should have following six user-defined functions. PrintBoard function code will be given to you. 1) InitialBoard: initialize board to all .s. 2) OpenConfigFile: Continuous prompt the user to enter the configuration input file name and open that file until it is successful. There are two exception scenarios you should deal with: empty file and bad file names. 3) PlaceBoats: places the boats into the board spaces when reading the input file. 4) BeginGame: get boats positions that user guesses to fire at. 5) CheckGame: If the guessing is correct, the spot is set to H, else X. If all three parts (three positions) of one boat has been hit, print out the boat has been sunk. Once 12 hits have been recorded, all boats have been sunk and the game is over. You should print out Congratulations!; the successful hit percentage as well as the final board.

I was given the following:

Board code

image text in transcribed

I was given the following notepad file for the user input/user guess:

image text in transcribed

I was given the following notepad file for placing ship:

image text in transcribed

PrintBoardCode.cpp openconfigfile.cpp Project 1.cpp printboard.cpp* 1 2 void printboard() cout Current Board Status = '1 88 board [row] [col]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions