You are on page 1of 10

#include<iostream>

#include<string>
#include<fstream>
using namespace std;
class Vehicle
{
protected:
int model;
string reg;
int CubicCapacity;
int chasis_no;
string brand;
int seating_capacity;
string color;
bool AC;
int Rent_Per_Hour;
int Rent_Per_Kilo;
public:
Vehicle(){}
//Setters
void setModel(int m)
{
model = m;
}
void setreg(string r)
{
reg = r;
}
void setCubicCapacity(int cc)
{
CubicCapacity = cc;
}
void setChasis(int c)
{
chasis_no = c;
}
void setBrand(string b)
{
brand = b;
}
void SetSeating_capacity(int s)
{
seating_capacity = s;
}
void setColor(string c)
{
color = c;
}
void setAC(bool ac)
{
AC = ac;
}
void setRent_Hour(int hr)
{
Rent_Per_Hour = hr;
}
void setRent_Kilo(int kr)
{
Rent_Per_Kilo = kr;
}
//---------GETTER
int getModel()
{
return model;
}
int getCubicCapacity()
{
return CubicCapacity;
}
int getChasis()
{
return chasis_no;
}
string getColor()
{
return color;
}
string getReg()
{
return reg;
}
int getSeatingCapacity()
{
return seating_capacity;
}
string getBrand()
{
return brand;
}
bool getAC()
{
return AC;
}
int getRent_Hr()
{
return Rent_Per_Hour;
}
int getRent_Kilo()
{
return Rent_Per_Kilo;
}
virtual void RentSetting() = 0;

};
class Car :public Vehicle
{
public:
void RentSetting()
{
cout << "Enter Rent Per Hour for this vehilce" << endl;
cin >> Rent_Per_Hour;
cout << "Enter Rent Per Kilometer for this vehilce" << endl;
cin >> Rent_Per_Kilo;
ofstream out;
out.open("mainrent.txt");
out << endl;
out << Rent_Per_Hour;
out.close();
}

};
class Bike :public Vehicle
{
public:
void RentSetting()
{
cout << "Enter Rent Per Hour for this vehilce" << endl;
cin >> Rent_Per_Hour;
cout << "Enter Rent Per Kilometer for this vehilce" << endl;
cin >> Rent_Per_Kilo;
}

};
class Person
{
private:
int age;
string name;
string cnic;
string Lic_no;
public:
Car obj2;

Person()
{
}
void setAge(int a)
{
age = a;
}
void setName(string n)
{
name = n;
}
void setCnic(string c)
{
cnic = c;
}
void setLic_no(string l)
{
Lic_no = l;
}
int getAge()
{
return age;
}
string getCnic()
{
return cnic;
}
string getLic()
{
return Lic_no;
}
string getName()
{
return name;
}
};
class CarRentSystem
{
private:
Car C;
Bike B;
Person P;
public:
Car obj5;
CarRentSystem()
{

}
void mainMenu()
{
int rent;
int rrent;
bool check = false;
bool check2 = false;
cout <<
"--------------------------------------------------------------------------------"
<< endl;
string MSG = "\n======================( Welcome To Vehicle Rental
System )======================";
cout << MSG << endl;
int choice;
cout << endl;
cout <<
"--------------------------------------------------------------------------------"
<< endl;
cout << "Press 1 to Rent A Vehicle\n" << endl;
cout << "Press 2 to Enter a Vehicle\n" << endl;
cout << "Press 3 to view rental History" << endl;
cin >> choice;
if (choice == 1)
{
cout << "Press 1 for Bike\n" << endl;
cout << "Press 2 for Car" << endl;
int c;
cin >> c;
if (c == 1)
{
bool chk = false;
int chh;
string b;
string r;
bool AC1;
string Brand1;
int Chasis1;
string Color1;
int CubicCapacity1;
int Model1;
string Reg1;
cout << "Enter Brand of Bike\n" << endl;
cin >> b;
cout << "Enter reg# of Bike" << endl;
cin >> r;
ifstream in;
in.open("Bikes.txt");
while (!in.eof())
{
in >> AC1;
in >> Brand1;
in >> Chasis1;
in >> Color1;
in >> CubicCapacity1;
in >> Model1;
in >> Reg1;
if (Brand1 == b && Reg1 == r)
{
chk = true;
cout << "Bike Found...press 1 to Rent a Bike "
<< endl;
cin >> chh;
cout << "Enter Name of customer" << endl;
string na;
cin >> na;
P.setName(na);
cout << "Enter age of customer" << endl;
int aa;
cin >> aa;
P.setAge(aa);
cout << "Enter CNIC of customer" << endl;
string cnc;
cin >> cnc;
P.setCnic(cnc);
cout << "Enter Lic of customer" << endl;
string lic;
cin >> lic;
P.setLic_no(lic);
ofstream out;
out.open("rent.txt", ios::app);
out << endl;
out << b << endl;
out << r << endl;
out << P.getName() << endl;
out << P.getAge() << endl;
out << P.getCnic() << endl;
out << P.getLic();
cout << endl;
cout << "VEHICLE RENTED THANKS" << endl;
out.close();
break;
}
}
in.close();
if (chk == false)
{
cout << "Bike Not Found" << endl;
mainMenu();
}
else
mainMenu();

}
else if (c == 2)
{
{
bool chk = false;
int chh;
string b;
string r;
bool AC1;
string Brand1;
int Chasis1;
string Color1;
int CubicCapacity1;
int Model1;
string Reg1;
cout << "Enter Brand of Car\n" << endl;
cin >> b;
cout << "Enter reg# of Car" << endl;
cin >> r;
ifstream in;
in.open("Cars.txt");
while (!in.eof())
{
in >> AC1;
in >> Brand1;
in >> Chasis1;
in >> Color1;
in >> CubicCapacity1;
in >> Model1;
in >> Reg1;
if (Brand1 == b && Reg1 == r)
{
chk = true;
cout << "Car Found...press 1 to Rent a
Car" << endl;
cin >> chh;
cout << "Enter Name of customer" << endl;
string na;
cin >> na;
P.setName(na);
cout << "Enter age of customer" << endl;
int aa;
cin >> aa;
P.setAge(aa);
cout << "Enter CNIC of customer" << endl;
string cnc;
cin >> cnc;
P.setCnic(cnc);
cout << "Enter Lic of customer" << endl;
string lic;
cin >> lic;
P.setLic_no(lic);
ofstream out;
out.open("rent.txt", ios::app);
out << endl;
out << b << endl;
out << r << endl;
out << P.getName() << endl;
out << P.getAge() << endl;
out << P.getCnic() << endl;
out << P.getLic();
cout << endl;
cout << "VEHICLE RENTED THANKS" << endl;
out.close();
break;
}
}
in.close();
if (chk == false)
{
cout << "Car Not Found" << endl;
mainMenu();
}
else
mainMenu();

}
}

else if (choice == 2)
{
cout << "Press 1 for Bike\n" << endl;
cout << "Press 2 for Car" << endl;
int c;
cin >> c;
if (c == 1)
{
string b;
string re;
string cl;
int cuc;
int ch;
int mo;
int sc;
B.setAC(false);
cout << "Enter Brand of Bike" << endl;
cin >> b;
B.setBrand(b);
cout << "Enter Chasis number of Bike" << endl;
cin >> ch;
B.setChasis(ch);
cout << "Enter registration of Bike" << endl;
cin >> re;
B.setreg(re);
cout << "Enter color of Bike" << endl;
cin >> cl;
B.setColor(cl);
cout << "Enter Cubic Capacity of Bike" << endl;
cin >> cuc;
B.setCubicCapacity(cuc);
cout << "Enter model of Bike" << endl;
cin >> mo;
B.setModel(mo);
cout << "Enter Seating capacity of Bike" << endl;
cin >> sc;
B.SetSeating_capacity(sc);
B.RentSetting();
ofstream out;
out.open("Bikes.txt", ios::app);
out << endl;
out << B.getAC() << endl;
out << B.getBrand() << endl;
out << B.getChasis() << endl;
out << B.getColor() << endl;
out << B.getCubicCapacity() << endl;
out << B.getModel() << endl;
out << B.getReg() << endl;
out.close();
cout << "DATA SAVED" << endl;
mainMenu();
}
else if (c == 2)
{
string b;
string re;
string cl;
int cuc;
int ch;
int mo;
int sc;
C.setAC(true);
cout << "Enter Brand of Car" << endl;
cin >> b;
C.setBrand(b);
cout << "Enter Chasis number of Car" << endl;
cin >> ch;
C.setChasis(ch);
cout << "Enter registration of Car" << endl;
cin >> re;
C.setreg(re);
cout << "Enter color of Car" << endl;
cin >> cl;
C.setColor(cl);
cout << "Enter Cubic Capacity of Car" << endl;
cin >> cuc;
C.setCubicCapacity(cuc);
cout << "Enter model of Car" << endl;
cin >> mo;
C.setModel(mo);
cout << "Enter Seating capacity of Car" << endl;
cin >> sc;
C.SetSeating_capacity(sc);
C.RentSetting();
ofstream out;
out.open("Cars.txt", ios::app);
out << endl;
out << C.getAC() << endl;
out << C.getBrand() << endl;
out << C.getChasis() << endl;
out << C.getColor() << endl;
out << C.getCubicCapacity() << endl;
out << C.getModel() << endl;
out << C.getReg();
out.close();
ofstream out1;
out1.open("main.txt");
{
out1 << C.getBrand() << endl;
out1 << C.getModel() << endl;
}
out1.close();
cout << "DATA SAVED" << endl;
mainMenu();
}
else
{
cout << "INVALID CHOICE" << endl;
mainMenu();

}
}
else if (choice == 3)
{
string b2;
string r2;
string Name2;
int Age2;
string Cnic2;
string Lic2;
ifstream in;
in.open("rent.txt");
int i = 1;
while (!in.eof())
{
in >> b2;
in >> r2;
in >> Name2;
in >> Age2;
in >> Cnic2;
in >> Lic2;
cout << endl;
cout << "DATA OF RENTED VEHICLE NO. " << i << endl;
cout << "Brand of Vehilce" << endl;
cout << b2 << endl;
cout << "Reg of Vehicle" << endl;
cout << r2 << endl;
cout << "Name of Customer" << endl;
cout << Name2 << endl;
cout << "Age of Customer" << endl;
cout << Age2 << endl;
cout << "CNIC of Customer" << endl;
cout << Cnic2 << endl;
cout << "Licence Number of Customer" << endl;
cout << Lic2 << endl;
cout << endl;
i++;
}
in.close();
mainMenu();
}
else
{
cout << "INALID INPUT TRY AGAIN" << endl;
mainMenu();
}
}
};
void main()
{
CarRentSystem crs;
crs.mainMenu();
}

You might also like