Assignment 9 - File Handling

1. Write a C program to find the average of a sequence of numbers stored in a text file.

Sample Output
Enter the filename: ch09/q01.txt
sum = 383
count = 6
average = 63.83

   
2. Write a C program to read a sequence of numbers from a text file and then write it to another text file in reverse order.

Sample Output
Input filename: ch09/q02i.txt
Output filename: ch09/q02o.txt
Program completed successfully

   
3.

Write a C program to input a sequence of numbers from the text file "q03_in.txt". Then, prompt the user to enter a number and find its position in the array.

Sample Output
Enter the number = 80
Not found
Enter the number = 23
It is at position 1
:

Optional  
   
4. Write a C program to read a sequence of names from the text file "q04_in.txt", sort it into descending order, and then send the output to another text file "q04_out.txt".
   
5. Write a C program to encrypt a text file by using each of the following methods:

(a) replacing every character in the file by its predecessor, that is, c = c – 1.
(b) swapping adjacent characters, e.g. abcdef => badcfe, abcde => badce

   
6. Write a C program to read a sequence of words from the text file "q06_in.txt", extract those words with "'era"' as a substring and then send the output to the text file "q06_out.txt".
   
7. Complete the Telephone Enquiry System so that it can generate the sample output as shown below. Program Outline

Sample Output

Telephone Enquiry System
1) List Records
2) Insert Record
3) Delete Record
4) Update Record
5) Exit
Choice: 1

Veronica_Chin 91748524
Erin_Lee 22334455
Tiffany_Yu 99112233
Winnie_Tsang 10106789

Telephone Enquiry System
1) List Records
2) Insert Record
3) Delete Record
4) Update Record
5) Exit
Choice: 2

Inserting record...
Name: Phil_Lee
Tel no: 25506111

Telephone Enquiry System
1) List Records
2) Insert Record
3) Delete Record
4) Update Record
5) Exit
Choice: 1

Veronica_Chin 91748524
Erin_Lee 22334455
Tiffany_Yu 99112233
Winnie_Tsang 10106789
Phil_Lee 25506111

Telephone Enquiry System
1) List Records
2) Insert Record
3) Delete Record
4) Update Record
5) Exit
Choice: 3

Deleting record...
Name: Tiffany_Yu

Telephone Enquiry System
1) List Records
2) Insert Record
3) Delete Record
4) Update Record
5) Exit
Choice: 1

Veronica_Chin 91748524
Erin_Lee 22334455
Winnie_Tsang 10106789
Phil_Lee 25506111

Telephone Enquiry System
1) List Records
2) Insert Record
3) Delete Record
4) Update Record
5) Exit
Choice: 4

Updating record...
Name: Erin_Lee
Old tel no: 22334455
New tel no: 11223344

Telephone Enquiry System
1) List Records
2) Insert Record
3) Delete Record
4) Update Record
5) Exit
Choice: 1

Veronica_Chin 91748524
Erin_Lee 11223344
Winnie_Tsang 10106789
Phil_Lee 25506111

Telephone Enquiry System
1) List Records
2) Insert Record
3) Delete Record
4) Update Record
5) Exit
Choice: 5


   
8. Write a C program to simulate the operation of an Automatic Teller Machine. Structures and functions should be used in this program.

Sample Output

Welcome to Hong Kong Bank

Userid: Tiffany_Yu
Password: s001230

Select one of the following options:
1) Cash Withdrawal
2) Deposit
3) Fund Transfer
4) Balance Check
5) Exit

Choice: 4

Your account balance is $63300

Select one of the following options:
1) Cash Withdrawal
2) Deposit
3) Fund Transfer
4) Balance Check
5) Exit

Choice: 1

Enter the amount you have to withdraw: 1700
Transaction accepted, please take the money
1 $1000 paper note
1 $500 paper note
2 $100 paper note

Select one of the following options:
1) Cash Withdrawal
2) Deposit
3) Fund Transfer
4) Balance Check
5) Exit

Choice: 5

Thanks for using the ATM services

Welcome to Hong Kong Bank

Userid: Kristy_Chan
Password: s001017

Select one of the following options:
1) Cash Withdrawal
2) Deposit
3) Fund Transfer
4) Balance Check
5) Exit

Choice: 3

To which account you want to transfer your money: Tiffany_Yu
Amount you want to transfer: 2000
Transfer successful

Select one of the following options:
1) Cash Withdrawal
2) Deposit
3) Fund Transfer
4) Balance Check
5) Exit

Choice: 5

Thanks for using the ATM services

Welcome to Hong Kong Bank

Userid: Tiffany_Yu
Password: s001230

Select one of the following options:
1) Cash Withdrawal
2) Deposit
3) Fund Transfer
4) Balance Check
5) Exit

Choice: 4

Your account balance is $63600

Select one of the following options:
1) Cash Withdrawal
2) Deposit
3) Fund Transfer
4) Balance Check
5) Exit

Choice: