Project 3
Aim: The main aim of this Project to create a API for a store to manage it maintainance Data in a proper record. This Project will a store to maintain Maintainance history of each and every Vehicle they would be working.
//Header files
#include <iostream>
#include <string>
using namespace std;
// Enum for Car Type
enum class Type
{
PETROL,
DIESEL,
ELECTRIC
};
// Base Class Vehile
class Vehicle
{
protected://Protected Members
string vmake, vmodel;
int vyear;
int vodometer;
public://Public Member Function
Vehicle(string make, string model, int year, int odometer)// Constructor to assign the values
{
vmake = make;
vmodel = model;
vyear = year;
vodometer = odometer;
}
string getmake()// Get function to get the values
{
return vmake;
}
string getmodel()
{
return vmodel;
}
int getyear()
{
return vyear;
}
int getodometer()
{
return vodometer;
}
void setmake(string val)//set function to set the values
{
vmake = val;
}
void setmodel(string val)
{
vmodel = val;
}
void setyear(int val)
{
vyear = val;
}
void setododmeter(int val)
{
vodometer = val;
}
virtual Type getType() = 0;
void getCarInformation()// to displace the car information
{
cout << "Make: " << vmake << ", Model: " << vmodel << ", Year: " << vyear << ", Odometer: " << vodometer << endl;
}
void checkTireRotation()// to check the Tyre need rotation or not
{
int distance = vodometer - 50000;
if (distance >= 0)
{
cout << "Tire rotation advised." <<endl;
}
else
{
cout << "Tires are good to go." <<endl;
}
}
void oilChange()// to check oil change required or not
{
int val;
cout<<"Enter the Oil Level"<<endl;
cin>>val;
if(val<=1)
{cout<<endl<<"Oil Level is low"<<endl;}
else{cout<<"Oil Level is OK"<<endl;}
}
void checkPower()// check the Vehicle need to be Recharge or not
{
int distance = vodometer % 400;
if (distance == 0)
{
cout << "Battery recharge advised." <<endl;
}
else
{
cout << "Your vehicle is good to go." <<endl;
}
}
~Vehicle()// destructor
{
}
};
class Petrolcar: public Vehicle// Child class :Petrol
{
public:
Petrolcar(string make, string model, int year, int odometer) : Vehicle(make, model, year, odometer)
{}
Type getType() { return Type::PETROL; }
};
class Dieselcar: public Vehicle// Child class :Diesel
{
public:
Dieselcar(string make, string model, int year, int odometer) : Vehicle(make, model, year, odometer)
{}
Type getType() { return Type::DIESEL; }
};
class Electriccar: public Vehicle// Child class :Electric
{
public:
Electriccar(string make, string model, int year, int odometer) : Vehicle(make, model, year, odometer)
{}
Type getType() { return Type::ELECTRIC; }
void checkTireRotation() // to check the Tyre need rotation or not
{
int distance = vodometer - 50000;
if (distance >= 0)
{
cout << "Tire rotation advised." <<endl;
}
else
{
cout << "Tires are good to go." <<endl;
}
}
void checkPower() // check the Vehicle need to be Recharge or not
{
int distance = vodometer % 400;
if (distance == 0)
{
cout << "Battery recharge advised." <<endl;
}
else
{
cout << "Your vehicle is good to go." <<endl;
}
}
};
class Fuelvehicle: public Vehicle
{
Type getType() = 0;
};
int vcount = 0;
int main()// main Fuction or the driver Code
{
string make, model;
int year, odometer;
int choice;
int max = 10;
Vehicle *vec[max];
Vehicle *newVehicle;
do// loop start for repetative Menu
{
cout << "Menu:\n0. Quit.\n1. List inventory.\n2. Add vehicle.\n3. Update vehicle\n";
cout << "4. Remove vehicle.\n5. Tire rotation.\n6. Oil change.\n7. Recharge.\n ";
cout << "Enter your choice: ";
cin >> choice;
switch(choice)//start of switch case
{
case 0://Quit
cout << "Exiting program.\n";
break;
case 1://list Inventory
cout << "Inventory:\n";
for (int i = 0; i < vcount; ++i)
{
cout << (i + 1) << ". ";
vec[i]->getCarInformation();
}
break;
case 2:// Add Vehicle to the Existing List
{
cout << "Enter vehicle make: ";
cin >> make;
cout << "Enter vehicle model: ";
cin >> model;
cout << "Enter vehicle year: ";
cin >> year;
cout << "Enter vehicle odometer reading: ";
cin >> odometer;
cout << "Select type ""0 - Petrol, 1 - Diesel, 2 - Electric"": ";
int type;
cin >> type;
switch (type)
{
case 0:
newVehicle = new Petrolcar(make, model, year, odometer);
break;
case 1:
newVehicle = new Dieselcar(make, model, year, odometer);
break;
case 2:
newVehicle = new Electriccar(make, model, year, odometer);
break;
default:
cout << "Invalid type selection.\n";
continue;
}
if (vcount < max)
{
vec[vcount++] = newVehicle;
cout << "Vehicle added to inventory.\n";
}
else
{
cout << "Inventory is full. Cannot add more vehicles.\n";
}
break;
}
case 3:// To Update existing list
{
cout<<"enter the make of vechicle you need to update: "<<endl;
cin >>make;
for(int i=0;i<vcount;i++)
{
if(vec[i]->getmake()==make)
{
int selection;
cout<<"enter the parameter to be updated: 1. year\n2. odometer reading"<<endl;
cin >>selection;
if(selection==1)
{
int newyear = vec[i]->getyear();
vec[i]->setyear(newyear);
}
else
{
int newodometer = vec[i]->getodometer();
vec[i]->setododmeter(newodometer);
}
}
}
break;
}
case 4:// Delete Existing car
{
cout<<"enter the make of vechicle: "<<endl;
cin >>make;
for(int i=0;i<vcount;i++)
{
if(vec[i]->getmake()==make)
{ delete vec[i];}
}
break;
}
case 5:// for Tyre Rotation check
{
cout<<"enter the make of vechicle: "<<endl;
cin >>make;
for(int i=0;i<vcount;i++)
{
if(vec[i]->getmake()==make)
{ vec[i]->checkTireRotation();}
}
break;
}
case 6:// For Checking of OilChange
{
cout<<"enter the make of vechicle: "<<endl;
cin >>make;
for(int i=0;i<vcount;i++)
{
if(vec[i]->getmake()==make)
{ vec[i]->oilChange();}
}
break;
}
case 7:// for Poer check
{
cout<<"enter the make of vechicle: "<<endl;
cin >>make;
for(int i=0;i<vcount;i++)
{
if(bool(vec[i]->getmake()==make))
{ vec[i]->checkPower();}
}
break;
}
default:// Default case
cout << "Invalid choice. Please try again.\n";
}
}while (choice != 0);// End of Do-while Loop
}
// end of program