CO311: Introduction to Modern Programming II

Practice Test to prepare for Practical #8 on March 27

Please read the entire problem before jumping into the code!

Suppose you were a desk sergeant in the Army, and your Captain noticed your work last week on the practice test. He’s got a “real job” for your class: he has a special project from the base Colonel that he’s recruiting 100 volunteers for, but needs to keep track of how many volunteers are Privates versus the volunteers who aren’t. Here’s your task:

Write a program that will read “volunteer” data from any file that is specified by the Captain. The data will be organized as follows:

There will be an unknown number of records in the file, one record per line. Because the Captain only wants 100 volunteers, you can assume that there will be a maximum of 100 records in the file. Here is an  example record:

	Sergeant Joe Biner

Each record consists of three components:

If your class isn’t already named soldier, you’ll want to change it: the Captain has indicated that he’ll probably have some new modifications in a week or so, and you’ll want to be ready for anything. You can also remove the code that tracks serial numbers; your Captain isn’t concerned with that piece of data. After reading all the records into your program, print to the screen a “roll call” showing each volunteer in the following format: last name, first name (rank). Follow the listing with a separator line and a summary line that gives the sum of Privates who have volunteered. Example input:

Private Tally Jones
Sergeant Joe Biner
Private Adam Antte
Private Kelly Durbin
Corporal Charles Dugan

Example output:

Jones, Tally (Private)
Biner, Joe (Sergeant)
Antte, Adam (Private)
Durbin, Kelly (Private)
Dugan, Charles (Corporal)
------------------------------
Privates: 3

Use good programming methods, including separate functions where appropriate! You can find a sample data file (volunteers.txt) in the COMMON area of the FTP site under practicals/p8.