Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Qn3. Write a complete C program - you must declare and use a self-referential structure for this question (8 Marks) You are asked to write

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Qn3. Write a complete C program - you must declare and use a self-referential structure for this question (8 Marks) You are asked to write a program for a computer shop that handles the purchases through online. When the customer places order to buy a computer, the shop will search for the specific item upon customers request in the order of first come first served basis. The items (computer/laptops) available in the shop are kept in a text file called computers.txt. At the beginning of the program the details of the computers are read from computers.txt and stored in a Linkedlist. Then the list of the computers ordered by customers is saved in a queue. Then the program should take the order from the beginning (head) of the queue and search for it in the Linkedlist. If the item found in the list delete it and put this computer in a stack to be able to retrieve for the last computer sold. The main() function handles all interactions with the user and other functions: Calls a function named readList()which opens a text file computers.txt (a sample text file is shown below) for reading and storing names of computers from the file to a LinkedList in order of name (insertion should happen in alphabetical order). It then repeatedly calls the menu () function to display user options, get the user selection returned by the menu() function, use a switch (or if.else if) statement to process user request by calling appropriate function(s). Details of options in menu function: (1) Display the current stock of computers, here you display the contents of the LinkedList (2) Add a new computer to stock - you need to insert a new computer to LinkedList (3) Display next order information displays the next computer in the order-list (first node of the queue) (4) Display all orders - displays all nodes of the queue (5) Add order to queue-adds new order to the end of the queue (6) Process the next order - Processes the first order in the queue. This function searches for this computer in the Linkedlist and deletes (if found) from LinkedList and puts it into a stack, deletes from the queue as well. (7) Cancel last order - It cancels the last processed order. It inserts the computer (top of the stack) back into LinkedList (computer is not added back into queue). (8) Display info of last order - displays the information of the last processed order (top of the stack). (9) Update computer file - updates the computers.txt with the remaining computers in the list (including the computers added in option2). (10) Quit program Sample computers.txt file computers.bst - Notepad File Edit Format View Help Dell Inspiron Dell G7 Lenovo ThinkPad Lenovo X1 Dell Alienware Acer Spin AS us Vivobots HP Spectre Lenova Yoga Samsung Galaxy Asus Zenbook Lenovo Ideapad HP Pavilion MacBook Air MACBook Pro Qn3_Sample_run - Notepad File Edit Format View Help Successfully loaded Computer file. What would you like to do? (1) Display the current stock (linked-list) (2) - Add a computer to stock (linked-list) (3) - Display next order info (4) - Display all orders (5) Add order to queue (6) Process the next order (7) Reverse last order (8) - Display info of last order (9) - Update computer file (10) Quit program 1 1 Computer Name I + | Acer Spin Asus Vivobook | Asus Zenbook | Dell Alienware | Dell G7 | Dell Inspiron | HP Pavilion | HP Spectre | Lenova Yoga | Lenovo Ideapad | Lenovo ThinkPad | Lenovo X1 | MAcBook Pro | MacBook Air | Samsung Galaxy What would you like to do? (1) Display the current stock (linked-list) (2) Add a computer to stock (linked-list) (3) - Display next order info (4) - Display all orders (5) - Add order to queue (6) - Process the next order (7) Reverse last order (8) - Display info of last order (9) - Update computer file (10) - Quit program 2 Please enter Computer name to insert: Lenovo XYZ What would you like to do? (1) - Display the current stock (linked-list) (2) - Add a computer to stock (linked-list) (3) - Display next order info (4) - Display all orders (5) - Add order to queue (6) Process the next order (7) - Reverse last order (8) - Display info of last order (9) - Update computer file (10) - Quit program 1 *Qn3_Sample_run - Notepad File Edit Format View Help 5 Please enter customer name: Peter Please enter name of Computer to order: Dell G10 Sorry, Computer Dell 610 is currently out of stock. Order not placed. What would you like to do? (1) Display the current stock (linked-list) (2) Add a computer to stock (linked-list) (3) - Display next order info (4) - Display all orders (5) - Add order to queue (6) Process the next order (7) Reverse last order (8) - Display info of last order (9) - Update computer file (10) - Quit program 5 Please enter customer name: Lilly Please enter name of Computer to order: Dell G7 Computer order for Dell G7 was successfully placed. What would you like to do? (1) Display the current stock (linked-list) (2) Add a computer to stock (linked-list) (3) - Display next order info (4) - Display all orders (5) Add order to queue (6) Process the next order (7) Reverse last order (8) - Display info of last order (9) - Update computer file (10) - Quit program 8 No orders have been processed. (2) *Qn3_Sample_run - Notepad File Edit Format View Help 8 No orders have been processed. What would you like to do? (1) - Display the current stock (linked-list) - Add a computer to stock (linked-list) (3) - Display next order info (4) - Display all orders (5) - Add order to queue (6) - Process the next order (7) - Reverse last order (8) - Display info of last order (9) - Update computer file (10) Quit program 3 1 NEXT ORDER 1 1 ID NAME Computer | 1 | Lilly | Dell G7 1 +- What would you like to do? (1) - Display the current stock (linked-list) (2) - Add a computer to stock (linked-list) (3) - Display next order info (4) - Display all orders (5) Add order to queue (6) - Process the next order (7) Reverse last order (8) - Display info of last order (9) - Update computer file (10) - Quit program 4 ALL ORDERS 1 ID 1 NAME Computer | 1 | Lilly | Dell G7 I + What would you like to do? (1) - Display the current stock (linked-list) (2) - Add a computer to stock (linked-list) (3) - Display next order info (4) Display all orders (5) - Add order to queue (6) - Process the next order (7) Reverse last order (8) - Display info of last order (9) Update computer file (10) Quit program 5 Please enter customer name: Alex Please enter name of Computer to order: Lenovo X1 Computer order for Lenovo X1 was successfully placed. What would you like to do? (1) - Display the current stock (linked-list) (2) - Add a computer to stock (linked-list) (3) Display next order info (4) - Display all orders (5) - Add order to queue (6) - Process the next order (7) Reverse last order (8) - Display info of last order (9) Update computer file (10) Quit program 3 *Qn3_Sample_run - Notepad File Edit Format View Help (9) Update computer file (10) - Quit program 4 | ALL ORDERS 1 | ID NAME Computer | | 1 | Lilly | Dell G7 I | 2 Alex | Lenovo X1 What would you like to do? (1) Display the current stock (linked-list) (2) - Add a computer to stock (linked-list) (3) - Display next order info (4) - Display all orders (5) Add order to queue (6) - Process the next order (7) Reverse last order (8) - Display info of last order (9) - Update computer file (10) - Quit program 1 | Computer Name | Acer Spin Asus Vivobook | Asus Zenbook Dell Alienware | Dell G7 | Dell Inspiron HP Pavilion HP Spectre | Lenova Yoga

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

What are the different techniques used in decision making?

Answered: 1 week ago

Question

2. Whats involved in listening?

Answered: 1 week ago

Question

1. How do listening and hearing diff er?

Answered: 1 week ago