#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
struct Time {
int hh;
int mm;
int ss;
char col1;
char col2;
};
struct Date {
int day;
int month;
int year;
char sym1;
char sym2;
};
class Vehicle {
string pltno;
int type;
Date dt;
Time arrive;
Time departure;
public:
void addVehicle();
void deleteVehicle();
void printVehicle(Vehicle v);
void show();
};
vector<Vehicle> veh(100);
int static totalVehicle = 0, totalCar = 0, totalBike = 0, totalAmt = 0, i = 0;
fstream file;
void Vehicle::addVehicle()
Vehicle* v = new Vehicle;
cout << "Enter vehicle type (1 for Car/2 for Bike): ";
cin >> v->type;
cout << "Enter vehicle number: ";
cin >> v->pltno;
cout << "Enter arrival time in hours, minutes, and seconds: ";
cin >> v->[Link] >> v->arrive.col1 >> v->[Link] >> v->arrive.col2 >> v->[Link];
cout << "Enter date in day, month, and year: ";
cin >> v->[Link] >> v->dt.sym1 >> v->[Link] >> v->dt.sym2 >> v->[Link];
[Link](i).pltno = v->pltno;
[Link](i).type = v->type;
[Link](i).[Link] = v->[Link];
[Link](i).[Link] = v->[Link];
[Link](i).[Link] = v->[Link];
[Link](i).[Link] = v->[Link];
[Link](i).[Link] = v->[Link];
[Link](i).[Link] = v->[Link];
i++;
totalVehicle++;
if (v->type == 1) {
totalCar++;
else {
totalBike++;
cout << "\nVehicle added successfully" << endl;
int computeTimeDifference(Time t1, Time t2)
{
int sec1, sec2, totalSec;
Time t3;
sec1 = [Link] * 60 * 60 + [Link] * 60 + [Link];
sec2 = [Link] * 60 * 60 + [Link] * 60 + [Link];
totalSec = sec2 - sec1;
[Link] = totalSec / 60;
[Link] = [Link] / 60;
[Link] = [Link] % 60;
[Link] = totalSec % 60;
return [Link];
void Vehicle::deleteVehicle()
string pno;
int typ;
Time depart;
int timeDiff;
int charge = 0;
cout << "Enter vehicle type (1 for Car/2 for Bike): ";
cin >> typ;
cout << "Enter vehicle number: ";
cin >> pno;
cout << "Enter departure time in hours, minutes, and seconds: ";
cin >> [Link] >> depart.col1 >> [Link] >> depart.col2 >> [Link];
for (int j = 0; j <= i; j++) {
if (([Link](j).pltno == pno) && ([Link](j).type == typ)) {
[Link](j).[Link] = [Link];
[Link](j).[Link] = [Link];
[Link](j).[Link] = [Link];
timeDiff = computeTimeDifference([Link](j).arrive, depart);
if ([Link](j).type == 1) {
totalCar--;
if (timeDiff < 2) {
charge = 20;
else {
if ((timeDiff > 2) && (timeDiff < 5)) {
charge = 40;
else {
charge = 50;
else {
totalBike--;
if (timeDiff < 2) {
charge = 5;
else {
if ((timeDiff > 2) && (timeDiff < 5)) {
charge = 10;
else {
charge = 20;
cout << "\nVehicle having vehicle number: " << [Link](j).pltno << " has left the parking after
paying Rs. " << charge << endl;
[Link]("[Link]", ios::app);
if (!file) {
cerr << "Error: file could not be opened" << endl;
exit(1);
}
file << [Link](j).type << "\t\t\t" << [Link](j).pltno << "\t\t\t" << [Link](j).[Link] << "/" <<
[Link](j).[Link] << "/" << [Link](j).[Link] << "\t\t\t" << [Link](j).[Link] << ":" <<
[Link](j).[Link] << ":" << [Link](j).[Link] << "\t\t\t" << [Link](j).[Link] << ":" <<
[Link](j).[Link] << ":" << [Link](j).[Link] << endl;
[Link]();
[Link]([Link]() + j);
i--;
totalVehicle--;
totalAmt = totalAmt + charge;
break;
if (j == i) {
cout << "\nWrong Entry, Try Again" << endl;
cout << "Departure: " << endl;
deleteVehicle();
void Vehicle::printVehicle(Vehicle v)
cout << [Link] << "\t\t\t" << [Link] << "\t\t\t" << [Link] << "/" << [Link] << "/" << [Link] <<
"\t\t\t" << [Link] << ":" << [Link] << ":" << [Link] << endl;
}
void Vehicle::show()
cout << "Vehicle Type\t\tVehicle Number\t\t\tDate\t\t\tArrival Time" << endl;
for (int j = 0; j < i; j++) {
printVehicle(veh[j]);
void totalVehicles()
cout << "Total number of vehicles parked: " << totalVehicle << endl;
cout << "Total number of cars parked: " << totalCar << endl;
cout << "Total number of bikes parked: " << totalBike << endl;
void totalAmount()
cout << "Total collection till now: " << totalAmt << endl;
int main()
int choice;
char ans;
do {
system("clear");
cout << "********************************************************************" <<
endl;
cout << " VEHICLE PARKING SYSTEM USING SEQUENTIAL FILE APPROACH " << endl;
cout << "1. Arrival of a vehicle" << endl
<< "2. Total number of vehicles parked" << endl
<< "3. Departure of vehicle" << endl
<< "4. Total amount collected" << endl
<< "5. Display" << endl
<< "6. Exit" << endl
<< "********************************************************************" << endl
<< "Enter your Choice: ";
cin >> choice;
switch (choice) {
case 1:
system("clear");
cout << "Add: " << endl;
[Link](i).addVehicle();
break;
case 2:
system("clear");
totalVehicles();
break;
case 3:
system("clear");
cout << "Departure: " << endl;
[Link](i).deleteVehicle();
break;
case 4:
system("clear");
totalAmount();
break;
case 5:
system("clear");
[Link](i).show();
break;
case 6:
exit(0);
cout << "\nDo you want to continue? (y/n): ";
cin >> ans;
if (ans == 'n') {
break;
else {
continue;
}
} while (true);
return 0;