Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please explain Battreship (also Battleships or Sea Battle) is a guessing game for two players. One player set positions of battleships in an array (greyed

Please explain
image text in transcribed
Battreship (also Battleships or Sea Battle) is a guessing game for two players. One player set positions of battleships in an array (greyed squares). Second player is guessing the positions of the ships (crosses in squares). Assume that in C program there are following declarations and definitions: \#include stdio. h \#include string.h \#define 10 \#define Y 10 const char* ship_names[] = { "none", "battleship", "cruiser", "destroyer", "submarine" \}; typedef struct_Field \{ char "ship_name; int hit; \} Field; a) Define function void setEmpty() which takes as a parameter two-dimensional array of Field and sets member fields for each array element. Address stored in variable ship name should be set to address of "none" from ship_names array (HINT: Field ship_name must not need to be dynamically allocatedI). Field hit should be set to . Example usage: Field sea [X][Y] setEmpty(sea); b) Define function const char* hitField() which takes as parameter two dimensional array of Field, row number as integer value and column as a character (see the function call in example). Function should check whether row and column parameters are in range of array size (range 1-10 for rows and ' A ' - J ' for columns, assume only uppercase letters). Function set hit value of selected array element to 1 and return ship_name address value. Example usage: puts (hitfield(sea, 1, 'A'))

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

Nested Relations And Complex Objects In Databases Lncs 361

Authors: Serge Abiteboul ,Patrick C. Fischer ,Hans-Jorg Schek

1st Edition

3540511717, 978-3540511717

More Books

Students also viewed these Databases questions

Question

What are your businesss key cost drivers?

Answered: 1 week ago