A file contains a series of random weights of blood donors from a blood donation event. Program 2 is developed to let th

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

A file contains a series of random weights of blood donors from a blood donation event. Program 2 is developed to let th

Post by answerhappygod »

A File Contains A Series Of Random Weights Of Blood Donors From A Blood Donation Event Program 2 Is Developed To Let Th 1
A File Contains A Series Of Random Weights Of Blood Donors From A Blood Donation Event Program 2 Is Developed To Let Th 1 (135.37 KiB) Viewed 32 times
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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply