Question: Objective: Practice using pointers and sort and search. Write a menu - driven application that stores an inventory in an array of structs and lets
Objective: Practice using pointers and sort and search.
Write a menudriven application that stores an inventory in an array of structs and lets a user print inventory sorted in descending order and unsorted original order.
SpecificationsRequirements:
Inventory Item:
Item ID digit
name one word
quantity
price
main
Main Menu
Print items in the original order
Sort menu option with a submenu to sort by any field Id name, quantity, and price
use enum and switch to implement menus
if you are not familiar with enum, please see the textbook
it is better to use an enum class rather than an enum, but you have never used enum before, start with enum; enum has a simpler syntax
a user should be able to printed unsorted and sorted inventory as many times as a user wants
load records from an input file of unknown length
no record validation is needed
General NotesTips:
no vectors
thoroughly test your code
sorting
sorting using pointers is faster because you have to swap pointers only rather than the entire record. As you know, a pointer is usually stored in bytes
a submenu must have the option to go back to the previous menu or main menu. If a user got into a submenu by mistake, a user should be able to go back without executing other menu choices; for example, if a user entered the Sort submenu, a user should be able to go back to the previous menu or main without being forced to sort
submenu should be implemented as a switch with enum; let it fall through
write a sort menu outerwrapper function to
ask a user for the sort key
call the sort function, and then
call the print function
this way you'll have reusable sort and print functions; do not print from the sort function just because you need to sort it does not mean you want to print the result for example, if you want to use binary search, you need to have your array sorted
actual sort functioninner
write one function to sort by any field
use Bubble Sort; it is not the most effective but the easiest to modify
do not copy and paste sort code multiple times into the same function
analyze the sort code, what would be different when you sort by balance vs by name?
string class lets you compare strings as you would compare numbers strstr; "Adam""Adams" false ; "Adam" "Ben" false ; "may""May" true m has higher ASCII value than M
do not write or use the swap function to swap pointers sort does an enormous number of swaps and executing a function is a computational expense. It takes statements to swap pointers, do it in the sort function directly
Code Snippets:
enum SortOption ID PRICE,NAME, BACKTOMAINenum TYPE declaration, it is not a variable
int sortOption;
cinsortOption;
switchsortOption
case ID:
case PRICE:
case NAME: sortInventory pInventory numRecs, sortOption ; break;
case BACKTOMAIN "Going back to the main menu"; break;
default: cout Invalid choice. Try again"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
