subject

We are designing a program that must do the following: Read 3 integers from a file called "data. txt"
Sum the integers
Compute the mean of the integers
Output the mean to a file called "mean. txt".
We are required to select functions from the library provided below to complete our program. Inside of the main () function, fill in the correct C statements to satisfy the four requirements listed above. You must fill in all the lines labeled with "statement x", where x is 2, 3, 4, 5, or 6. The first statement has been completed for you.
// These are the library functions that we must invoke!
// Precondition: The input file must already be open.
int read_integer (FILE *infile)
{
int number = 0;
fscanf (infile, "%d", &number);
return number;
}

int calculate_sum (int number1, int number2, int number3)

{
int sum = 0;
sum = number1 + number2 + number3;
return sum;
}

double calculate_mean (int sum, int number)
{
double mean = 0.0;
mean = ((double) sum) / number;
return mean;
}
// Precondition: The input file must already be open.
void print_double (FILE *outfile, double number)
{
fprintf (outfile, "%0.2lf\n", number);
}
// Fill in the appropriate statements for main ().
#include
int main (void)
{
int n1 = 0, n2 = 0, n3 = 0, sum = 0;
double average = 0.0;
FILE *infile = NULL, *outfile = NULL;
// We will not check to see if files were opened successfully; assume they are
infile = fopen ("data. txt", "r");
outfile = fopen ("mean. txt", "w");
n1 = read_integer (infile) // statement 1
// statement 2 (2 pts)
// statement 3 (2
pts)
// statement 4 (2 pts)
// statement 5 (2 pts)
// statement 6 (2
pts)
fclose (infile);
fclose (outfile);
return 0;
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 07:30
Events and conditions that happen within an organization that are somewhat easier to deal with when responding to change are called
Answers: 1
question
Computers and Technology, 22.06.2019 11:00
The great length of north america causes the climate to be varied. true false
Answers: 2
question
Computers and Technology, 23.06.2019 19:30
You can apply several different worksheet themes from which tab?
Answers: 1
question
Computers and Technology, 24.06.2019 08:10
Where are american poets found in the dewey decimal system
Answers: 1
You know the right answer?
We are designing a program that must do the following: Read 3 integers from a file called "data. tx...
Questions
question
Computers and Technology, 23.12.2019 17:31
Questions on the website: 13722360