Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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

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

More Books

Students also viewed these Databases questions

Question

What is a border case?

Answered: 1 week ago

Question

write a java program to build a posting and commenting system

Answered: 1 week ago

Question

What is focal length? Explain with a diagram and give an example.

Answered: 1 week ago

Question

What is physics and how does it apply in daily life?

Answered: 1 week ago