Project 3
#include <stdio.h>
#include <stdlib.h>
typedef enum {
GAS,
DIESEL,
ELECTRIC
} FuelType;
typedef struct {
char make[20];
char model[20];
int year;
int odometer;
} Vehicle;
typedef struct {
Vehicle vehicle;
FuelType fuelType;
} GasCar;
typedef struct {
Vehicle vehicle;
FuelType fuelType;
} DieselCar;
typedef struct {
Vehicle vehicle;
FuelType fuelType;
} ElectricCar;
FuelType getType(Vehicle *vehicle) {
// This is a virtual function implementation
// You can customize the logic for each car type
if (vehicle->fuelType == GAS) {
return GAS;
} else if (vehicle->fuelType == DIESEL) {
return DIESEL;
} else {
return ELECTRIC;
}
}
void checkTireRotation(Vehicle *vehicle) {
// Check if tire rotation is needed based on odometer reading
if (vehicle->odometer % 50000 == 0) {
printf("Tire rotation needed for %s %s\n", vehicle->make, vehicle->model);
} else {
printf("Tire rotation not needed for %s %s\n", vehicle->make, vehicle->model);
}
}
void checkPower(Vehicle *vehicle) {
// Check if power recharge is needed based on odometer reading
if (vehicle->odometer % 400 == 0) {
printf("Power recharge needed for %s %s\n", vehicle->make, vehicle->model);
} else {
printf("Power recharge not needed for %s %s\n", vehicle->make, vehicle->model);
}
}
int main() {
Vehicle vehicle1 = { "Toyota", "Camry", 2022, 50000 };
Vehicle vehicle2 = { "Ford", "Mustang", 2020, 100000 };
GasCar gasCar1 = { vehicle1, GAS };
DieselCar dieselCar1 = { vehicle2, DIESEL };
FuelType fuelType1 = getType(&gasCar1.vehicle);
FuelType fuelType2 = getType(&dieselCar1.vehicle);
printf("Vehicle 1 Fuel Type: %d\n", fuelType1);
printf("Vehicle 2 Fuel Type: %d\n", fuelType2);
checkTireRotation(&vehicle1);
checkPower(&vehicle2);
return 0;
}