Lab 10:  File Access This lab accompanies Chapter 10 of Starting Out with Programming Logic & Design. Lab 10.1 – File Access and Pseudocode Critical Review When a program needs to save data for later use, it writes the data in a file.  The data can be read from the file at a later time. Three things must happen in order to work with a file.  1) Open a file.  2) Process the file.  3)  Close the file. An internal file must be created for an output file or input file, such as: Declare OutputFile myFile  //to write out Declare InputFile myFile   //to read in A data file must also be created to store the output, such as: Open myFile “thedata.txt” New keywords and syntax include the following: Open [InternalName] [FileName] Write [InternalName] [String or Data] Read [InternalName] [Data] Close [InternalName] AppendMode  //used with Open when need to append Loops are used to process the data in a file.  For example: For counter = 1 to 5 Display “Enter a number:” Input number Write myFile number End For When reading information from a file and it is unknown how many items there are, use the eof function.  For example: While NOT eof(myFile) Read myFile number Display number End While This lab examines how to work with a file by writing pseudocode.  Read the following programming problem prior to completing the lab.  The following program from Lab 9.1 will be used, with some modifications. The American Red Cross wants you to write a program that will calculate the average pints of blood donated during a blood drive.  The program should take in the number of pints donated during the drive, based on a seven hour drive period.  The average pints donated during that period should be calculated and written to a file.  Write a loop around the program to run multiple times.  The data should be appended to the file to keep track of multiple days.  If the user wants to print data from the file, read it in and then display it.  Store the pints per hour and the average pints donated in a file called blood.txt. Step 1:  Note that the getPints, getTotal, and getAverage functions do not change.  Also note that the references to displayInfo, getHigh, and getLow functions are removed to meet the new requirements.  In the pseudocode below, add the following: In the Main Module A variable named option of the data type Integer Input option Write an if statement that will determine which option to run Call a module called writeToFile that passes pints and averagePints Call a module called readFromFile that passes pints and averagePints In the writeToFile Module Declare an output file called outFile in AppendMode, with the name bloodFile.  (Reference: Appending Data to an Existing File, Page 370). Open the internal file (bloodFile) and a text file named blood.txt.  (Reference: Creating a File and Writing Data to it, Page 362.) Write the string “Pints Each Hour” to the file. (Reference: Writing Data to a File, Page 363). In the while loop, write each element of the pints array to the bloodFile.  (Reference: Using Loops to Process Files, Page 371). Write the string “Average Pints” to the file. Write the value of averagePints to the file. Close the bloodFile. (Reference: Closing an Output File, Page 363). In the readFromFile Module Declare an input file called inFile , with the name bloodFile.  (Reference: Reading Data from a File, Page 366). Open the internal file (bloodFile) and a text file named blood.txt. Read the string “Pints Each Hour” in from your file and store into a variable str1.  This should be done such as Read bloodFile str1.  The string will be stored in the variable str1. Display str1 to the screen. Read pints in from the bloodFile and store in the pints array. Display pints to the screen. Read the string “Average Pints” in from your file and store into a variable str2. Display str2 to the screen. Read averagePints in from the bloodFile. Display averagePints to the screen Close the file.  (Reference: Closing an Input File, Page 36…

Looking for solution of this Assignment?

WHY CHOOSE US?

We deliver quality original papers

Our experts write quality original papers using academic databases.  

Free revisions

We offer our clients multiple free revisions just to ensure you get what you want.

Discounted prices

All our prices are discounted which makes it affordable to you. Use code FIRST15 to get your discount

100% originality

We deliver papers that are written from scratch to deliver 100% originality. Our papers are free from plagiarism and NO similarity

On-time delivery

We will deliver your paper on time even on short notice or  short deadline, overnight essay or even an urgent essay