Question: **MUST BE DONE IN C PROGRAMMING LANGUAGE*** Please modify the code below to do the following Given code: dealer.c -------------- // Program for a car

**MUST BE DONE IN C PROGRAMMING LANGUAGE***

Please modify the code below to do the following

**MUST BE DONE IN C PROGRAMMING LANGUAGE*** Please modify the code below

Given code:

dealer.c

--------------

// Program for a car dealership to manage car inventory #include #include "car.h" /********************************************************** * main: Prompts the user to enter an operation code, * * then calls a function to perform the requested * * action. Repeats until the user enters the * * command 'q'. Prints an error message if the user * * enters an illegal code. * **********************************************************/ int main(void) { char code; struct car *car_list = NULL; printf("Operation Code: a for appending to the list, f for finding a car" ", p for printing the list; q for quit. "); for (;;) { printf("Enter operation code: "); scanf(" %c", &code); while (getchar() != ' ') /* skips to end of line */ ; switch (code) { case 'a': car_list = append_to_list(car_list); break; case 'f': find_car(car_list); break; case 'p': printList(car_list); break; case 'q': clearList(car_list); return 0; default: printf("Illegal code "); } printf(" "); } }

readline.c

-------------------

#include #include "readline.h" #include int read_line(char str[], int n) { int ch, i = 0; while (isspace(ch = getchar())); str[i++] = ch; while ((ch = getchar()) != ' ') { if (i

car.c

-----------------

#include #include "car.h" #include "readline.h" #include #include struct car *append_to_list(struct car *list){ struct car* newCar = (struct car*)malloc(sizeof(struct car)); newCar->next = NULL; printf("Enter Car Manufacturer : "); read_line(newCar->make, LEN); printf("Enter Model: "); read_line(newCar->model, LEN); printf("Enter Color: "); read_line(newCar->color, LEN); printf("Enter year: "); scanf("%d", &newCar->year); printf("Enter City MPG: "); scanf("%d", &newCar->city_mpg); printf("Enter Highway MPG: "); scanf("%d", &newCar->highway_mpg); printf("Enter Quantity: "); scanf("%d", &newCar->quantity); if(list == NULL) { return newCar; } else { struct car* ptr = list; while(1) { if( (strcmp(ptr->make, newCar->make)==0) && (strcmp(ptr->model, newCar->model)==0) && (strcmp(ptr->color, newCar->color)==0) && (ptr->year == newCar->year) && (ptr->city_mpg == newCar->city_mpg) && (ptr->highway_mpg == newCar->highway_mpg) && (ptr->quantity == newCar->quantity) ) { printf("Car already exists in the list. "); return list; } if(ptr->next != NULL) { ptr = ptr->next; } else { break; } } ptr->next = newCar; return list; } return NULL; } void find_car(struct car * list) { char userModel[LEN+1], userMake[LEN+1]; printf("Enter make to search for: "); read_line(userMake, LEN); printf("Enter model to search for: "); read_line(userModel, LEN); int found = 0; struct car* ptr = list; while(ptr != NULL) { if( (strcmp(ptr->make, userMake)==0) && (strcmp(ptr->model, userModel)==0) ) { struct car *c = ptr; printf("Car Model: %s, Make: %s, Color: %s, Year: %d, quantity: %d ", c->model, c->make, c->color, c->year, c->quantity); found = 1; } ptr = ptr->next; } if(!found) { printf("No matching car found. "); } }

void printList(struct car *list) { struct car* ptr = list; while(ptr != NULL) { struct car *c = ptr; printf("Car Model: %s, Make: %s, Color: %s, Year: %d, quantity: %d", c->model, c->make, c->color, c->year, c->quantity); ptr = ptr->next; } } void clearList(struct car *list) { struct car* ptr = list; while(ptr != NULL) { struct car *c = ptr; ptr = ptr->next; free(c); } printf("List cleared "); }

readline.h

-----------------------

#ifndef READLINE_H_INCLUDED #define READLINE_H_INCLUDED int read_line(char str[], int n); #endif // READLINE_H_INCLUDED

car.h

---------------

#ifndef CAR_H_INCLUDED #define CAR_H_INCLUDED #define LEN 30 struct car{ char make[LEN+1]; char model[LEN+1]; char color[LEN+1]; int year; int city_mpg; int highway_mpg; int quantity; struct car *next; }; struct car *append_to_list(struct car *list); void find_car(struct car *list); void printList(struct car *list); void clearList(struct car *list); #endif // CAR_H_INCLUDED

1. (70 points) Modify project 9 by adding and modifying the following functions: 1) Add a delete function in caar.c that delete a car from the list. The function should delete a player by the car's make, model, color, and manufacture year. These information will be entered by the user. The function should have the following prototype: struct car* delete_from_list (struct car 'list) You will also need to add the function prototype to the header file; modify the main function in dealer.c to add 'd' for delete option in the menu and it calls the delete function when the d' option is selected 2) Modify the append to_list function so the car is inserted into an ordered list (by make, then model) and the list remains ordered after the insertion. For example, ford escape should be before ford taurus in the list ford taurus should be before jeep wrangler in the list; if the make and model are the same, the car entries do not need to be ordered by other members

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!