The purpose of this lab is to give you some practice with the ‘while’ and more advanced ‘if’ statements. Follow the steps below and turn in printed copies of your source code after steps 4 and 5 (No digital copy is required).
1. Write a C++ program that implements the flowchart given on the accompanying page (It should exactly model the flowchart). This is a very simplistic program, which needs several improvements. Those improvements will come in the remaining steps. This basic idea of this program is that we are going to place a PC running this program in a local mall to summarize the results of the “Pepsi Challenge” taste test. Individuals will be asked to sample both Coke and Pepsi and then enter their vote by typing ‘c’ or ‘p’ on the keyboard. At the end of the day, the person responsible for the test will enter a ‘q’, which will be the signal to quit. At that point the program will report the winner of the contest as either Coke or Pepsi.
2. One problem with the given algorithm is that an invalid vote is counted for Coke. For example, if a person went to type ‘p’ for Pepsi, but accidentally typed ‘o’ (which is next to ‘p’), the program is presently counting the vote for Coke. Add an ‘if’ statement within the ‘if-else’ statement so that only ‘c’ votes are counted for Coke, and invalid votes are simply not counted at all.
3. Another problem with this program is that it is case sensitive. If the shift key is pressed or caps lock is on, a vote of ‘P’ or ‘C’ does not get counted of the appropriate Cola. Fix the program so that it is case insensitive so that either ‘p’ or ‘P’ is counted for Pepsi, either ‘c’ or ‘C’ is counted for Coke, and either ‘q’ or ‘Q’ is accepted as the signal to quit.
4. No doubt Coke was the company that set up this test because when the vote is tied, the given algorithm will declare ‘Coke’ the winner. Fix the program so that when there is a tie, it will say ‘Coke and Pepsi tied’, rather than saying ‘Coke wins’. Be sure to print a copy of your program at this point.
5. Fix the program so that it has all the features of the program in step 4, but can handle a three-way taste test between Coke, Pepsi, and Dr. Pepper. Print a second copy of your program at this point.