Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i need help with this program, I am stuck at it /* My typedef structures from a

ID: 3824599 • Letter: I

Question

i need help with this program, I am stuck at it

/* My typedef structures from a different file */

Typedef struct {

                             Char name[21];

                             Double attempts[N_ATTEMPTS];

                             Double personal_best;

                             Double deviation;

                             }jumper_t;

Typedef struct {

                             Double average_of_best;

                             Double winning_jump;

                             }stats_t;

Pseudocode

/*-------------------------------------------------------------*/

main   

out_file = open_out_file ();                     

get_data(IN_FILENAME, jump_list);                

get_stats(jump_list, &jump_stats);             

print_all(out_file, jump_list, &jump_stats);  

/*-------------------------------------------------------------*/

FILE * open_out_file(void)         /* It already exists */

/*-------------------------------------------------------------*/

void get_data (char *filename,                                /* input */              

jumper_t jump_list[NCOMPETITORS] ); /* output */

     /*It already exists */

/*-------------------------------------------------------------*/

/*     The print_all SUB-FUNCTION is provided for you          */

void print_all(FILE * out_file, jumper_t jump_list[NCOMPETITORS] , stats_t *jump_stats )

     /* It already exists */

/*-------------------------------------------------------------*/

CSC 60. Spring 2017. Lab 8 arrays & structures.  

Page 3 of 5.

/*--------------------------------------------------------------------------------*/

/*     THIS IS A SUB-FUNCTION THAT YOU HAVE TO WRITE         */

void get_stats( jumper_t jump_list[NCOMPETITORS],     /* in & out */     

    stats_t *jump_stats )                                  /* in & out */         

                      {   

Zero out the average_of_best. (HINT: use the -> notation)    

Zero out the winning_jump.      

Loop from r=zero to r< NCOMPETITORS increment by one   

{        

set the jumper's personal_best to the jumper's first jump        

loop from c=one to c< N_ATTEMPTS increment by one         

{             

figure the jumper’s personal_best jump(use an IF)      

   }         

add the jumper's personal _best jump into the running total average_of_best         

loop from c=zero to c< N_ATTEMPTS increment by one         

{             

figure the winning_jump (use an IF)        

}    

}         /* end of the loop, r< NCOMPETITORS */    

compute the average of the best jumps

    loop from r=zero to < NCOMPETITORS increment by one   

{          

figure the jumper's deviation from the winning_jump             

(deviation is: winning_jump - jumper's personal_best jump)   

}  

return

} /*-------------------------------------------------------------*/

Explanation / Answer

/* My typedef structures from a different file */
Typedef struct {
Char name[21];
Double attempts[N_ATTEMPTS];
Double personal_best;
Double deviation;
}jumper_t;
Typedef struct {
Double average_of_best;
Double winning_jump;
}stats_t;


Pseudocode

/*-------------------------------------------------------------*/
main   
out_file = open_out_file ();   
get_data(IN_FILENAME, jump_list);
get_stats(jump_list, &jump_stats);   
print_all(out_file, jump_list, &jump_stats);

/*-------------------------------------------------------------*/
FILE * open_out_file(void) /* It already exists */

/*-------------------------------------------------------------*/
void get_data (char *filename, /* input */
jumper_t jump_list[NCOMPETITORS] ); /* output */

/*It already exists */

/*-------------------------------------------------------------*/
/* The print_all SUB-FUNCTION is provided for you */
void print_all(FILE * out_file, jumper_t jump_list[NCOMPETITORS] , stats_t *jump_stats )

/* It already exists */

/*-------------------------------------------------------------*/



CSC 60. Spring 2017. Lab 8 arrays & structures.
Page 3 of 5.


/*--------------------------------------------------------------------------------*/
/* THIS IS A SUB-FUNCTION THAT YOU HAVE TO WRITE */
void get_stats( jumper_t jump_list[NCOMPETITORS], /* in & out */   
stats_t *jump_stats ) /* in & out */   
{   
//Zero out the average_of_best. (HINT: use the -> notation)
jump_stats->average_of_best = 0;
//Zero out the winning_jump.
jump_stats->winning_jump = 0;

//Loop from r=zero to r< NCOMPETITORS increment by one   
for(int r = 0; r < NCOMPETITORS; r++)
{
    // set the jumper's personal_best to the jumper's first jump
    jump_list[r].personal_best = jump_list[r].attempts[0];
    // loop from c=one to c< N_ATTEMPTS increment by one   
    for(int c = 1; c < N_ATTEMPTS; c++)
    {   
       //figure the jumper’s personal_best jump(use an IF)
       if(jump_list[r].attempts[c] > jump_list[r].personal_best)
           jump_list[r].personal_best = jump_list[r].attempts[c];
    }
    //add the jumper's personal _best jump into the running total average_of_best   
    jump_stats->average_of_best += jump_list[r].personal_best;
    // loop from c=zero to c< N_ATTEMPTS increment by one   
    for(int c = 0; c < N_ATTEMPTS; c++)
    {   
       //figure the winning_jump (use an IF)
       if( jump_list[r].attempts[c] > jump_stats->winning_jump)
           jump_stats->winning_jump = jump_list[r].attempts[c];
    }
} /* end of the loop, r< NCOMPETITORS */
//compute the average of the best jumps
jump_stats->average_of_best /= NCOMPETITORS;
//loop from r=zero to < NCOMPETITORS increment by one   
for(int r = 0; r < NCOMPETITORS; r++)
{
    //figure the jumper's deviation from the winning_jump   
    //(deviation is: winning_jump - jumper's personal_best jump)   
    jump_list[r].deviation = jump_stats->winning_jump - jump_list[r].personal_best;
}
return
} /*-------------------------------------------------------------*/