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. Grading Rubric Follow best practices in programming with declarations in .h files and implementations in .cpp files. Creat a makefile (not makefile.txt!)
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