#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;
}
Comments
Leave a comment