Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Program A small car dealer would like to maintain information for the cars in stock. Each car was stored with the make and model,

C Program

A small car dealer would like to maintain information for the cars in stock. Each car was stored with the make and model, color, manufacture year, city mpg, highway mpg, and quantity. The C program dealer.c contains the car struct declaration, function prototypes, the main function, and the read_line function which is found below.

image text in transcribed

image text in transcribed

Complete the function definitions so it uses a dynamically allocated linked list to store the cars. The following functions should be completed:

1.) append_to_list: ask the user to enter a cars make, model, color, manufacture year, city mpg, highway mpg, and quantity(in that exact order), then add the car to the end of the linked list.

a.) It should check whether the car has already existed by make, model, color, and manufacture year. If so, the function should print a message and exit.

b.) If the car does not exist, allocate memory for the player, store the data, and append the car to the end of the linked list.

c.) If the list is empty, the function should return the pointer to the newly created car.

d.) Otherwise, add the car to the end of the linked list and return the pointer to the linked list.

2.) find_car: search by make and model, print the cars color, manufacture year, city mpg, highway mpg, and quantity. Print all cars that match the make and model. If the make and model is not found, print a message.

3.) printList: print the make, model, and manufacture year, and color of all the cars.

4.) clearList: when the user exists the program, all the memory allocated for the linked list should be deallocated.

Note: Use read_line function included in the program for reading in make, model and color.

+include include include #de fine LEN 30 struct carf 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 * *ente rs 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 listi g for quit.n") for (;) printf("Enter operation code:") scanf ( " %c" while (getchar ( ) != ' ') /* skips t , &code); end of line */ switch (code case 'a': carlist= appendtolist (carlist); case 'f': find car (car list) case 'p': printlist (car list); case 'g: clearList (car list) default: printf ("Illegal code ") ---- break break; break; return 0

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

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

List the causes of separation in an organisation.

Answered: 1 week ago