Question: ***MUST BE DONE IN C PROGRAMMING LANGUAGE** Modify the given code to do the following Given Code project 8: // Program for a car dealership
***MUST BE DONE IN C PROGRAMMING LANGUAGE**
Modify the given code to do the following

Given Code project 8:
// Program for a car dealership to manage car inventory
#include
#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); int read_line(char str[], int n);
/********************************************************** * 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(" "); } } 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 "); }
int read_line(char str[], int n) { int ch, i = 0; while (isspace(ch = getchar())); str[i++] = ch; while ((ch = getchar()) != ' ') { if (i 1. (60 points) Modify Project 8 so that the program is split into three source files and two header files 1) Put all functions related to operations on the list of cars into car.c. 2) Create a header file named car.h that contains struct car declaration and prototypes for the functions in car.c. The header file should enclose the contents of the header file in an #1 fndef_#endif pair to protect the file, 3) Put the read line function in a separate file named readline.c 4) Create a header file named readline.h that contains a prototype for the read 1ine function. The header file should enclose the contents of the header file in an #ifndef-#endif pair to protect the file. 5) dealer.c contains the main function. 6) Include appropriate header files in the source files 2. (40 points) Write a makefile to build the program on student cluster. The makefile should contain the following rules: 1) Build readline.o by compiling readline.c 2) Build car.o by compiling car.c 3) Build dealer.o by compiling dealer.c 4) Build dealer by linking readline.o, car.o, and dealer.o Each rule should include the name of the target file, dependencies among files, and the command to be executed. The makefile should name the executable file for the program dealer
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
