Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A main ( ) function that does the following (this is what the program does!!!): Opens an input file input.dat for reading; Opens an output

A main ( ) function that does the following (this is what the program does!!!):

Opens an input file "input.dat" for reading;

Opens an output file "output.dat" for writing;

Reads five records from the input file (input.dat); You will need to use a combination of read_double ( ) and read_integer ( ) function calls here!

Calculates the sum of the GPAs;

Calculates the sum of the class standings;

Calculates the sum of the ages;

Calculates the mean of the GPAs, writing the result to the output file (output.dat);

Calculates the mean of the class standings, writing the result to the output file (output.dat);

Calculates the mean of the ages, writing the result to the output file (output.dat);

Calculates the deviation of each GPA from the mean (Hint: need to call calculate_deviation ( ) 5 times)

Calculates the variance of the GPAs

Calculates the standard deviation of the GPAs, writing the result to the output file (output.dat);

Determines the min of the GPAs, writing the result to the output file (output.dat);

Determines the max of the GPAs, writing the result to the output file (output.dat);

Closes the input and output files (i.e. input.dat and output.dat)

Expected Input File Format (real numbers only):

For this assignment you will be required to read five records from the "input.dat" file. Each record will have the following form:

Student ID# (an 8 digit integer number)

GPA (a floating-point value to the hundredths place)

Class Standing (1 - 4, where 1 is a freshmen, 2 is a sophomore, 3 is a junior, and 4 is a senior --> all integers)

Age (a floating-point value)

Example data for 1 student record in the file could be as follows:

12345678

3.78

3

20.5

This is what I have so far with my functions and header file:

// HEADER FILE

#define _CRT_SECURE_NO_WARNINGS #include #include

double read_double(FILE* infile); double calculate_sum(double number1, double number2, double number3, double number4, double number5); double calculate_mean(double sum, int number); double calculate_deviation(double number, double mean); double calculate_variance(double deviation1, double deviation2, double deviation3, double deviation4, double deviation5, int number); double calculate_standard_deviation(double variance); double find_max(double number1, double number2, double number3, double number4, double number5); double find_min(double number1, double number2, double number3, double number4, double number5); void print_double(FILE* outfile, double number);

// FUNCTIONS

#include "PA3.h"

double read_double(FILE* infile) { double d; fscanf(infile, "%lf", &d); return(d); }

double calculate_sum(double number1, double number2, double number3, double number4, double number5) { double sum = 0.0; sum = number1 + number2 + number3 + number4 + number5; return(sum); }

double calculate_mean(double sum, int number) { double mean = 0.0; mean = sum / number; return(mean); }

double calculate_deviation(double number, double mean) { double deviation = 0.0; deviation = number - mean; return(deviation); }

double calculate_variance(double deviation1, double deviation2, double deviation3, double deviation4, double deviation5, int number) { double variance = 0.0; variance = ((deviation1 * deviation1) + (deviation2 * deviation2) + (deviation3 * deviation3) + (deviation4 * deviation4) + (deviation5 * deviation5)) / number; return(variance); }

double calculate_standard_deviation(double variance) { double standard_deviation = 0.0; standard_deviation = sqrt(variance); return(standard_deviation); }

double find_max(double number1, double number2, double number3, double number4, double number5) { double first = (number1 > number2) ? number1 : number2; double second = (number3 > number4) ? number3 : number4; double third = (first > second) ? first : second;

return (third > number5) ? third : number5; }

double find_min(double number1, double number2, double number3, double number4, double number5) { double first = (number1 < number2) ? number1 : number2; double second = (number3 < number4) ? number3 : number4; double third = (first < second) ? first : second;

return (third < number5) ? third : number5; }

void print_double(FILE* outfile, double number) { fprintf(outfile, "%.2f", number); }

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

More Books

Students also viewed these Databases questions

Question

Differentiate 3sin(9x+2x)

Answered: 1 week ago