0% found this document useful (0 votes)
37 views

Linux Code

This C++ program implements a vehicle parking system using classes, structures, and vectors. It allows users to add and remove vehicles from the parking system, view totals of parked vehicles and collected fees, and output the vehicle data. Key features include classes for Vehicle, Date, and Time, vectors to store vehicle objects, and functions for input/output, calculations, and menu display.

Uploaded by

Speed Up
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Linux Code

This C++ program implements a vehicle parking system using classes, structures, and vectors. It allows users to add and remove vehicles from the parking system, view totals of parked vehicles and collected fees, and output the vehicle data. Key features include classes for Vehicle, Date, and Time, vectors to store vehicle objects, and functions for input/output, calculations, and menu display.

Uploaded by

Speed Up
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

#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->arrive.hh >> v->arrive.col1 >> v->arrive.mm >> v->arrive.col2 >> v->arrive.ss;

cout << "Enter date in day, month, and year: ";


cin >> v->dt.day >> v->dt.sym1 >> v->dt.month >> v->dt.sym2 >> v->dt.year;

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++;

cout << "\nVehicle added successfully" << endl;

int computeTimeDifference(Time t1, Time t2)


{

int sec1, sec2, totalSec;

Time t3;

sec1 = t1.hh * 60 * 60 + t1.mm * 60 + t1.ss;

sec2 = t2.hh * 60 * 60 + t2.mm * 60 + t2.ss;

totalSec = sec2 - sec1;

t3.mm = totalSec / 60;

t3.hh = t3.mm / 60;

t3.mm = t3.mm % 60;

t3.ss = totalSec % 60;

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): ";

cin >> typ;

cout << "Enter vehicle number: ";

cin >> pno;

cout << "Enter departure time in hours, minutes, and seconds: ";

cin >> depart.hh >> depart.col1 >> depart.mm >> depart.col2 >> depart.ss;

for (int j = 0; j <= i; j++) {

if ((veh.at(j).pltno == pno) && (veh.at(j).type == typ)) {

veh.at(j).departure.hh = depart.hh;

veh.at(j).departure.mm = depart.mm;

veh.at(j).departure.ss = depart.ss;

timeDiff = computeTimeDifference(veh.at(j).arrive, depart);

if (veh.at(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: " << veh.at(j).pltno << " has left the parking after
paying Rs. " << charge << endl;

file.open("parkingDatabase.dat", ios::app);

if (!file) {

cerr << "Error: file could not be opened" << endl;

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--;

totalAmt = totalAmt + charge;

break;

if (j == i) {

cout << "\nWrong Entry, Try Again" << endl;

cout << "Departure: " << endl;

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()

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;

veh.at(i).addVehicle();

break;

case 2:

system("clear");

totalVehicles();

break;

case 3:
system("clear");

cout << "Departure: " << endl;

veh.at(i).deleteVehicle();

break;

case 4:

system("clear");

totalAmount();

break;

case 5:

system("clear");

veh.at(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;

You might also like