Question
Please use comment headers to specify what each section of code does. The programming language is C.

Obiectives 1. To learn how to write functions given specifications 2. To learn how to the use pass by value and pass by reference variables 3. Review previous concepts like if-statements and loops. Movies about dragons and dragon training were very popular this summer. Your fiend has not stopped talking about how awesome dragons are and how cool it would be to train them. To amuse your friend you have decided to create a dragon-training simulator using your C programming skills. The basic idea behind the simulation is as follows: 1) You will simulate 10 days of dragon training 2) In the beginning the user gets a new dragon with some initial statistics for strength, intellect, and agility 3) At the beginning of each day the user receive a weather report. 4) Based on that, the user can determine which tasks their dragon should complete that day 5) Then, the days activity is simulated After 10 days the simulation ends and the user is told whether or not they have completed training Training may be completed earlier than 10 days if the obstacle course is completed A skeleton of the solution for this assignment is posted on the webcourse. You must fill in the seven functions that are currently empty. After you write each function, you should test it before moving on. The main function should not be modified for the final submission (you may modify it during testing, as long as you return it to its initial form) Descriptions of each function are given in the skeleton along with the function Pre- and Post-conditions. The output samples at the end of this document show the wording you should use and how the program should run when completed. Points are allotted for following the precise wording shown

Skeleton code:
media%2F663%2F6634f796-6bc5-4dac-8776-d7

media%2F42d%2F42d1039d-da12-4c21-b532-cb

media%2Fd98%2Fd98d95a2-0707-43b3-a1a3-d1

media%2Fd87%2Fd87112eb-e492-490a-9f02-e5

media%2F28c%2F28c3cfcd-a5a5-42f0-82c7-f3

Sample output:

media%2Fb86%2Fb8612135-c202-4834-9abd-78

media%2Fe1a%2Fe1ac846b-aa53-4d35-83bc-8a

media%2Fd9d%2Fd9dab50a-4789-4d95-93fc-28
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//copy the code and run it
//comments are provided within the code

//Note: if have any problem in understanding then feel free to
//comment in the comment section

// Fill in your own header comment

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

// Constants to be used.
// Passing score

#define SCORE 70

// Symbolic constants for true and false.

#define FALSE 0

#define TRUE 1

// Function prototypes - do not change these
void set_stats(int * d_strength, int * d_intel, int * d_agil);
void print_stats(int strength, int intelligence, int agility, char name[]);
int menu();
int weather();
int train_strength(int weather, char name[]);
int train_intelligence(int weather, char name[]);
int train_agility(int weather, char name[]);
int obstacle_course(int weather, int strength, int intel, int agility);
void end_message(int completed, char name[]);

// Main function
int main() {
int num_day, ans, weather_value, score = 0, completed = FALSE;
int dragon_strength, dragon_intelligence, dragon_agility;

char name[20], answer[4];

srand(time(0));
printf("Welcome to Dragon Training!\n");
printf("You've been assigned a new dragon! Would you like to give it a name? (yes/no)\n");
scanf("%s", answer);

if(strcmp(answer, "yes") == 0) {
    printf("Great! What would like to call your dragon?\n");
    scanf("%s", name);
}
else
strcpy(name, "your dragon");

printf("\nTo complete training, %s must finish the final \nobstacle course with a score of 70 or better.\n", name);

printf("\nYou may attempt the obstacle course at any time, \nbut you must finish within 10 days.\n");

printf("\nBetter get started!\n");

set_stats(&dragon_strength, &dragon_intelligence, &dragon_agility);
for (num_day = 1; num_day <= 10; num_day++) {
    printf("\nIt is Day #%d.\n", num_day);
    print_stats(dragon_strength, dragon_intelligence, dragon_agility,name);
    weather_value = weather();
    ans = menu();

    switch(ans) {

          case 1:dragon_strength += train_strength(weather_value, name);
          break;

          case 2:dragon_intelligence += train_intelligence(weather_value,name);
          break;

          case 3:dragon_agility += train_agility(weather_value, name);
          break;

          case 4:score = obstacle_course(weather_value, dragon_strength,dragon_intelligence, dragon_agility);
          printf("%s scored a %d on their obstacle course run!\n",
          name, score);
          break;
        }

    if(score >= SCORE) {
      completed = TRUE;
      break;
    }
}

end_message(completed, name);
return 0;
}

// Pre-conditions: d_strength, d_intel, and d_agil are pointers to variables that store
//the dragon's strength, intelligence, and agility statistics.
// Post-condition: Each of the dragon's statistics are set to a pseudorandom
//initial value.
//What to do in this function: Set each of the dragon's values to a
//pseudorandom initial value.
//Strength should be a random value from 0-99. Then add 5 to make sure the
// dragon has at least 5 strength.
// Intellect should be a random value from 1-10.
// Agility should be a random value from 0-19. Then add 2 to make sure the
// dragon has at least 2 agility.

void set_stats(int * d_strength, int * d_intel, int * d_agil) {
*d_strength =(int)(rand()%100 + 5);
*d_intel = (int)(rand()%10+1);
*d_agil = (int)(rand()%20+2);
}

// Pre-conditions: There are no parameters for this function.
// Post-condition: The user is presented with a menu and given
// the opportunity to respond. If they respond with
// a valid menu option, return the user's choice.
// What to do in this function: Prompt the user with the menu and
// read in their response. If their answer is less than 1 or greater
// than 4, continue to prompt them until they provide a valid answer.
// Then, return their answer.

int menu() {
int ch;
do{
    //ch will store the choice
printf("What would you like to do today?\n");
printf("1-Train strength\n");
printf("2-Train knowkedge\n");
printf("3-Train agility\n");
printf("4-Attempt the obstacle_course\n");
scanf("%d",&ch);
}while(ch<1 || ch>4);
return ch;
}

// Pre-condition: None
// Post-condition: The weather report for the day is printed and the
// corresponding weather status in between 1 and 5,
// inclusive, is returned.

int weather() {
// Get the weather status value.
int retval = rand()%5 + 1;
printf("\nHere is today's weather forecast:\n");
// Print out the appropriate forecast for that status.\n");
if (retval == 1)
printf("It is cloudy with a high chance of rain.\n");
else if (retval == 2)
printf("It is partly cloudy and windy.\n");
else if (retval == 3)
printf("It is partly sunny with low humidity.\n");
else if (retval == 4)
printf("It is warm and sunny with medium winds.\n");
else
printf("It's a perfect beach day. Sunny and hot!\n");
printf("\n");
return retval; // Return this status value.
}

// Pre-condition: strength, intelligence, agility, and name are variables
//that represent the name of the dragon and it's stats
// Post-condition: A listing of the dragon's stats are printed
// What to do with this function: This is fairly self-explanatory from the
// pre and post conditions. Look to the sample given in the assignment for
// the format.

void print_stats(int strength, int intelligence, int agility, char name[])
{
printf("Here are %s current stats:\n",name );
printf("\tStrength:%d\n",strength );
printf("\tIntelligence:%d\n",intelligence);
printf("\tAgility:%d\n",agility);
}

// Pre-condition: weather is an integer from 1-5 that represents the
// current day's forecast. name is the dragon's name.
// Post-condition: A day's strength taining is carried out. The current
// gain in strength is printed and returned.
// What to do with this function: First, determine the maximum possible
// gain in strength by mutliplying the weather by 3 and adding 5.
// If the maximum possible gain is less than 10, set it to 10.
// Then, determine the actual gain by generation a psuedorandom
// number between 1 and the maximum gain.
// Print the amount of strength gained according to the sample run,
// and return that value

int train_strength(int weather, char name[]) {
//max strength gain using above function
int max_strength_gain = (weather*3)+5;

if(max_strength_gain<10)max_strength_gain=10;

int actual_gain = rand()%max_strength_gain+1;
printf("After training hard, %s gained %d strength!\n",name,actual_gain );
return actual_gain;
}

// Pre-condition: weather is an integer from 1-5 that represents the
// current day's forecast. name is the dragon's name.
// Post-condition: A day's knowkedge taining is carried out. The current
// gain in knwoledge is printed and returned.
// What to do with this function: First, determine the maximum possible
// gain in knowledge by dividing 15 by the weather and adding 5.
// If the maximum possible gain is less than 10, set it to 10.
// Then, determine the actual gain by generation a psuedorandom
// number between 1 and the maximum gain.
// Print the amount of intellect gained according to the sample run,
// and return that value

int train_intelligence(int weather, char name[]) {
//max knowledge gain using above function
int max_knowledge_gain = (15/weather) + 5;

if(max_knowledge_gain<10)max_knowledge_gain=10;

int actual_gain = rand()%max_knowledge_gain+1;
printf("After hitting the books, %s gained %d intellect!\n",name,actual_gain );
return actual_gain;
}

// Pre-condition: weather is an integer from 1-5 that represents the
// current day's forecast. name is the dragon's name.
// Post-condition: A day's agility taining is carried out. The current
// gain in agility is printed and returned.
//
// What to do with this function: First, determine the maximum possible
// gain in agility using the following function: 13 + weather%5 +(weather+4)%5
// Then, determine the actual gain by generation a psuedorandom
// number between 1 and the maximum gain.
// Print the amount of agility gained according to the sample run,
// and return that value
int train_agility(int weather, char name[]) {
//max agility using above function
int max_agility_gain = 13 + weather%5 +(weather+4)%5;
int actual_gain = rand()%max_agility_gain+1;
printf("After running sprints, %s gained %d agility!\n",name,actual_gain );
return actual_gain;
}

// Pre-condition: weather is an integer from 1-5 that represents the
// current day's forecast. strength, intel, and agility
// are variables representing the dragon's stats
// Post-condition: A day's obstacle course is run and a score for the
// run is returned.

int obstacle_course(int weather, int strength, int intel, int agility){
return 10 + 2*weather + strength/4 + intel + agility/2;
}

// Pre-condition: completed is an integer that represents either TRUE or FALSE
//                name is the dragon's name.
// Post-condition: The user's overall result is printed out.
// What to do with this function: See if the dragon completed the obstacle
// course. Print the appropriate response according to the sample run.
void end_message(int completed, char name[]) {
if(completed==1){
    printf("Congratulations! %s completed their training!\n",name );
    }else
    printf("Sorry %s your training is not completed!\n",name );
}

code image is:

··· ~/Chegg/ans.c . . Sublime Text (UNREGISTERED) -E t L (45%) 11:28 AM 268 copy the cade and run it 261 conments are provid

0 /Chegg/ans.c.-Sublime Text (UNREGISTERED) E L (45%) 11:28 AM 305 scants, answer 306 307 it(strenp[answer, yes printf(Cr

0 /Chegg/ans.c.-Sublime Text (UNREGISTERED) -E t L (45%) 11:29 AM 353 354 Pre-conditions: d strength,d intel, and d agil are

0 /Chegg/ans.c.-Sublime Text (UNREGISTERED) nDtD(44%) 11:29 Ar t 39B 399 inclusive, 1s returned 40 iotr weather) 481 / Get th

0 /Chegg/ans.c.-Sublime Text (UNREGISTERED) nDtD(44%) 11:29 Ar t 446 lor train strength(int weather, char nanel l) t 447 //na0 /Chegg/ans.c.-Sublime Text (UNREGISTERED) nDtD(44%) 11:29 Ar t 485 What to do with this function: First, determine the maxi

output of sample1:

skyhawk-14@skyhawk14-X54Zuq:-/Chegg skyhawk 14@skyhawk14-x542uq:-/Cheggs a.out Helcone to Dragon Training! Youve been assign

skyhawk-14@skyhawk14-X54Zuq:-/Chegg E D(46%) 11:25AM .t 3-Train agility 4-Attenpt the obstacle_course After hitting the books

output sample2:

●●● skyhawk-14@skyhawk14-X54Zuq:-/Chegg skyhawk 14@skyhawk14-x542uq:-/Cheggs a.out Helcone to Dragon Training! Youve been as

skyhawk-14@skyhawk14-X54Zuq:-/Chegg 11:38 AM Here is todays weather forecast: It is partly cloudy and windy What would you l

skyhawk-14@skyhawk14-XS4Zuq:-/Chegg D(41%) 11:39 AM It is partly cloudy and windy what would you like to do today? 1-Train st

skyhawk-14@skyhawk14-X54Zuq:-/Chegg D(41%) + 11:39 AM 3-Train agility 4-Attenpt the obstacle_course Toothful scored a 48 on

Add a comment
Know the answer?
Add Answer to:
Please use comment headers to specify what each section of code does. The programming language is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and...

    Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and please add comments for the whole code. Include a class diagrams, and explain the approach you used for the project and how you implemented that, briefly in a few sentences. Please note the following: -Names chosen for classes, functions, and variables should effectively convey the purpose and meaning of the named entity. - Code duplication should be avoided by factoring out common code into...

  • Introduction to C Programming – COP 3223 1. To learn how to use arrays to store...

    Introduction to C Programming – COP 3223 1. To learn how to use arrays to store and retrieve data to help solving problems. 2. Reinforce use of input files. Introduction: Ninja Academy Ninjas are awesome! Your friend has not stopped talking about how cool ninjas and how they would like to become a ninja. To amuse your friend, you have decided to create a series of programs about ninjas. Problem: Mentorship (ninjamentors.c) It is time for your friend to select...

  • Please use C programming to write the code to solve the following problem. Also, please use the i...

    Please use C programming to write the code to solve the following problem. Also, please use the instructions, functions, syntax and any other required part of the problem. Thanks in advance. Use these functions below especially: void inputStringFromUser(char *prompt, char *s, int arraySize); void songNameDuplicate(char *songName); void songNameFound(char *songName); void songNameNotFound(char *songName); void songNameDeleted(char *songName); void artistFound(char *artist); void artistNotFound(char *artist); void printMusicLibraryEmpty(void); void printMusicLibraryTitle(void); const int MAX_LENGTH = 1024; You will write a program that maintains information about your...

  • In C++, Please help me compute the following flowchart exactly like this requirement: Use while loops...

    In C++, Please help me compute the following flowchart exactly like this requirement: Use while loops for the input validations required: number of employees(cannot be less than 1) and number of days any employee missed(cannot be a negative number, 0 is valid.) Each function needs a separate flowchart. The function charts are not connected to main with flowlines. main will have the usual start and end symbols. The other three functions should indicate the parameters, if any, in start; and...

  • programming language is C++. Please also provide an explanation of how to create a file with...

    programming language is C++. Please also provide an explanation of how to create a file with the given information and how to use that file in the program Let's consider a file with the following student information: John Smith 99.0 Sarah Johnson 85.0 Jim Robinson 70.0 Mary Anderson 100.0 Michael Jackson 92.0 Each line in the file contains the first name, last name, and test score of a student. Write a program that prompts the user for the file name...

  • PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end...

    PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end please include a main function that tests the functions that will go into a separate driver file. Prototypes int R_get_int (void); int R_pow void R Jarvis int start); void R_fill_array(int arrayll, int len); void R_prt_array (int arrayl, int len) void R-copy-back (int from[], int to [], int len); int R_count_num (int num, int arrayll, int len) (int base, int ex) 3. Build and run...

  • PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will...

    PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will guide you in starting the program in a methodical way. The program will display a window with GUI widgets that are associated with particular functions: Employee Payroll O X -- - - - - - - - - - - Show Payroll Find Employee by Name Highest Lowest Find Employee by Amount Write Output to Fie Cancel - -------- ------------- Notice that some of...

  • Using C programming language Question 1 a) through m) Exercise #1: Write a C program that...

    Using C programming language Question 1 a) through m) Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. a. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. b....

  • C programming language Purpose The purpose of this assignment is to help you to practice working...

    C programming language Purpose The purpose of this assignment is to help you to practice working with functions, arrays, and design simple algorithms Learning Outcomes ● Develop skills with multidimensional arrays ● Learn how to traverse multidimensional arrays ● Passing arrays to functions ● Develop algorithm design skills (e.g. recursion) Problem Overview Problem Overview Tic-Tac-Toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the...

  • C++ Programming Programming Project Outcomes:  Understand and use C++ functions for procedural abstraction and Functional...

    C++ Programming Programming Project Outcomes:  Understand and use C++ functions for procedural abstraction and Functional Decomposition  Develop some functions for generating numerical data from numerical inputs  Understand and utilize file input and file output to perform computing tasks Requirements: 1. You should do a functional decomposition to identify the functions that you will use in the program. These should include reading and writing the files, tallying and showing statistics, etc. 2. The program should prompt the user...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT