Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ battleship program. need the game.cpp. the battleship.h is : #ifndef BATTLESHIP_H_ #define BATTLESHIP_H_ const int FLEET_SIZE=5; const int FIELD_SIZE=5; struct location{ int x; char

c++ battleship program. need the game.cpp.

the battleship.h is :

#ifndef BATTLESHIP_H_ #define BATTLESHIP_H_ const int FLEET_SIZE=5; const int FIELD_SIZE=5; struct location{ int x; char y; }; struct ship{ location loc; bool sunk; }; void initialize(ship[]); location pick(); bool match(ship, location); int check(const ship[], location); void deploy(ship[]); void printShip(ship); void printFleet(const ship[]); bool operational(const ship[]); location fire(); void sink(ship&); #endif

the battleship.cpp is:

#include #include #include #include "battleship.h" using std::cout; using std::cin; using std::endl; bool match(ship myShip, location mySpot){ // returns true if this location matches // the location of the ship // returns false otherwise if (myShip.loc.x == mySpot.x && myShip.loc.y == mySpot.y) return true; else return false; } int check(const ship myFleet[], location mySpot){ // returns the index of element of the array // that matches the location // returns -1 if none do for (int i = 0; i > mySpot.x >> mySpot.y; return mySpot; } void sink(ship& myShip) { myShip.sunk = true; }

image text in transcribedimage text in transcribedimage text in transcribed

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

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

Explain the causes of indiscipline.

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago