Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following struct and procedure are defined. const int SIZE = 5 ; typedef struct awesome _ data _ struct { int data [ SIZE

The following struct and procedure are defined.
const int SIZE =5;
typedef struct awesome_data_struct {
int data [SIZE];
char type;
} awesome_data
void
who_am_i ( const awesome_data &str1, awesome_data &str2)
{
int i;
for ( i =0; i < SIZE; i++){
str2.data [i]= str1.data [SIZE -i -1];
}
str2. type = str1. type ;
return ;
}
Q1. Hand execute the code below using this procedure.
// Initialise d1. data with {7,9,-11,3,2} and d1. type with 'x '.
// Initialise d2. data with {4,-5,8,3,7} and d2. type with 'y '.
awesome_data d1={{7,9,-11,3,2},'x'};
awesome_data d2={{4,-5,8,3,7},'y'};
who_am_i ( d1, d2);
Q2. Hand execute the code below using this procedure.
// Initialise d1. data with {-2,5,6,7,-1} and d1. type with 'r '.
// Initialise d2. data with {3,7,9,-2,5} and d2. type with 'z '.
awesome_data d1={{-2,5,6,7,-1},'R'};
awesome_data d2={{3,7,9,-2,5},'z
'};
who_am_i ( d2, d1);
Q3. Give a single short sentence to describe what the function who_am_i is doing, and provide
a more appropriate name for it
You are designing a game and you need to implement a data structure to capture the notion of a player.
This data structure should contain the following:
-The x and y position of the player
- their name
- a player identification number;
- an array of length 5. resenting power levels of the player
Q4. Write a data structure named player to encode the information specified for an player.
Q5. Implement the procedure below, which copies the power levles of the player in the second parameter to the interger array in the first parameter.
void copy_powers ( int power_levels [], player & pl )
Q6. Using your player sruct from Q4, create MAX_PLAYERS number of players on the first dotted line. On the second dotted line, for the 31-st player, set the 2-nd value of their power level to be 4
Dene MAX_ENEMIES number of enemies using the data structure you've implemented
( void ) dull_and_duller (void)
{
const int MAX_ENEMIES =200;
---------------------------------------------------
---------------------------------------------------

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

JDBC Database Programming With J2ee

Authors: Art Taylor

1st Edition

0130453234, 978-0130453235

More Books

Students also viewed these Databases questions