Answer to Question #284817 in C for laith

Question #284817

Write a C program that does the following: a. Declare a structure called Car with the following members: Price (float), Year (int), Color (String) and Brand (String). b. Ask the user to enter the information of 10 cars and save them in an array called CARS. c. Print the color of the car(s) that has (have) a price greater than 15000. d. Write a function called oldestCar that takes the array CARS as an argument and returns the oldest car among all cars. e. In the main, call the function oldestCar and print all information of the oldest car.


1
Expert's answer
2022-01-04T16:22:49-0500
#include<conio.h>
#include<stdio.h>



/*
	Write a C program that does the following: 
	a. Declare a structure called Car with the following members: 
		Price (float), Year (int), Color (String) and Brand (String). 
	b. Ask the user to enter the information of 10 cars and save them in an array called CARS. 
	c. Print the color of the car(s) that has (have) a price greater than 15000. 
	d. Write a function called oldestCar that takes the array CARS as an argument and returns the oldest car among all cars.
	e. In the main, call the function oldestCar and print all information of the oldest car.
*/


#define NO_OF_CARS	10


struct Car
{
	float Price;
	int Year;
	char Color[10];
	char Brand[10];	
};


void OldestCar(Car *C, int N)
{
	int Oldest,n,ind;
	Oldest = C[0].Year;
	for(n=0;n<N;n++)
	{
		if(Oldest>=C[n].Year) {Oldest=C[n].Year; ind = n;}
	}
	printf("\n\tOldest Car: ");
	printf("\n\tYear : %d",C[ind].Year);
	printf("\n\tPrice: %.2f",C[ind].Price);
	printf("\n\tBrand: %s",C[ind].Brand);
	printf("\n\tColor: %s",C[ind].Color);
}




int main()
{
	struct Car CARS[NO_OF_CARS];
	int n;
	
	for(n=0;n<NO_OF_CARS;n++)
	{
		CARS[n].Price=10000+n*1000;
		CARS[n].Year = n+2000;
		sprintf(CARS[n].Color,"%s","WHITE");
		sprintf(CARS[n].Brand,"%s","BMW");
	}
	
	OldestCar(&CARS[0],NO_OF_CARS);


	printf("\n\n\tColor of Cars having price more than 15000...")	;
	for(n=0;n<NO_OF_CARS;n++)
	{
		if(CARS[n].Price>15000)
		{
			printf("\n\tYear : %d\t%.2f\t%s\t%s",CARS[n].Year,CARS[n].Price,CARS[n].Brand,CARS[n].Color);
		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS