Your goal is to implement an application that reads a file, modify its content, and writes the modification back to the same file. The file includes 2 lines of integers. The first line indicates which integer on the second line has been selected (active). And the second line lists all the integers in the list (maximum of 10).
Your application should have a menu that is constantly displayed on the screen (see the menu below). Right below the menu, the program should display list of all integers in the file (second line). Also, it should show which integer is currently selected (active) by displaying an arrow to its left.
The user should be able to select a menu item by entering its associated key and pressing the Enter key on the keyboard.
“Select Down” selects the next item in the list. If the item at the end of the list is selected, this option selects the first item in the list. “Select Up” selects the previous item in the list. If the first item is selected, this option selects the item at the end of the list.
“Move Down” moves the selected item one position down. If the item at the end of the list is selected, moving down will not be possible. “Move Up” moves the selected item one position up. If the first item is selected, moving up will not be possible.
“Insert” will insert an integer before the selected item and makes the newly inserted item active. The integer is typed by the user. If the list is full, insertion will not be possible. Do not accept incorrect values (like non-integer or characters).
“Delete” deletes the active item. After deleting, the next item in the list becomes active. If the item at the end of the list is deleted, its previous item becomes active. If there is one item or no item in the list, selecting the delete option will display an arrow without any integer to its right.
“Sort” sorts the list in ascending order. The active item after the sort is same as the active item before the sort.
“Exit” ends the application.
Make sure to use the top-down design to break your program to many simpler tasks (at least one function per task). Also create helper functions (example: function to check if the list is full or function to check if the list is empty). The functions should do one specific task only. Do not use global variables. Use one single dimension array only. Make sure to check the special cases. Example: when the list is full, when the list is empty or when the last item in the list is selected.
When you start the program, the program should copy the content of the file into a variable and an array before closing the file. When the exit option is selected, the program should open the same file for output, writes back the content of the variable and the array into the file, and it closes the file before exiting the program. When you are using the program, you should modify the array and not the file.
Make sure to test your program completely before submission. Do not forget to add comments.
Submit your well-documented C++ program via Canvas.
Menu:
- Select Down
- Select Up
- Move Down
- Move up
- Insert
- Delete
- Sort
- Exit