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

PROBLEM: Write two structs, and a function get_stats that uses structures and po

ID: 3815889 • Letter: P

Question

PROBLEM: Write two structs, and a function get_stats that uses structures and pointers. Program must follow the provided psuedo code EXACTLY.

(1) You first need to declare a typedef struct jumper_t. Add it to the lab8.h file.

         Name your structure jumper_t and its 4 parts are:

                   a character array name that is 21 in length,

                   a double array ofattempts that is N_ATTEMPTS in length,

                   a double named personal_best,

                   and a double named deviation.

(2) You next need to declare a typedef struct stats_t. Add it to the lab8.h file.

        Name your structure stats_t and its 2 parts are:

                   Two variables, both type double, named: average_of_best, winning_jump.

(3) Write the function get_stats in its own file. The prototype is:

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

                                stats_t *jump_stats);          /* output */

It will figure the best jump for each jumper (the personal_best), compute the all-over average of all the best jumps, find the winning jump, and each jumper’s deviation from the winning jump.

(4) You need to add your name to: lab8.h, open_out_file.c (on the fprintf & change the assignment name to Lab 8), and get_stats.c

You need to add the two structures to lab8.h and write the one function get_stats in its own file.

INPUT/OUTPUT DESCRIPTION:

    The program input is a set of jumper's names and their six attempts at the long jump. The jump lengths are type double. Each record/line of the file has a jumper’s name and six attempts. The file consists of the four names, followed by the first six attempts, and then each successive set of attempts.

     The program output:

            First type: make        (which will look for your file named makefile)

            Then type: jumps      (or whatever other name you used to replace a.out)

            The output will go to a file name lab8_out.txt. The name is in a #define in lab8.h.

            So type: cat lab8_out.txt           to see your output.

ALGORITHM DEVELOPMENT - 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 */

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

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

/* 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

}

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

EXAMPLE:

This is a sample example. It does not match the provided data file in length or in value! This sample data is in the file named lab8sample.dat.

Here are the files referred to in the assignment. They are not really needed as long you follow the psuedocode laid out.

https://www.dropbox.com/sh/o66es2dzc5bz5yl/AAArIxc9go6CM9-bf4LizboMa?dl=0

SAMPLE OUTPUT (usin lab8sample.dat): [bielreathena lab8 cat lab8 out.txt Name, Lab 8 output Your Track Results Try 1 Try 2 Try 3 Try 4 Try 5 Try 6 Personal Best Deviation Nanne 5.00 Moe Johnson 1.00 5.00 2.00 00 0.00 3.00 1.00 6.00 0.00 2.000 6.00 2.00 4.00 6.00 2.00 Lad Loop 5.00 3.00 2.00 2.00 5.00 5.00 0.00 1.00 Monroe Miner 4.00 Jay Jacob 4.00 2.00 0.00 3.00 4.00 1.00 2.00 Best Jump Average 5.00 meters Winning Jump 6.00 meters [bielreathena lab8

Explanation / Answer

CODE:

get_stats.c

/*-----------------------------------------------------------*/
/*It will figure the best jump for each jumper (the personal_best), */
/*compute the all-over average of all the best jumps, */
/*find the winning jump, and each jumper’s deviation from the winning jump.*/

#include "lab8.h"

void get_stats( jumper_t jump_list[NCOMPETITORS], /* in & out */
stats_t *jump_stats ) /* in & out */
{
jump_stats->average_of_best = 0;
jump_stats->winning_jump = 0;
for(int r = 0; r < NCOMPETITORS; r++)
{
jump_list[r].personal_best = jump_list[r].ofattempts[0];
for(int c = 1; c < N_ATTEMPTS; c++)
{
if(jump_list[r].personal_best < jump_list[r].ofattempts[c])
{
jump_list[r].personal_best = jump_list[r].ofattempts[c];
}
}
jump_stats->average_of_best += jump_list[r].personal_best;
for(int c = 0; c < N_ATTEMPTS; c++)
{
if(jump_stats->winning_jump < jump_list[r].ofattempts[c])
{
jump_stats->winning_jump = jump_list[r].ofattempts[c];
}
}
}
  
jump_stats->average_of_best = jump_stats->average_of_best / NCOMPETITORS;
  
for(int r = 0; r < NCOMPETITORS; r++)
{
jump_list[r].deviation = jump_stats->winning_jump - jump_list[r].personal_best;
}
}

struct definitions in lab8.h

typedef struct
{
char name[21];
double ofattempts[N_ATTEMPTS];
double personal_best;
double deviation;
}jumper_t;

typedef struct
{
double average_of_best;
double winning_jump;
}stats_t;

NOTE: THERE ARE TWO ERRORS IN THE FILES YOU PROVIDED.

print_all.c: line 25: replace "attempts" to "ofattempts"

get_data.c: line 41: replace "attempts" to "ofattempts"

Cheers!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote