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

please use C++ prefer if you use print instead of cout << Ill. Overview & Requir

ID: 3888987 • Letter: P

Question

please use C++
prefer if you use print instead of cout <<





Ill. Overview & Requirements: Write a beodglim that unctionss numbers, coecords read i from a file, and wites the requlired results to an output file (Gee main ()I. Your program shoud double (FILE 'infile) -Reads one double precision number from the input file. Note: You may assume that the file only contains real numbers. (5 pts) int read integer (FILE 'infile) - Reads one integer number from the input file. (double number1, double number2, double number3, double numberd, double number5) Finds the sum of number1, number2, number3, numberd, and number5 and returns the result. 5 pts) double calculate-mean (double sum, int number)- number is not 0. If it is 0 the function returns 1.0 (we (5 pts) double calculate_deviation (double number number mear Determines the mean through the calculation sum / number and returns the result. You need to check to make sure tha r, double mean) - Determines the deviation of number from the mean and returns the result. The deviation may be calculated as le deviation1, double deviationz, double deviation3, double deviation4, double deviation5, int number) Determines the variance through e will assume that we are calculating the mean of positive numbers), otherwise it returns the mean. are calculating the (10 pts) double calculate variance (double de tation 3 double the calculation: (deviation1)*2 + (deviationz)'2 (deviation3)2 (deviation4)"2 + (deviation5)*2) / number and returns the result. Hint: you may call your calculate mean ( ) function to determine the resultl function that is found in math.h. (5 pts) double calculate-standard-deviation (double variance) . Calculates the standard deviation a (10 pts) double find-max (double number 1, double numbers, (10 pts) double find_min (double number1, double number (5 pts) void print_double (FILE"outfile, double number) Pr (20 pts) A main ( ) function that does the following (this is what the program does!) sqrt (variance) and returns the result. Recall that you may use the sqrt ) le number2, double number3, double number4, double numbers) - Determines the maximum number out of the five input 2, double number3, double number4, double number5) - Determines the minimum number out of the five input parameters passed into the function, returning the max. parameters passed into the function, returning the min. ints a double precision number (to the hundredths place) to an output file Opens an input file "input.dat" for reading; Opens an output file "output.dat" for writing;

Explanation / Answer

main.cpp:

#include <stdio.h>

#include <math.h>

#include <fstream>

double read_double(FILE *infile) {

double d;

fscanf(infile,"%lf",&d);

printf("%f ", d);

return d;

}

int read_integer(FILE *infile) {

int d;

fscanf(infile,"%d",&d);

printf("%d ", d);

return d;

}

double calculate_sum(double n1, double n2, double n3, double n4, double n5) {

return n1 + n2 + n3 + n4 + n5;

}

double calculate_mean(double sum, int n) {

if(n==0) {

return -1;

}

return sum/n;

}

double calculate_deviation(double number, int mean) {

return number - mean;

}

double calculate_variance(double n1, double n2, double n3, double n4, double n5, int n) {

return (n1*n1 + n2*n2 + n3*n3 + n4*n4 + n5*n5)/n;

}

double calculate_standard_deviation(double variance) {

return sqrt(variance);

}

double max(double a, double b) {

if(a > b) {

return a;

} else {

return b;

}

}

double min(double a, double b) {

if(a < b) {

return a;

} else {

return b;

}

}

double find_max(double n1, double n2, double n3, double n4, double n5) {

return max(n1, max(n2, max(n3, max(n4, n5))));

}

double find_min(double n1, double n2, double n3, double n4, double n5) {

return min(n1, min(n2, min(n3, min(n4, n5))));

}

void print_double(FILE *outfile, double number) {

fprintf(outfile, "%.2f ", number);

}

int main(int argc, char **argv)

{

FILE *input = fopen("../input.dat", "r");

FILE *output = fopen("../output.dat", "w");

if(input == NULL || output == NULL) {

printf("Error! Unable to open file. ");

return 1;

}

double gpa1, gpa2, gpa3, gpa4, gpa5;

int st1, st2, st3, st4, st5;

double age1, age2, age3, age4, age5;

read_integer(input);

gpa1 = read_double(input);

st1 = read_integer(input);

age1 = read_double(input);

read_integer(input);

gpa2 = read_double(input);

st2 = read_integer(input);

age2 = read_double(input);

read_integer(input);

gpa3 = read_double(input);

st3 = read_integer(input);

age3 = read_double(input);

read_integer(input);

gpa4 = read_double(input);

st4 = read_integer(input);

age4 = read_double(input);

read_integer(input);

gpa5 = read_double(input);

st5 = read_integer(input);

age5 = read_double(input);

double sumGPA = calculate_sum(gpa1, gpa2, gpa3, gpa4, gpa5);

double gpaMean = calculate_mean(sumGPA, 5);

double standingMean = calculate_mean(calculate_sum(st1, st2, st3, st4, st5), 5);

double ageMean = calculate_mean(calculate_sum(age1, age2, age3, age4, age5), 5);

double gpaStDev = calculate_standard_deviation(calculate_variance(gpa1, gpa2, gpa3, gpa4, gpa5, 5));

double gpaMin = find_min(gpa1, gpa2, gpa3, gpa4, gpa5);

double gpaMax = find_max(gpa1, gpa2, gpa3, gpa4, gpa5);

print_double(output, gpaMean);

print_double(output, standingMean);

print_double(output, ageMean);

print_double(output, gpaStDev);

print_double(output, gpaMin);

print_double(output, gpaMax);

return 0;

}


input.dat:

12345678
3.78
2
8.5

12345678
1.78
2
20.5

12345678
6.78
4
7.5

12345678
6.28
1
12.5

12345678
1.78
5
10.5


output.dat:
4.08
2.80
11.90
4.61
1.78
6.78