You are asked to write a program that uses functions with reference variables to implement the following task.Students are asked to take a survey on food in school’s cafeteria.
The survey is scaled as follows:1. Poor2. Below Satisfactory3. Neutral4. Satisfactory5. GoodThis survey was distributed in class in hard copies.After collecting the surveys, the secretary is going to enter the results in our program manually so that we have an electronic copy of these records for future reference. Your program is going to let the secretary input information that is the name of the student (for simplicity we assume one-word first names) followed by their vote (in numbers) or quit the data entry. This task will be implemented via the following menu:1. Enter data2. Quit Your program should write the information that it reads form the keyboard into an output file called surveyResults.txt. The data in this file will look like the following Andrew 1 Lisa 3 . . . When the user chooses to quit, your program reads the file that it just generated based on user input, this time to compute how many students voted for each survey option.Notice we do not know how many students have taken the survey and your code should reflect this.Do not try and count the entries, we have a better way of letting the successful read be our guidance in whether we have data left in the file or not. Your program should report to the user how many students voted for each survey option. So you need to have 5 counter variables corresponding to 5 options in the menu. Note that the name of the students will not be part of this report at this stage.
You MUST use the functions based on the prototypes given below: void getName ( string & ); void getVote ( int & ); void displayStat ( string ); Function getName: This is a void function that receives a string reference variable.
It first prompts the user for the first name: Please enter the first name(one-word) and press enter. It then reads this string into the reference variable it receives. This way the same variable that is passed to this function in main will now contain the first name entered by the secretary in this function. This is how reference variables work.
Function getVote: This is another void function whose job is similar to getName, but instead of "fetching" the name, it "gets" the vote of the user in integer form. Therefore this function is the one that displays the survey as a menu to the user. So that they know how and what they are voting on. So it first displays the following:
Please rank the cafeteria food by choosing an option:1. Poor2. Below Satisfactory3. Neutral4. Satisfactory5. Good The user is expected to enter a number in 1-5 inclusive, this input will again be read/stored in the reference variable that this function is receiving so that whoever called it will have their variable containing the student’s vote (in int form).Function displayStat: This function receives the name of the file in its string parameter.In order to count the number of votes per survey options, it should declare 5 counters locally, that will be used in the report.It should read from the file, not knowing how many lines of data there are in the file, but knowing what pattern of data is expected per line: one-word name, followed by space or tab and an integer in the range 1-5 inclusive.You keep reading the data in the file in a while loop.At this point we are not interested in the name of the student, so we just read the name so that we can get to their vote.A switch statement will be used to check the vote and update its counter as the result.After the while loop you have 5 counters storing the information that you will display to the user in five lines (since we have 5 options) one of which could look like the following:2 student(s) voted for option 1. . . .So here is the step by step instructions to follow for your program:• Set up a do-while loop to display the 2-option menu so the user (the secretary) gets a chance to enter data or quit. • Inside the do-while loop after you check that the user wants to enter data, you call the getName function first, and pass the main’s local variable to store each student’s name, to this function. So that whatever the user inputs to this variable inside the function, main can see it as well.
• After asking the getName function to get the name for you, call the getVote function to "fetch" the student’s vote.• After the above two function calls, main has the user’s data in its local variables. And can write them into the output file we call surveyResults.txt. • Loop back and see if the user wants to enter more data or quit.• After the loop, we are done with data entry by the user, so our file has the record of user’s input. So we can close the file as an output file here.• Now we are ready to pass the name of this file to our function displayStat.
• MAKE SURE TO CLOSE YOUR FILES IN ANY FUNCTION YOU DEFINE THEM. THIS IS VERY IMPORTANT FOR THIS PROGRAM.
BONUS PART: TOTAL OF 25 BONUS POINTS (PARTIAL CREDIT APPLIES!) Have a function that receives the first name of a student and the name of a file and looks for the student’s vote.The function prototype is: void findStudentVote(string, string); If you found them you output a message like: Andrew thinks the quality of cafeteria food is poor.
And if you could not, output a message like: Jim did not participate in our survey.
Notice we are interested in the interpretation of the student’s vote and not just the option number.In order to do this you MUST have a separate function that we define as: string voteMeansWhat ( int ); This function MUST BE CALLED by the findStudentVote function.Please note that earning the full Bonus points requires adhering to the instructions above.Follow them carefully in your code to secure the full Bonus credit.
Have a segment of code in the main function to test this additional section. You should have a segment that prompts the user for the name and then call your function (that calls another function in its definition) to report back about the student they asked about.
side note from me: my book is called: starting out with c++ and it is a grapefruit on the front!! thanks!!