0% found this document useful (0 votes)
14 views

Chapter10 Examples

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Chapter10 Examples

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Programming Logic & Design

Sequential Data Files Examples


Example #1 (Problem #1 Page 652)
a. Input names and three test scores of students from the user, terminated by "ZZZ",0,0,0, and
create a data file "grades" with records of the following form:

student_name (String), test_1 (Integer), test_2 (Integer), test_3 (Integer)

b. Display the contents of the file "grades" created in Part a. Each student’s record should
appear on a separate line and include the total score (the sum of the three tests) for that
student. For example, a line of output might be as follows:

R. Abrams 76 84 82 242

c. Modify the program of Part b so that at the option of the user, it displays either the entire
contents of the file "grades" or just the record of a specified student. In either case, for each
student displayed, also display his or her total test score.
Example #1 (Problem #1 Page 652) - Notes
• To_Integer() takes in a string and returns the integer number (e.g.
To_Integer("37") is 37)

• To_Float() takes in a string and returns the number (e.g.


To_Float("37.5") is 37.5)

• Get_Nth_String returns the nth string in a long string, separated by the


separator (e.g. Get_Nth_String("ab,cd,ef",",",2) is "cd"). It returns the
separator after the last separated string (e.g.
Get_Nth_String("ab,cd,ef",",",4) returns ",")
Example #2 (Problem #2 Page 652)
Assume that a file named "inventory", which contains the inventory of parts for the Legendary Lawn
Mower Company (from Section 10.5), already exists with records of the following form:

part_Number (Integer), part_Name (String), quantity (Integer)

Also assume that the records in this file are ordered by increasing part number. For each part of this
problem, write a program that performs the indicated task.

a. Input a part number from the user and delete the corresponding record from the "inventory" file.

b. Input a part number and a quantity from the user and modify the record corresponding to that
part number by changing the value of its last field to the quantity input.

c. Input a new part number, part name, and quantity from the user and insert the corresponding
record in the proper place in the "inventory" file.

You might also like