Please read the entire problem before jumping into the code!
You did such a good job with the Count the Privates that your Captain wants you to modify it to count several ranks. He wasnt very clear, however, which ranks youre going to be counting! You decided to use the techniques covered in class to let you use a separate file to define the ranks to be counted (the criteria file), eliminating the need to keep changing the program whenever the Captain changes his mind. Youll also keep track of the volunteers that dont meet the rank criteria, just in case.
The other project parameters havent changed: he has a special project from the base Colonel that hes recruiting 100 volunteers for, and needs to keep track of the volunteers according to rank.
Heres your task:
Write a program that will first read criteria data from one file you specify, then reads separate volunteer data from any file that is specified by the Captain. The criteria will be a list of ranks to be counted, one rank per line. Youll need to be sure you match spelling and capitalization with the data file, or your project may not work!
Sample criteria file:
Private Corporal Sergeant Lieutenant
The data you receive 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:
After reading all the records into your program, print to the screen a summary showing the total of each rank of volunteer and the percentage of the total this represents. Including line for the count of volunteers that dont meet the criteria. Finish the output with a separator line and the grand total count of volunteers. Example input:
Private Tally Jones Sergeant Joe Biner Private Adam Antte Private Kelly Durbin Corporal Charles Dugan
Example criteria:
Private Sergeant
Example output:
Privates: 3 (60%) Sergeants: 1 (20%) Other: 1 (20%) ------------------------------ Total: 5
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. A sample criteria file (ranks.txt) can be found in the COMMON area under practicals/p9.