Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

int randomInt(int); int main() { srand(time(NULL)); return 0; } /* Function: randomInt Purpose: returns a random number in the range [0,max) Parameters: in: maximum of

image text in transcribedimage text in transcribedimage text in transcribed

int randomInt(int); int main() { srand(time(NULL)); return 0; } /* Function: randomInt Purpose: returns a random number in the range [0,max) Parameters: in: maximum of range return: randomly generated number */ int randomInt(int max) { return(rand() % max); } 

Goal Timmy Tortoise and Harold the Hare have been charged with rescuing a baby Dragon being kept captive in an underground bunker by a band of pirates. In order to compute their chances of a successful rescue, Timmy Tortoise wants to use a program to simulate the battles between our heroes and those pirates. Using the VM provided for the course, you will implement a C program that simulates Timmy and Harold fighting each pirate one at a time. The program will execute 100 runs of this simulation, it will determine the winner each time, and it will collect statistics on survival rates. The winner of each simulation will be the survivor(s), either one of the heroes, or both heroes, or the pirates if both heroes are dead Learning Outcomes You will practice problem solving and designing modular functions to implement a solution. You will work with structures in C, as well as pointers and dynamically allocated memory Instructions 1. Data structures Your program will define the following data types as structures: the HeroType structure will contain a hero's name (as a string), as well as indicators of his strength, his armour, and his health, all represented as integers .the PirateType structure will contain a pirate's strength and health indicators .the ArrayType structure will be a collection structure which contains a primitive (regular) array of PirateType pointers; the ArrayType will also need to store the current number of pirates in the array Your program will initialize one HeroType structure for Timmy, and another one for Harold, as follows: .Timmy's strength is set at 5, his armour at 5, and his health indicator begins at 30 points Harold's strength is set at 7, his armour at 3, and his health indicator begins at 30 points For each run of the simulation, a different ArrayType structure will be initialized to hold the pirates: .the array structure will be filled with 10 dynamically allocated PirateType structures each pirate will have a strength as a randomly generated number between 3 and 6 (inclusively) each pirate will have a health indicator that begins at 20 points .each pirate will be pushed to the back (the end) of the ArrayType structure Goal Timmy Tortoise and Harold the Hare have been charged with rescuing a baby Dragon being kept captive in an underground bunker by a band of pirates. In order to compute their chances of a successful rescue, Timmy Tortoise wants to use a program to simulate the battles between our heroes and those pirates. Using the VM provided for the course, you will implement a C program that simulates Timmy and Harold fighting each pirate one at a time. The program will execute 100 runs of this simulation, it will determine the winner each time, and it will collect statistics on survival rates. The winner of each simulation will be the survivor(s), either one of the heroes, or both heroes, or the pirates if both heroes are dead Learning Outcomes You will practice problem solving and designing modular functions to implement a solution. You will work with structures in C, as well as pointers and dynamically allocated memory Instructions 1. Data structures Your program will define the following data types as structures: the HeroType structure will contain a hero's name (as a string), as well as indicators of his strength, his armour, and his health, all represented as integers .the PirateType structure will contain a pirate's strength and health indicators .the ArrayType structure will be a collection structure which contains a primitive (regular) array of PirateType pointers; the ArrayType will also need to store the current number of pirates in the array Your program will initialize one HeroType structure for Timmy, and another one for Harold, as follows: .Timmy's strength is set at 5, his armour at 5, and his health indicator begins at 30 points Harold's strength is set at 7, his armour at 3, and his health indicator begins at 30 points For each run of the simulation, a different ArrayType structure will be initialized to hold the pirates: .the array structure will be filled with 10 dynamically allocated PirateType structures each pirate will have a strength as a randomly generated number between 3 and 6 (inclusively) each pirate will have a health indicator that begins at 20 points .each pirate will be pushed to the back (the end) of the ArrayType structure

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

Students also viewed these Databases questions