Question: getInput.c #include #define MAX_LINE 80 // functions from statistics.c, prototype is in statistic.h #include statistics.h /* --- * getIntegerLine() * returns a positive integer from

getInput.c
#include
#define MAX_LINE 80
// functions from statistics.c, prototype is in statistic.h #include "statistics.h"
/* --- * getIntegerLine() * returns a positive integer from a line of input * * Assumption: assumes proper input. */ int getIntegerLine() { char line[MAX_LINE]; int return_user_int=-1;
fgets( line, sizeof( line ), stdin ); while( sscanf( line, "%d", &return_user_int ) != 1 ) { // Not a positive integer - indicates end of input return -1; } return return_user_int; }
/* --- * prompts user for input. */ void promptList() { printf( " Assumes proper input " ); printf( " Type a list of non-negative integers, below, one integer per line " ); printf( " Indicate the END of input with any letter (a-z): -> " ); }
void driver() { int anumber=-1;
promptList();
while( (anumber = getIntegerLine()) >= 0 ) {
printf( "Entered ---> %d -> ", anumber );
printf( "Running Average ---> %4.2lf -> ", running_average( anumber ) ); }
printf( "End of input " );
}
runProgram.c:
extern void driver();
int main() { driver(); }
Statistics.c
double running_average( int add_number ) { static double total_numbers = 0; static double total_sum = 0; total_sum = total_sum + (double) add_number; total_numbers += 1; return total_sum / total_numbers; }
Statistics.h
// only include declaration once, by defining prepprocessor 'dummy variable' #ifndef STATISTICS_H #define STATISTICS_H
extern double running_average( int add_number ); extern double sum_func(int add_num); extern double avg_func(int add_num); extern double sum_square_func(int add_num); extern double variance_func(int add_num); extern double minimum(int add_num); extern double maximum(int add_num);
#endif
Modify the output stream of the program runProgram and add functions to compute statistics in the file statistics.c. Currently the program reads in a stream of integers from standard input. It assumes that there is 1 integer per line. The program starts reading when it encounters a non-positive number or character. You will need to add below statistics to statistics.c (and edit add prototypes to statistics.h), so that each statistics is computed in a separate function, also you will need to refine the output (in the function drivers() in the file getInput.c), so it looks exactly as depicted below" Input file (read from standard Input) 1 3 XXX Outputs exactly line up the ":"): Sum: 10.00 Average: 2.50 Sum of Squares : 30.0 Sample Variance: 1.25 Minimum: 1 Maximum: 4 Before you implement - runprogram prints out the correct Average of 2.50 as a running average, but not in the proper output format. Below is the output of the program before starting. The content of input04.txt is listed by the cat command below: {csci-odiningrid:86} cat input04.txt 4 1 3 XXX {csci-odin: ingrid:84} runprogram Entered ---> 2 -> Running Average ---> 2.00 -> Entered ---> 4 -> Running Average ---> 3.00 -> Entered ---> 1 -> Running Average ---> 2.33 -> Entered ---> 3 -> Running Average ---> 2.50 -> End of input Only getInput.c and statistics.c and statistics.h need to modified. In getInput.c you only modify the function driver. Modify the output stream of the program runProgram and add functions to compute statistics in the file statistics.c. Currently the program reads in a stream of integers from standard input. It assumes that there is 1 integer per line. The program starts reading when it encounters a non-positive number or character. You will need to add below statistics to statistics.c (and edit add prototypes to statistics.h), so that each statistics is computed in a separate function, also you will need to refine the output (in the function drivers() in the file getInput.c), so it looks exactly as depicted below" Input file (read from standard Input) 1 3 XXX Outputs exactly line up the ":"): Sum: 10.00 Average: 2.50 Sum of Squares : 30.0 Sample Variance: 1.25 Minimum: 1 Maximum: 4 Before you implement - runprogram prints out the correct Average of 2.50 as a running average, but not in the proper output format. Below is the output of the program before starting. The content of input04.txt is listed by the cat command below: {csci-odiningrid:86} cat input04.txt 4 1 3 XXX {csci-odin: ingrid:84} runprogram Entered ---> 2 -> Running Average ---> 2.00 -> Entered ---> 4 -> Running Average ---> 3.00 -> Entered ---> 1 -> Running Average ---> 2.33 -> Entered ---> 3 -> Running Average ---> 2.50 -> End of input Only getInput.c and statistics.c and statistics.h need to modified. In getInput.c you only modify the function driver
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
