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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 19:10, hgdthbgjnb83661
What a backup plan that you have created in a event you encounter a situation
Answers: 2
image
Computers and Technology, 23.06.2019 12:00, daelinrobinson
If you're using an existing powerpoint presentation that will receive new slides based on a word outline, select the a. slide that will appear after the new slides. b. first slide in the presentation. c. slide that will appear before the new slides. d. last slide in the presentation.
Answers: 2
image
Computers and Technology, 23.06.2019 17:30, kenyasutton10
What are the most commonly found items in the trash according to the municipal solid waste report?
Answers: 1
image
Computers and Technology, 23.06.2019 22:00, bb1593
Jackson, who works in the finance department of a company, is holding a seminar for other employees on how to file taxes. only three employees sign up to attend the seminar. which device can he use to share his presentation with a group of three employees?
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 in other subjects:

Konu
Biology, 26.03.2021 21:30
Konu
Mathematics, 26.03.2021 21:30