Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class called WaterVehicle that has the following member variables to represent the ship: length of ship (in number of grid spaces) starting grid

Create a class called WaterVehicle that has the following member variables to represent the ship:

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

Destroyer 2

Submarine 3

Cruiser 3

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 as described in Assignment 1. 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. (Remember ROCkET programming methodology!)

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

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions

Question

If ( A^2 - A + I = 0 ), then inverse of matrix ( A ) is?

Answered: 1 week ago

Question

What is computer neworking ?

Answered: 1 week ago