A file contains a series of random weights of blood donors from a blood donation event. Program 2 is developed to let th
Posted: Wed Apr 27, 2022 3:08 pm
Urgent help please I only have 1 hours to complete this please write the answer clearly.
*REMINDER!!*
use handwriting only. And cannot run any code in devC++. TQ.
A file contains a series of random weights of blood donors from a blood donation event. Program 2 is developed to let the Doctor in charge know about the number of donors, total weight of all donors and average weight of donors. This program will read all the weights from the input file named "weight.txt”. Figure 2 shows the content of the input file. Note: Let assume that the total of donors is unknown. Then, the program will calculate the number of donors, total weight of all donors and average weight of donors and display it into the output file named "Output.txt". Figure 3 shows the contents of the output file. Based on the comment in the Program 2, complete the program with appropriate C++ statement(s). Write your answers in Table 2. 50 45 65 36 78 45 89 65 48 58 89 92 71 76 88 56 53 60 68 Figure 2: Content of input file named "weight.txt" Number of donors: 19 Total weight of donors: 1232 Average weight of donors: 64.8421 Figure 3: Content of output file named "Output.txt" 1 17 Program 2 2 #include <iostream> 3 //(a) Library function (1mark) 4 5 using namespace std; 6 int main() 7 8 int a Number=0; 9 int numbers=0; 10 double sum=0.0; 11 12 double average=0.0; fstream Input File, Output File; 1/ (b) Open input and output files (5marks) 13 14 1/ (c) Test for unsuccessful opening file. (2marks) 15 16 cout << "failed to read file."; 17 Jelse 181 1/(d) Read all weights from input file. (2marks) 19 20 { 21 numbers++; 22 sum+=aNumber; 23 } 24 if (numbers>0) 25 average sum/numbers; 26 else 27 average=0.0; /* (e) Display number of donors, total weight of all donors and average weight of donors into output file (3marks) */ 28
*REMINDER!!*
use handwriting only. And cannot run any code in devC++. TQ.
A file contains a series of random weights of blood donors from a blood donation event. Program 2 is developed to let the Doctor in charge know about the number of donors, total weight of all donors and average weight of donors. This program will read all the weights from the input file named "weight.txt”. Figure 2 shows the content of the input file. Note: Let assume that the total of donors is unknown. Then, the program will calculate the number of donors, total weight of all donors and average weight of donors and display it into the output file named "Output.txt". Figure 3 shows the contents of the output file. Based on the comment in the Program 2, complete the program with appropriate C++ statement(s). Write your answers in Table 2. 50 45 65 36 78 45 89 65 48 58 89 92 71 76 88 56 53 60 68 Figure 2: Content of input file named "weight.txt" Number of donors: 19 Total weight of donors: 1232 Average weight of donors: 64.8421 Figure 3: Content of output file named "Output.txt" 1 17 Program 2 2 #include <iostream> 3 //(a) Library function (1mark) 4 5 using namespace std; 6 int main() 7 8 int a Number=0; 9 int numbers=0; 10 double sum=0.0; 11 12 double average=0.0; fstream Input File, Output File; 1/ (b) Open input and output files (5marks) 13 14 1/ (c) Test for unsuccessful opening file. (2marks) 15 16 cout << "failed to read file."; 17 Jelse 181 1/(d) Read all weights from input file. (2marks) 19 20 { 21 numbers++; 22 sum+=aNumber; 23 } 24 if (numbers>0) 25 average sum/numbers; 26 else 27 average=0.0; /* (e) Display number of donors, total weight of all donors and average weight of donors into output file (3marks) */ 28