CO311: Introduction to Modern Programming II

Lab Practical #13: May 8, 2000

Please read the entire problem before jumping into the code!

Using the in-class examples and practice test as a guide, modify the solution to the Practical 8 Practice Test to use a “safe” array to hold your data read from a file.

The following is the exact instructions from that original practice test:

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:

  • A single-word field that represents the rank (e.g.: Sergeant).
  • A single-word field that represents the first name (e.g.: Joe).
  • A single-word field that represents the last name (e.g.: Biner).

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.

Your class definition, implementation and driver program should be in separate files as appropriate. Submit your copies to the FTP site in a separate folder/directory called P13.

Submissions to the FTP site that are NOT saved in the separate P13 directory will be automatically docked 10 points for failing to follow instructions.