Question: Problem: Write a program in C++ that should read through a specified file and determine the most frequent and second most frequent male and female
Problem: Write a program in C++ that should read through a specified file and determine the most frequent and second most frequent male and female names and then display them and their frequencies, together with some additional statistics, in a specified format.
Requirements
The program should contain and use at least the following functions:
a) string getUserInput(string) -- Prompts the user for an input, returns the string that the user entered.
b) void errorMsg(string, bool) -- displays an error message and optionally terminates. We wrote this in class.
c) void getTokens(string s, string &name, string &gender, string &count) -- this is one of the workhorse functions for the assignment. Each time you read a line of data from the file, you then call this function to pick out the individual pieces from it. Note that it returns them all via string reference parameters.
d) void updateMaxInfo(string name, int count, string gender, int & maxname, string & maxgender, int &maxcount) -- this is the other workhorse for the assignment. Every time you read the data from a line (the name, gender, and count), you call this function to update the current running maximum information for whichever gender the line corresponds to.
The program is required to work like this:
Get the name of the file to process from the user. Use the function getUserInput() for this.
If the file doesn't exist (it's not possible to open it), call the errorMsg() function to display an appropriate message and terminate the program.
Read the data for each name and call getTokens() to extract the three pieces of information. Then call updateMaxInfo() to update the variables which hold the current maximum and second maximum frequencies for the gender appropriate for the name you read. This is a looping process...each cycle of the loop processes one name's data from the file.
The output should be displayed in the manner of the following example:
File to process :
Most frequent female:
Frequency:
Second frequent female:
Frequency:
Distinct female names:
Most frequent male:
Frequency:
Second frequent male:
Frequency:
Distinct male names:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
