Starting Out with Programming Logic and Design2....solved

Starting Out with Programming Logic and Design2....solved

Starting Out with Programming Logic and Design2This lab examines how to work with a file by writing pseudocode.Read the followingprogramming problem prior to completing the lab.The following program from Lab 9.1will be used, with some modifications.The American Red Cross wants you to write a program thatwill calculate the average pints of blood donated during ablood drive.The program should take in the number of pintsdonated during the drive, based on a seven hour driveperiod.The average pints donated during that period shouldbe calculated and written to a file.Write a loop aroundthe program to run multiple times.The data should beappended to the file to keep track of multiple days.If theuser wants to print data from the file, read it in and thendisplay it.Store the pints per hour and the average pintsdonated in a file called blood.txt.Step 1:Note that the getPints, getTotal, and getAverage functions do not change.Alsonote that the references to displayInfo, getHigh, and getLow functions are removed tomeet the new requirements.In the pseudocode below, add the following:In the Main Modulea.A variable namedoptionof the data type Integerb.Inputoptionc.Write an if statement that will determine which option to rund.Call a module calledwriteToFilethat passespintsandaveragePintse.Call a module calledreadFromFilethat passespintsandaveragePintsIn the writeToFile Modulef.Declare an output file calledoutFileinAppendMode, with the namebloodFile.(Reference: Appending Data to an Existing File, Page 370).g.Open the internal file (bloodFile) and a text file namedblood.txt.(Reference: Creating a File and Writing Data to it, Page 362.)h.Write the string “Pints Each Hour” to the file. (Reference: Writing Data to a File,Page 363).i.In the while loop, write each element of the pints array to the bloodFile.(Reference: Using Loops to Process Files, Page 371).j.Write the string “Average Pints” to the file.k.Write the value of averagePints to the file.l.Close the bloodFile. (Reference: Closing an Output File, Page 363).In the readFromFile Modulem.Declare an input file calledinFile, with the name bloodFile.(Reference:Reading Data from a File, Page 366).n.Open the internal file (bloodFile) and a text file namedblood.txt.
Powered by