Question: Page 5 Problem 4 (40 points): Dynamic Allocation and I/O Now it's time to help the local cafes by writing some software to keep track

 Page 5 Problem 4 (40 points): Dynamic Allocation and I/O Now

Page 5 Problem 4 (40 points): Dynamic Allocation and I/O Now it's time to help the local cafes by writing some software to keep track of orders, tabulate bills, and store customer orders into files. A customer is represented as a doubly-linked list of customer_ts. The head node is a sentinel, and other nodes in the list record an item number and the quantity of that item. The structure is defined as follows: typedef struct customer t customer_t: struct customer_t customer t next; // the next customer t in the list customer to prov: 17 the previous customer t in the list int item num; 1/ which item was ordered int quantity; 1/ how many of the item were ordered 1. (15 points) Start by writing a function to add a new order to a customer, as shown below. The argumenta points to the sentinel for the customer, the argument num is the item number to be ordered, and the argument qty gives the number of that item to order. If the customer has already ordered an item of type num, the quantity aty must be added to the matching list element's quantity field, after which the function should return 1. Otherwise, the function must dynamically allocate a new customer_t (return 0 if allocation fails), fill it in appropriately with the item number and the quantity, add the new customer into the list, and return 1. int goi_mon (customer_t* c, int num, int qty) customer to one; for (one - c->next; c!- one; one - one->next) { if (num - one->item_num) { go aty == one - guontity, TEE 10 if (NULL -- one) { return 0; one->quantity - qty

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!