Description
Assignment’s Instructions
Write a C++ program which performs the following steps. Pay attention to any of the compiler’s warning messages. Remember to comment your code. Comments should explain every major step in your code.
- Display the selection menu shown in Figure 1.
- Process the user’s selection using a 𝑆𝑊𝐼𝑇𝐶𝐻 structure and ensure to account for lowercase and uppercase entries.
- If the user enters A 𝑜𝑟 𝑎 , invoke the function 𝑔𝑟𝑎𝑑𝑒𝑇𝑎𝑏𝑙𝑒 . Once done, prompt the user again.
- If the user enters B 𝑜𝑟 𝑏 , invoke the function 𝑓𝑖𝑙𝑒𝑆𝑢𝑚𝑚𝑎𝑟𝑦 . Once done, prompt the user again.
- If the user enters C 𝑜𝑟 𝑐 , terminate the program and print the message 𝑃𝑟𝑜𝑔𝑟𝑎𝑚 𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑡𝑒𝑑.
- If the user enters another value, show an error message and PROMPT the user again. The program should never terminate unless the user selects the exit option.
- 𝑔𝑒𝑡𝐿𝑒𝑡𝑡𝑒𝑟𝐺𝑟𝑎𝑑𝑒 : accepts one parameter of type 𝑓𝑙𝑜𝑎𝑡 and returns the corresponding letter grade as follows:
Range | Letter Grade | |
0 | 59 | F |
60 | 69 | D |
70 | 79 | C |
80 | 89 | B |
90 | 100 | A |
Other | X |
- 𝑝𝑟𝑖𝑛𝑡𝐺𝑟𝑎𝑑𝑒𝑇𝑎𝑏𝑙𝑒 : utilizes the function 𝑔𝑒𝑡𝐿𝑒𝑡𝑡𝑒𝑟𝐺𝑟𝑎𝑑𝑒 and prints the table shown in Figure 4. You may pick the proper column width to format and print the table.
- 𝑓𝑖𝑙𝑒𝑆𝑢𝑚𝑚𝑎𝑟𝑦 :
- Open the file “grades.dat”.
- If the file cannot be opened, display the error message “𝐸𝑟𝑟𝑜𝑟, 𝑐𝑎𝑛𝑛𝑜𝑡 𝑜𝑝𝑒𝑛 𝑓𝑖𝑙𝑒: 𝑔𝑟𝑎𝑑𝑒𝑠. 𝑑𝑎𝑡”
- Once the file is successfully opened, print the table shown in Figure 6 and use the function 𝑔𝑒𝑡𝐿𝑒𝑡𝑡𝑒𝑟𝐺𝑟𝑎𝑑𝑒 .
- Compute and print the 𝑚𝑖𝑛𝑖𝑚𝑢𝑚, 𝑚𝑎𝑥𝑖𝑚𝑢𝑚, and 𝑎𝑣𝑒𝑟𝑎𝑔𝑒 of all grades in the file. See the bottom of Figure 6
Assessment:
Figures
Figure 1: Selection Menu
Figure 2: invalid entries print an error message and prompts the user again
Figure 3: option ‘c’ terminates the program. Note the message before the program ends.
Figure 4: option ‘A’ prints the letter conversion table and prompts the user again
Figure 5: option ‘B’ prints an error message if the file cannot be opened and prompts the user again
Figure 6: option ‘B’ reads the file grades.dat, prints the table and prompts the user again