Linux Code
Linux Code
Linux Code
#include <vector>
#include <fstream>
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 show();
};
vector<Vehicle> veh(100);
fstream file;
void Vehicle::addVehicle()
cout << "Enter vehicle type (1 for Car/2 for Bike): ";
cout << "Enter arrival time in hours, minutes, and seconds: ";
cin >> v->arrive.hh >> v->arrive.col1 >> v->arrive.mm >> v->arrive.col2 >> v->arrive.ss;
veh.at(i).pltno = v->pltno;
veh.at(i).type = v->type;
veh.at(i).arrive.hh = v->arrive.hh;
veh.at(i).arrive.mm = v->arrive.mm;
veh.at(i).arrive.ss = v->arrive.ss;
veh.at(i).dt.day = v->dt.day;
veh.at(i).dt.month = v->dt.month;
veh.at(i).dt.year = v->dt.year;
i++;
totalVehicle++;
if (v->type == 1) {
totalCar++;
else {
totalBike++;
Time t3;
return t3.hh;
void Vehicle::deleteVehicle()
string pno;
int typ;
Time depart;
int timeDiff;
int charge = 0;
cout << "Enter vehicle type (1 for Car/2 for Bike): ";
cout << "Enter departure time in hours, minutes, and seconds: ";
cin >> depart.hh >> depart.col1 >> depart.mm >> depart.col2 >> depart.ss;
veh.at(j).departure.hh = depart.hh;
veh.at(j).departure.mm = depart.mm;
veh.at(j).departure.ss = depart.ss;
if (veh.at(j).type == 1) {
totalCar--;
if (timeDiff < 2) {
charge = 20;
else {
charge = 40;
else {
charge = 50;
else {
totalBike--;
if (timeDiff < 2) {
charge = 5;
else {
charge = 10;
else {
charge = 20;
cout << "\nVehicle having vehicle number: " << veh.at(j).pltno << " has left the parking after
paying Rs. " << charge << endl;
file.open("parkingDatabase.dat", ios::app);
if (!file) {
exit(1);
}
file << veh.at(j).type << "\t\t\t" << veh.at(j).pltno << "\t\t\t" << veh.at(j).dt.day << "/" <<
veh.at(j).dt.month << "/" << veh.at(j).dt.year << "\t\t\t" << veh.at(j).arrive.hh << ":" <<
veh.at(j).arrive.mm << ":" << veh.at(j).arrive.ss << "\t\t\t" << veh.at(j).departure.hh << ":" <<
veh.at(j).departure.mm << ":" << veh.at(j).departure.ss << endl;
file.close();
veh.erase(veh.begin() + j);
i--;
totalVehicle--;
break;
if (j == i) {
deleteVehicle();
void Vehicle::printVehicle(Vehicle v)
cout << v.type << "\t\t\t" << v.pltno << "\t\t\t" << v.dt.day << "/" << v.dt.month << "/" << v.dt.year <<
"\t\t\t" << v.arrive.hh << ":" << v.arrive.mm << ":" << v.arrive.ss << endl;
}
void Vehicle::show()
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 << " VEHICLE PARKING SYSTEM USING SEQUENTIAL FILE APPROACH " << endl;
switch (choice) {
case 1:
system("clear");
veh.at(i).addVehicle();
break;
case 2:
system("clear");
totalVehicles();
break;
case 3:
system("clear");
veh.at(i).deleteVehicle();
break;
case 4:
system("clear");
totalAmount();
break;
case 5:
system("clear");
veh.at(i).show();
break;
case 6:
exit(0);
if (ans == 'n') {
break;
else {
continue;
}
} while (true);
return 0;