Tải bản đầy đủ (.pdf) (2 trang)

Supplementary tasks file processing

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (188.63 KB, 2 trang )

Chapter 9: File Processing
A. Review
A.1. What is a file pointer? How different is it from the pointers of other types? Give an example for
illustration.
A.2. What is a sequential-access file? What is a random-access file? Make a comparison between them.
Give an example of their use contexts.
A.3. Describe the required steps for reading data from a file. Give an example for illustration.
A.4. Describe the required steps for writing data into a file. Give an example for illustration.
B. Practice
B.1. Write a program to save the following table into a file that can be later opened and read with
Notepad. After that, read the saved file and find the customer who bought the products the most and
the customer who had the lowest value.
CustomerID
121
310
400
592
520

Location
Ho Chi Minh City
Ho Chi Minh City
Da Nang
Ha Noi
Nha Trang

ProductBought
10
15
8
12


9

Value
25.06
60
20.83
53.92
24.1

B2. Write a program to update the location of all the customers whose previous location is “Ho Chi Minh
City” in B.1 and then save all the data existing and updated data back to the file.
B.3. Write a program to save the following table into a file that can not be read with Notepad. After that,
read the saved file and count the number of students in each class. The result will be then written to a
file that can be opened and read with Notepad.
StudentName
AA Nguyễn
BB Smith
CC Kennedy
DD Lưu
EE Scott

Class
CCO1
CCO2
CCO2
CCO1
CCO2

AVG
8.3

8.1
8.2
8.4
8

B.4. Write a program to update the AVG of the student whose name is “CC Kennedy” from 8.2 to 8.5 in
B.3 and then save all the data existing and updated data back to the file.

1


B.5. Write a program to insert another student of class “CCO1” into the resulting file in B.4 with the
following information:
StudentName = “AB Brown”
Class = “CCO1”
AVG = 8.3
B.6. Use the file processing for your assignment.
B.7. Check your coding style with the programs you have written. Should anything be changed with your
programs so that they can be not only executable but also readable? Rewrite your programs if yes.

2



×