Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A car salesperson needs to keep track of all cars on a used carlot. The informat

ID: 3612887 • Letter: A

Question

A car salesperson needs to keep track of all cars on a used carlot.
The information he needs includes:
1. id
2. the type
3. seating capacity
4. price
5. colour of each car
Define a struct named Cars that will contain all of thesemembers.

In the main function:
a. Declare a struct array named carlot of the datatype Cars, maximum size is 10.
b. Read a given number of cars in the array carlot.
c. output specifications of one car.
d. delete a car in a given position.
e. insert a new car in the top of the array (position=0).

Explanation / Answer

#include <stdio.h> { //declaring a variable for later use int i , n , j ,k ,pos; //declaring a structure of car struct car{ int id; char cartype; int seat_capacity; float price; char color; } //declaring the array of structures question a. struct car carlot[10]; printf("enter the specification for cars"); //to inform the user what values should be entered printf("enter car id,cartype,seatcapacity,price,color"); //i is less than 10 because the size of carlot is 10 //question b to read 10 item for(i=0 ; i< 10 ; i++) scanf("%d %s %d %f %s",&carlot[i].id,&carlot[i].cartype, &carlot[i].seatcapacity,&carlot[i].price, &carlot[i].color); //question c to print the details of 1 car printf("enter the id of a particular car to read itsdetail"); scanf("%d",&n); //comparing the values of n with the ids of allca rs for(j=0 ; j<= 10 ; j++) { if(carlot[j].id == n) printf("%d%s%d%f%s",carlot[n].id,carlot[n].cartype,carlot[n].seatcapacity,carlot[n].price,carlot[n].color); } //que d to delete a car in a given pos //eneter the positin of the car through m printf("enter the positin of the car"); scanf("%d", &pos); for( k = pos ; k<= 10; k++) { carlot[k-1] = carlot[k] ; carlot[k-1]=0; } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote