Question
(C++) Vectors store a linear arrangement of values, accessed by a single index. Using vectors, write a program to play a modified battleship game -
(C++) Vectors store a linear arrangement of values, accessed by a single index. Using vectors, write a program to play a modified battleship game - a guessing game where the location and number of ships are concealed to the user and the goal of the game is for the user to hit as many ships as possible by selecting the location of the shots . Define a vector of 10 elements where the location of the ships will be stored and changed if they get hit. Select at most 3 random locations to put each ship (denoted as ) but do not show these locations unless there is a hit in the ship or until the end of the game. Display 10 empty spaces (denoted as ) in a row. Then, give the user 3 opportunities to select the location of the shots, and display whether they hit a ship (denoted as ) or do not (denoted as ) . At the end of the game, display the location of all the ships and the percentage of ships that were destroyed. Figure 1 shows a sample outcome of the game.
Note that the user would input the element number, not the index of the vector. Clear your screen every time you print to the console so that you only have one row of symbols at a time.v
Shot 1 Location: 3 -Shot 2 Location: 4 .Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started