Question
Write a C++ program in Cpp 11 with the following description Your file names will be makefile, main.cpp, node. cpp , node. hpp , linked_list.cpp,
Write a C++ program in Cpp 11 with the following description
Your file names will be makefile, main.cpp, node.cpp, node.hpp, linked_list.cpp, and linked_list.hpp. Your executable should be named grocerylist. Add a line to your makefile that executes the executable. Tab and add the line:
Write an ordered linked list to implement a grocery list. You will ask the user for information and modify the list as the user indicates. All of the information will be written to a file. Just as in the first program, you are to check to see if the file exists. If it does, open the file and populate the list. When the program terminates, print the information to a file. Call the file grocerylist.txt. The first entry in the list is to be the number in the list.
You will modify the Node class that you wrote in the last program. You will create a structure that contains the main data and the Node class will contain a variable of that structure and the link. You will write an ordered link list class that will insert, delete, traverse, and retrieve items from the list. The list will be ordered on the UPC code. You will not enter duplicate items. If the item already exists, then you need to indicate that to the user and not enter it in the list.
Structure data:
UPC code number of the item
Item description description of item that must be able to include spaces
Quantity number of item to purchase
Cost cost per item
Aisle number of aisle at store
Node class data:
Structure will be a declaration of the structure defined above
the information of the structure must be private to the class, but can be returned from the class.
Link pointer to next item in the list
Node class member functions
Default constructor
Constructor that takes UPC, item, quantity, cost, and aisle
Mutator function to set next pointer
Accessor function to return next pointer
Accessor function to return UPC code
Accessor function to return complete structure
compare_UPC function that will compare a given UPC against the one in the class
process_data function that will calculate and return the total cost for this item. Total cost = cost * quantity.
NOTE: Total cost will NOT be stored in the structure
Linked list class data
head pointer points to first Node in list
tail pointer points to last Node in list
count keeps track of number of Nodes in list
Linked list class functions
Any needed constructors
Insert node
Delete node
Traverse list
Retrieve node
Check for empty
Return number in list
Note: This is an ORDERED list. It will be ordered by UPC number.
Note: Remember that a linked list is created in static (automatic memory) and a Node is in dynamic memory.
Requirements for main:
In the main program, you are to declare the linked list when the execution of your program begins. You will present a menu to the user to ask if the user wants to 1) Add a grocery item 2) Delete an item 3) Retrieve an item 4) Traverse the list forwards and print out all of the items or 5) exit the program. When the user selects 1, the program should ask for the UPC code, item description, quantity, and aisle. When the user selects 2, the program should ask for the UPC code to be deleted. The program should ask the user to confirm that item is to be deleted. When the user selects 3, the program should ask for the UPC code to be retrieved. When the user selects 4, all of the nodes should be traversed in the list and printed. The total cost for each item should be calculated. The items should be printed in the linked list traverse function by using the accessor function for the entire structure. When the user selects 5, the program should end and write the current list to the file.
Sample input:
1
Enter UPC code:
Enter description:
Enter quantity:
Enter cost:
Enter aisle:
2
Enter item to delete:
Show item to delete
Confirm delete (y/n)?
3
Enter UPC code:
Show information
4
print out list in order by UPC code. Should include total cost
5
Exit program and write list to file.
Sample output when 4 is selected.
1234 Butter 1 $3.00 Aisle 10
1235 Sour Cream 2 $1.25 Aisle 10
1236 Bread 5 $1.40 Aisle 22
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started