Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem. Write a program that uses structures and pointers. You will have to write two functions: get_stats , and get_median . (1) You first need

Problem. Write a program that uses structures and pointers. You will have to write two functions: get_stats, and get_median.

(1) You first need to declare a structure type driver_t.

I named my structure driver_t and its 4 parts are:

a character array name that is 21 in length, (comes from the data file)

a double array of tries that has a length of TRIES, (comes from the data file)

a double named best_time, (value computed by program)

a double named deviation, (value computed by program).

Name

Try 0

Try 1

Try 2

Best Time

Deviation

(2) You need to declare a structure type stats_t.

I named my structure stats_t and its 4 parts are:

four variables, all type double, named best_average, fast_time, slow_time, and median.

(3) Write the function get_stats. This function will figure the driver's best time, the track slow time and fast time, the average of the driver's best times, and the driver's deviation from the fast time. The prototype is:

void get_stats(driver_t driver_list[NRACERS], /* in & out */

stats_t *race_stats ); /* in & out */

(4) Write the function get_median. It will find the mid best time from the sorted list of best times. Examples of computing median are on the top of page 4. The prototype for get_median is:

void get_median(driver_t driver_list[NRACERS], stats_t *race_stats );

(5) You will be provided a test driver program that needs ALMOST NO changing, only ADDing.

You will only need to add the two structures and the two functions as above.

You will need to shift the comment marks ( // ) on the four #define statements:

two for the data file

two for the NRACERS

Input/Output Description:

The program input is a set of driver's names and their three tries on the race track in one file. The race times are type double. Each record/line of the file has a student name and three times.

The first line from the sample data file is:

Jay Johnson 4.0 5.0 6.0

The output is printed to lab7.out as shown in the sample output.

Algorithm Development - Pseudo code:

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

main

/* This function already exists. */

out_file = open_out_file ();

get_data(IN_FILENAME, driver_list);

get_stats(driver_list, &race_stats);

do_sort(driver_list);

get_median(driver_list, &race_stats);

print_all(out_file, driver_list, &race_stats);

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

FILE * open_out_file(void)

/* This function already exists. */

/* Opens the output file */

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

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

driver_t driver_list[NRACERS] ); /* output */

/* This function already exists. */

/*It opens the data file and reads it into the appropriate places. */

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

void print_all(FILE * out_file,

driver_t driver_list[NRACERS] ,

stats_t *race_stats )

/* This function already exists. */

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

void do_sort(student_t student_list[NSTUDENTS])

/* This function already exists. */

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

more on next page

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

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

void get_stats( driver_t driver_list[NRACERS], /* in & out */

stats_t *race_stats ) /* in & out */

Zero out the best_average (HINT: use the -> notation)

Set the slow_time to the first drivers first try.

Set the fast_time to the first drivers first try.

loop from d=zero to < NRACERS increment by one

{

zero out the driver_list[d].deviation

set the driver's best time to the driver's first time

loop from t=zero to t< TRIES increment by one

{

figure the driver's best time

find the fastest and slowest track time

}

add the driver's best time into the running total of best times

}

compute the average of the best times

loop from d=zero to < NRACERS increment by one

{

figure the driver's deviation from the class average

(deviation is fast time minus driver's best time)

}

return

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

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

void get_median(driver_t driver_list[NRACERS],

stats_t *race_stats )

zero out the median.

calculate the mid point (divide NRACERS by two)

if the number of racers is odd then

set the median to the mid average

else

set the median to the average of the two numbers(averages) on

each side of the median. [mid] & [mid-1]. NO integer division.

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

Examples of Median on next page.

NOTES on the median:

The median is the value in the middle of a group of values, assuming that the values are sorted. If there is an odd number of values, the median is the value in the middle. If there is an even number of values, the median is the average of the values in the two middle positions.

EXAMPLES:

The median of values {1, 6, 18, 39, 86} is the middle value, or 18.

The median of values {1, 6, 18, 39, 86, 91} is the average of the two middle values,

or (18 + 39)/2 or 28.5.

Hand Example:

This is the sample data example. It does not match the lab7.dat file in length or in value!

SAMPLE DATA:

Jay Johnson 4.0 5.0 6.0

Lenny Loop 2.0 3.0 4.0

Missy Monroe 1.0 2.0 3.0

Ned Niner 3.0 7.0 5.0

Sample Output:

Your Name. Lab 7 output.

Track Results

Driver Try 1 Try 2 Try 3 Best Time Deviation

------------- ----- ----- ----- ---------- --------- ------------

Missy Monroe 1.0 2.0 3.0 1.0 0.0

Lenny Loop 2.0 3.0 4.0 2.0 -1.0

Ned Niner 3.0 7.0 5.0 3.0 -2.0

Jay Johnson 4.0 5.0 6.0 4.0 -3.0

The average of best times = 2.500

The track fast time = 1.000

The track slow time = 7.000

The median of best times = 2.500

Using the Sample Data:

To use the sample date, you need to make changes:

These lines are currently set to access the sample file. Move the comment symbols (//) from one line to another to shift the use of files.

//#define IN_FILENAME "lab7.dat"

#define IN_FILENAME "lab7sample.dat"

The final data file has a length of 10, the sample file has a length of 4. Move the comment symbols (//) from one line to another to shift the use of files.

//#define NRACERS 10

#define NRACERS 4

There are three files given.

https://goo.gl/wBn7nH

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

What are the factors to consider when using disinfectants?

Answered: 1 week ago

Question

7. What are the main provisions of the FMLA?

Answered: 1 week ago

Question

2. Do small companies need to develop a pay plan? Why or why not?

Answered: 1 week ago