Computer science Help C language ONLY FOR EliteExperts

profileamjad55
3main.c

#include "stdafx.h" #include "PA3Header.h" int main(void) { FILE * input = NULL; FILE * output = NULL; int id1 = 0, id2 = 0, id3 = 0, id4 = 0, id5 = 0, class1 = 0, class2 = 0, class3 = 0, class4 = 0, class5 = 0; double gpa1 = 0.0, gpa2 = 0.0, gpa3 = 0.0, gpa4 = 0.0, gpa5 = 0.0, age1 = 0.0, age2 = 0.0, age3 = 0.0, age4 = 0.0, age5 = 0.0, sum_gpa = 0.0, sum_class, sum_age, mean_gpa = 0.0, mean_class = 0.0, mean_age = 0.0, deviation1_gpa = 0.0, deviation2_gpa = 0.0, deviation3_gpa = 0.0, deviation4_gpa = 0.0, deviation5_gpa = 0.0, variance_gpa = 0.0, standard_deviation_gpa = 0.0, max_gpa = 0.0, min_gpa = 0.0; input = fopen("input.dat", "r"); output = fopen("output.dat", "w"); //These generic ones can handle reading id and gpa all; need to make sure to make 5 of these id1 = read_integer(input); fprintf(output, "\n%d", id1); //we also need to show that we can print double precision values to our output, so we are outputing gpa1 gpa1 = read_double(input); fprintf(output, "\n%.2lf", gpa1); // in other functions class1 = read_integer(input); age1 = read_double(input); id2 = read_integer(input); gpa2 = read_double(input); class2 = read_integer(input); age2 = read_double(input); id3 = read_integer(input); gpa3 = read_double(input); class3 = read_integer(input); age3 = read_double(input); id4 = read_integer(input); gpa4 = read_double(input); class4 = read_integer(input); age4 = read_double(input); id5 = read_integer(input); gpa5 = read_double(input); class5 = read_integer(input); age5 = read_double(input); //Part 1- Calculating Sums // calculating the sum of the gpa to our <output.dat> file sum_gpa = calculate_sum(gpa1, gpa2, gpa3, gpa4, gpa5); fprintf(output, "\n\n\n%.2lf", sum_gpa); //calculating the sum of class standings and printing it off to our <output.dat> file sum_class = calculate_sum(class1, class2, class3, class4, class5); fprintf(output, "\n%.2lf", sum_class); // calculating the sum of ages and printing it off to our <output.dat> file sum_age = calculate_sum(age1, age2, age3, age4, age5); fprintf(output, "\n%.2lf", sum_age); //Part 2- Finding Means of different values // we passed in the original sum of the GPA's and are dividing it by 5 mean_gpa = calculate_mean(sum_gpa, 5); fprintf(output, "\n\n\n %.2lf", mean_gpa); // we passed in the original sum of the class and are dividing it by 5 mean_class = calculate_mean(sum_class, 5); fprintf(output, "\n%.2lf", mean_class); // we passed in the original sum of the age's and are dividing it by 5 mean_age = calculate_mean(sum_age, 5); fprintf(output, "\n%.2lf", mean_age); //Part 3- Finding the deviation. deviation1_gpa = calculate_deviation(gpa1, mean_gpa); fprintf(output, "\n\n\n%.2lf", deviation1_gpa); // calculating the deviation of gpa 2 from the mean of GPA's deviation2_gpa = calculate_deviation(gpa2, mean_gpa); fprintf(output, "\n%.2lf", deviation2_gpa); // calculating the deviation of gpa 3 from the mean of GPA's deviation3_gpa = calculate_deviation(gpa3, mean_gpa); fprintf(output, "\n%.2lf", deviation3_gpa); // calculating the deviation of gpa 4 from the mean of GPA's deviation4_gpa = calculate_deviation(gpa4, mean_gpa); fprintf(output, "\n%.2lf", deviation4_gpa); // calculating the deviation of gpa 5 from the mean of GPA's deviation5_gpa = calculate_deviation(gpa5, mean_gpa); fprintf(output, "\n%.2lf", deviation5_gpa); //calculating the variance of all the GPA's by squaring them all and dividing by the number of GPA's variance_gpa = calculate_variance(deviation1_gpa, deviation2_gpa, deviation3_gpa, deviation4_gpa, deviation5_gpa, 5); fprintf(output, "\n%.2lf", variance_gpa); // calculating the standard deviation of the GPA's by taking the square root of the variance. We included the <math.h> function in our header standard_deviation_gpa = calculate_standard_deviation(variance_gpa); fprintf(output, "\n%.2lf", standard_deviation_gpa); //Part 4- the minimum and maximum GPA's from the solution set // the maximum gpa with this function max_gpa = find_max(gpa1, gpa2, gpa3, gpa4, gpa5); fprintf(output, "\n\n\n%.2lf", max_gpa); //we are finding the minimum gpa with this function min_gpa = find_min(gpa1, gpa2, gpa3, gpa4, gpa5); fprintf(output, "\n%.2lf", min_gpa); fclose(input); fclose(output); return 0; }