Challenge

Project 3

/*
* project2.c++
*
* Created on: 16-Mar-2023
* Author: Pankaj
*/

#include //header file
using namespace std;

enum Type
{
GAS,
DIESEL,
ELECTRIC
};
class Vehicle {
protected: //protected members
string make, model;
int year, odometer;
Type type;
public: //public members
Vehicle() { //constructors

cout << "Enter the vehicle type (0 for GAS, 1 for DIESEL, 2 for ELECTRIC): "; //for retriving the information from the users
int t;
cin >> t;
type = static_cast(t);

cout << "Enter the make of the vehicle: ";
cin >> make;

cout << "Enter the model of the vehicle: ";
cin >> model;

cout << "Enter the manufacturing year of the vehicle: ";
cin >> year;

cout << "Enter the odometer reading of the vehicle: ";
cin >> odometer;


}
};

class Service : public Vehicle { //derived class
protected: //protected class
int tire_remaining, battery_remaining;
public: //public members
Service() { //constructor
tire_remaining = 50000 - odometer;
battery_remaining = 400 - odometer;
}

void check_tire_rotation() { //function for checking tire rotation
cout << "Tire rotation information: " << endl;
if (odometer >= 50000) {
cout << "The tires need to be changed as their lifetime is over." << endl;
}
else {
cout << "The tires are in good condition. After " << tire_remaining << " kms, they will need to be changed." << endl;
}
}

void check_charger_power() { //function for checking battery charge
cout << "Battery information: " << endl;
if (odometer >= 400) {
cout << "The battery needs to be changed." << endl;
}
else {
cout << "The battery is in good condition. After " << battery_remaining << " kms, it will need to be changed." << endl;
}
}

void check_oil() { //function for checking battery charge
cout << "Vehicle oil information: " << endl;
if (odometer >= 10000) {
cout << "The oil needs to be changed." << endl;
}
else {
cout << "The oil is in good condition. After 10000kms, it will need to be changed." << endl;
}
}
};

class Vehicle_info : public Vehicle //derived class
{
protected: //protected members
int customer_vehicle_type;
public: //public members
Vehicle_info() //constructor
{
cout << "Enter the customer's vehicle type (0 for GAS, 1 for DIESEL, 2 for ELECTRIC): ";
cin >> customer_vehicle_type;
}

void print_vehicle_info() //function for printing vehicle info
{
switch (customer_vehicle_type) {
case GAS:
cout << "This vehicle runs on liquefied gas." << endl;
break;
case DIESEL:
cout << "This vehicle runs on liquid petroleum." << endl;
break;
case ELECTRIC:
cout << "This vehicle runs on rechargeable battery." << endl;
break;
default:
cout << "Invalid vehicle type selected." << endl;
break;
}
}
};

int main()
{
Service s; //object created
Vehicle_info vi;
int choice;
cout << "Enter the choice of service (1 to 4): ";
cin >> choice;
switch (choice)
{
case 1:
vi.print_vehicle_info();
break;
case 2:
s.check_tire_rotation();
break;
case 3:
s.check_oil();
break;
case 4:
s.check_charger_power();
break;
default:
cout<<"Invalid selection"<}
}

 OUTPUT :-  Enter the vehicle type (0 for GAS, 1 for DIESEL, 2 for ELECTRIC): 1
Enter the make of the vehicle: 2015
Enter the model of the vehicle: Vdi
Enter the manufacturing year of the vehicle: 2018
Enter the odometer reading of the vehicle: 25468
Enter the vehicle type (0 for GAS, 1 for DIESEL, 2 for ELECTRIC): 2
Enter the make of the vehicle: 2015
Enter the model of the vehicle: vdi
Enter the manufacturing year of the vehicle: 2018
Enter the odometer reading of the vehicle: 88546
Enter the customer's vehicle type (0 for GAS, 1 for DIESEL, 2 for ELECTRIC): 2
Enter the choice of service (1 to 4): 2
Tire rotation information:
The tires are in good condition. After 24532 kms, they will need to be changed.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.