Week 9 Lab Exercises PDF
Week 9 Lab Exercises PDF
College of Science
Department of Computer Science
COMP2002, Spring 2011
Week 9 Lab Exercises (Files)
Exercise 1:
Write a C++ program which reads from a file inventory records of some items and then
performs some tasks based on the user’s selection. The program must first display for the
user a menu to allow him/her to select one of the following tasks. Once the user made
his/her selection, then the program must perform the corresponding task and then re-
display the menu again and again until the option ‘X’ is selected:
Menu Options:
D -> Display the contents of the input file on the screen
T -> Calculate and display the total price on the screen
X -> Exit the program
When the user selects the first two options, the program must read the input file, perform
the task and then close the file. A sample input file can contain the following records
where the 1st column is the item#, the 2nd column is the price and the 3rd column is the
quantity in the stock:
Exercise 2:
Modify the above program so that the menu will have one more option B as follows:
Menu Options:
D -> Display the contents of the input file on the screen
T -> Calculate and display the total price on the screen
B -> Save the big quantities items in an output file
X -> Exit the program
where big quantities are those which exceed 1000 in the stock. When the user selects this
option, the program must first read the name of the output file from the keyboard and then
write the matching records on it and then close it.