Answer to Question #63100 in C for ranga

Question #63100
If there is a space to park the vechiles then some n number of vechiles are parked there and then count how many are of cars, and how many of are scooters and note the arrival time and the departure time, display the order of parked vechiles, and the color of vechile,if he wants to take the vehicle from the parking he has to tell the number of vehicle if the number is wrong he can’t able to take the vehicle from parking in that case he has to tell the car model and the color of vehicle and also the rc book of vehicle and also he has to calculate the parking fees based on time he kept.
1
Expert's answer
2019-11-06T09:23:17-0500
#include 
#include 

typedef struct {
	int hh; //hours
	int mm; //minutes
} time;

typedef struct {
	int number;
	char type[255]; 
	char color[255];
	char model[255];
	time arrival;
	time departure;
} vehicle;

time makeTime(int a, int b) {
	time res;
	res.hh = a, res.mm = b;
	
	return res;
}

vehicle readVehicle() {
	vehicle res;
	int a, b;
	char s[255];
	
	
	printf("Enter vehicles number: ");
	scanf("%d", &a);
	res.number = a;
	
	printf("Enter vehicles type: ");
	scanf("%s", &s);
	strcpy(res.type, s);
	
	printf("Enter vehicles color: ");
	scanf("%s", &s);
	strcpy(res.color, s);
	
	printf("Enter vehicles model: ");
	scanf("%s", &s);
	strcpy(res.model, s);
	
	printf("Enter arrival time: ");
	scanf("%d:%d", &a, &b);
	res.arrival = makeTime(a, b);
	
	printf("Enter departure time: ");
	scanf("%d:%d", &a, &b);
	res.departure = makeTime(a, b);
	
	return res;
}

void printVehicle(vehicle a) {
	printf("Vehicle number: %d. ", a.number);
	printf("Vehicle type: %s. ", a.type);
	printf("Vehicle color: %s. ", a.color);
	printf("Vehicle model: %s\n", a.model);
	
	printf("Arrival time: %d%d:%d%d. ", a.arrival.hh / 10, a.arrival.hh % 10, a.arrival.mm / 10, a.arrival.mm % 10);
	printf("Departure time: %d%d:%d%d\n", a.departure.hh / 10, a.departure.hh % 10, a.departure.mm / 10, a.departure.mm % 10);
}

int main() {
	int n, i, t;
	printf("Please, enter number of vehicles: ");
	scanf("%d", &n);
	
	vehicle *a = malloc(sizeof(vehicle)*n);
	
	for (i = 0; i < n; i++) {
 printf("Please, enter vehicle #%d: \n", i + 1);
 
 a[i] = readVehicle();
	}
	
	int numberOfCars = 0, numberOfScooters = 0;
	
	for (i = 0; i < n; i++) {
 printVehicle(a[i]);
 
 if (strcmp(a[i].type, "car") == 0) {
 numberOfCars++;
 }
 if (strcmp(a[i].type, "scooter") == 0) {
 numberOfScooters++;
 }
	}
	
	printf("Number of cars: %d. Number of scooters: %d\n", numberOfCars, numberOfScooters);
	
	return 0;
}

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
APPROVED BY CLIENTS