Chapter 10 HW

.docx

School

George Mason University *

*We aren’t endorsed by this school

Course

306

Subject

Computer Science

Date

Apr 30, 2024

Type

docx

Pages

2

Uploaded by JudgeTiger2966 on coursehero.com

Part I Short Answer 1. What is a sequential file and what are the disadvantages of sequential files. A sequential file is a type of data organization where documents are kept in a predetermined order. Sequential files' drawbacks include their time-consuming nature, incompatibility with contemporary technologies, and lack of direct access. 2. Define each of the following file processes. a. READ - Retrieving data from an existing file is the process of reading from a file. b. WRITE - Writing to a file entail either creating a new file if one doesn't already exist or appending additional data to an existing one. c. OPEN - A connection is made between your software and the file on disk when you open a file. d. CLOSE - When you close a file, the program's connection to the file ends. e. APPEND - Adding new data to the end of an existing file is known as appending. f. EOF - The symbol for the end of a file is EOF. 3. What are the similarities between files and arrays ? Sequential access, text files, and data storage are the similarities between files and arrays. 4. What are the differences between files and arrays ? When it comes to store in memory manipulation, arrays are dynamic data structures, whereas files offer permanent storage for a variety of data kinds. 5. What is the logic error in this code? Module readFile(String filename) Declare inputFile file Declare string item Open file filename While eof(file) Read file item Display item endWhile end Module The while loop condition in the given code is the source of the logic mistake. There is an issue with the condition While eof(file). Part II Programming Exercise - Searching an Array Design a pseudocode program that Reads the first 20 records from salesFile Loads those 20 amounts into an array named dailySales[ ].
Totals and outputs the total of all sales. If you need help, look at the examples in your textbook for processing data files. Module main() Declare salesFile, dailySales as Array of Real Declare Integer count = 0, calcTotal = 0, readSales // Open the sales file Open SalesFile "sales.dat" // Read the first 20 records and store them in the dailySales array While count < 20 Read salesFile[count] dailySales[count] = salesFile[count] count = count + 1 End While // Calculate the total sales For i = 0 to 19 calcTotal = calcTotal + dailySales[i] End For // Output the total sales Output "Total sales: $" + calcTotal End Module
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help