Question
Please use C: This project is an exercise in linked lists. It will allow the user to order a number of pizzas and then place
Please use C:
This project is an exercise in linked lists. It will allow the user to order a number of pizzas and then place them in a delivery list. The program will ask the user if he or she wishes a new pizza. If the user answers yes the program will ask for toppings. When the toppings have all been entered the pizza will be placed in a delivery list. When the user has finished ordering pizzas, the pizzas in the delivery list will be displayed in reverse order from the order in which they were entered. Running the program may look like:
djn@djn-ThinkPad-T410 ~/classes/cs $ pizza new pizza? (y/n) y toppings for new pizza: topping: mushrooms topping: pepperoni topping: extra cheese topping: new pizza? (y/n) x try again new pizza? (y/n) y toppings for new pizza: topping: pepperoni topping: green pepper topping: new pizza? (y/n) y toppings for new pizza: topping: ice cream topping: ketchup topping: whipped cream topping: new pizza? (y/n) n deliveries: pizza 1 has 3 topping(s) ice cream ketchup whipped cream pizza 2 has 2 topping(s) green pepper pepperoni pizza 3 has 3 topping(s) extra cheese mushrooms pepperoni djn@djn-ThinkPad-T410 ~/classes/cs $
The program will represent pizzas as a set of strings, a string for each topping. Sets, in turn, will be represented as linked lists. When a pizza has been ordered it will be placed into another linked list -- a list of sets.
Sets
A set of strings will be represented by a struct:
typedef struct { node *head; int count; } set;
where node is defined as
typedef struct node { char *data; struct node *next; } node;
You will provide functions to operate on sets:
set *createset(). Creates (with dmalloc() -- see below) a set, initializes its fields and returns a pointer to the set. int insert(char *str, set *s). Places a new string in the set by inserting a new node into its linked list and increments count. The toppings will be inserted into the pizza set in alphabetical order (use strcmpi() below for this). Duplicate strings (ignoring case) will not be allowed in the set. Returns whether the insertion was successful. void printset(set *s). Displays the elements of the set with each string on a new line.
The code for these functions will be placed in a file set_
You will also want to add some more functions to set_
/* compares strings for alphabetical ordering */ int strcmpi(char *s, char *t) { while (*s && tolower(*s) == tolower(*t)) { s++; t++; } return tolower(*s) - tolower(*t); } /* allocates memory with a check for successful allocation */ void *dmalloc(int size) { void *p = malloc(size); if (!p) { printf("memory allocation failed "); exit(1); } return p; }
You must always check the pointer returned by malloc() for successful memory allocation. In your program use the dmalloc() function above in place of malloc() to ensure that this is always done. You may also find it convenient to write a function char *stringcopy(char *s) which creates (with dmalloc()) a copy of the string parameter.
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