+1-316-444-1378

BIS1003 Introduction to Programming

Workshop 7

Topic 7: Files and exceptions

Apply and test your knowledge of the current and previous topics by attempting the

questions below. Completing these questions will help you to succeed in your subject.

Workshop Questions

1. Write a program to create a data file for storing student records. Assume a student

record consists of the following fields: ID, Last Name, First Name, and Marks. The

Marks field contains a number between 0 and 100. Write a program that loops to get

data for multiple students from the user and stores those as records in the student.txt

file. The user should enter a negative number as the ID to signal the end of the loop.

Your program should be able to reject non-numeric and out of range marks.

Additionally, handle all file related exceptions.

2. Write a program that reads the student data file ‘students.txt’ (containing the same

record structure as exercise (1) and displays the records of only the students having

marks more than 80. Your program should handle all file I/O exceptions.

3. Write a program that asks the user for a file name and then display contents of that

file preceded by the line numbers as shown in format below. Your program should

handle all file I/O exceptions.

1: text of line1

2: text of line2

Categories: Uncategorized