Question: Code in C++: Create a class called WaterVehicle that has the following member variables to represent the ships: length of ship (in number of grid

Code in C++: Create a class called WaterVehicle that has the following member variables to represent the ships:

length of ship (in number of grid spaces)

starting grid location

horizontal or vertical orientation on grid

sunk (Boolean indicating whether the ship has been sunk or not)

You will also need to create a reasonable complement of member functions (constructors, accessor, and mutator functions) to create the ships, to set the location of the ship, get the location of the ship, determine if the ship was hit, and determine if the ship is sunk. Then create a Carrier, a Battleship, a Cruiser, a Submarine, and a Destroyer which are all of type WaterVehicle and have the following lengths: Ship Type Number of Grid Squares Carrier 5 Battleship 4 Cruiser 3 Submarine 3 Destroyer 2 Then write a program which will allow input of the ship length, grid location, and orientation. Assume the grid where the submarine is to be placed is a 10 by 10 grid and is indexed. Randomly generate 15 torpedo shots in the main of the program, output the shot grid locations to the screen, and then output whether the torpedo hit any ship and if it did, whether that ship was sunk. You will need private member variables to keep track of where a ship has been hit to understand if it has been sunk.

Finally overload the << operator to print a WaterVehicle with tabs between fields:

length of ship (in number of grid spaces)

starting grid location

horizontal or vertical orientation on grid

sunk (Boolean indicating whether the ship has been sunk or not)

Demonstrate the use of this operator for each WaterVehicle after the torpedos have been fired.

USE LANGUAGE C++

MAKE Upto maximum 4 files and give user input for where he wants to place the ships

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!