Anda di halaman 1dari 21

// DESCRIPTION: It tells how to accommodate the vehicles of student, faculty and staff in the

university parking area.

//******************************************UET PARKING
SYSTEM******************************************
//*****HEADER FILES*****
#include "stdafx.h"
#include<iostream>
#include<conio.h>
#include<windows.h>
using namespace std;
#include<string>

class vehicle
{
protected:
int reg_no;
public:
void setreg(int r)
{
reg_no = r;
}

int getreg()
{
return reg_no;
}
};

class stakeholders
{
protected:
string name;

float balance;

public:
vehicle car;
virtual void setbalance()
{
}
virtual void set()
{
}
};

class student :public stakeholders


{
public:

vehicle getcar()
{
return car;
}

bool checkdues()
{
if (balance>10)
{
return true;
}

else
return false;
}

float getdues()
{
return balance;

void set(float q)
{
balance = q;
}

void increment(int x)
{
balance = balance + x;
cout << "Your new balance is " << balance << endl;
}

void setbalance(float d)
{
balance = balance - d;

cout << "Your remaining balance is " << balance << endl;
}
};

class staff :public stakeholders


{
protected:
int grade;

public:

void setgrade(int g)
{
grade = g;
}

int getgrade()
{
return grade;
}

void set(float q)
{
balance = q;
}

int getbalance()
{
return balance;
}

void setbalance(float d)
{
balance = balance - d;

cout << "Your remaining balance is " << balance << endl;
}

bool checkgrade()
{
if (grade >= 14)
{
return true;
}

else
return false;
}

vehicle getcar()
{
return car;
}

};

class faculty :public stakeholders


{
protected:
int parkingslot;

public:
vehicle getcar()
{
return car;
}

int getslot()
{
return parkingslot;
}

void setslot(int s)
{
parkingslot = s;
}

};

class parking //Parking Class with Student Faculty and Staff members as attributes
{
private:

int park[60];
student s;
faculty f;
staff sta;
int space;
float x;
public:

parking()
{

for (int i = 0; i<60; i++)


{
park[i] = 0;
}

void facultyslot(int slot, int reg)


{
park[slot] = reg;
}

bool checkpark()
{
bool vacant = false;
for (int i = 0; i<60; i++)
{
if (park[i] == 0)
{
cout << "Space " << i << " is vacant" << endl;
vacant = true;
}

if (vacant == true)
return true;
else
return false;
}

void viewpark() // Viewing the parking


{
cout << "\tVIEW PARKING" << endl << endl;
for (int i = 0; i<60; i++)
{

if (park[i] != 0)
{
cout << "Slot " << i << ": " << park[i] << endl;
}

else
cout << "Slot " << i << " is empty" << endl;

}
}

void deallocate(int r) // Deallocating the space from the parking


{
int i = 0;
while (park[i] != r)
{
i++;
}

park[i] = 0;
cout << "Goodbye,see you soon" << endl;
system("pause");
}

int allocateparking(int choice, int reg, int x) // Allocating space to the new car entrant
{
if (choice == 1)
{

if (checkpark() == true)
{

cout << "Choose your parking space: ";


cin >> space;
park[space] = reg;
cout << "You have been allocated parking space, please park
in the specified place THANKYOU" << endl;
return 0;
}

else
{
cout << "Sorry No parking space available, you can park
outside" << endl;
}

}
if (choice == 2)
{

if (checkpark() == true)
{

cout << "Choose your parking space: ";


cin >> space;
park[space] = reg;
cout << "You have been allocated parking space, please park
in the specified place THANKYOU" << endl;
}

else
{
cout << "Sorry No parking space available, you can park
outside" << endl;
}
}
}

};
// Admin Functionalities and things under his/her hold
class admin :public stakeholders
{
private:
static admin *head1;
static admin *head2;
static admin *head3;
student obj;
staff obj1;
faculty obj2;
admin *next;
int g;
int x;
// parking p;

public:
void addstudentcar(string n, int regno, float bal)
{
admin *newnode = new admin;
newnode->name = n;
newnode->obj.set(bal);
newnode->obj.car.setreg(regno);
newnode->next = NULL;
newnode->next = head1;
head1 = newnode;
}
void addstaffcar(string n, int regno, float bal, int gra)
{
admin *newnode = new admin;
newnode->name = n;
newnode->obj1.set(bal);
newnode->obj1.setgrade(gra);
newnode->obj1.car.setreg(regno);
newnode->next = NULL;
newnode->next = head2;
head2 = newnode;
}
void addfacultycar(string n, int regno, int slotno)
{
admin *newnode = new admin;
newnode->name = n;
newnode->obj2.car.setreg(regno);
newnode->obj2.setslot(slotno);
newnode->next = NULL;
newnode->next = head3;
head3 = newnode;

void displaycars(int choice)


{
if (choice == 1)
{
admin *temp = head1;
cout << endl;
cout << "Name" << "\tBalance" << "\tReg_no" << endl << endl;
while (temp != NULL)
{
cout << temp->name << "\t";
cout << temp->obj.getdues() << "\t";
cout << temp->obj.car.getreg();
cout << endl;
temp = temp->next;
}
}

if (choice == 2)
{
admin *temp = head2;
cout << endl;
cout << "Name" << "\tBalance" << "\tGrade" << "\tReg_no" << endl << endl;
while (temp != NULL)
{
cout << temp->name << "\t";
cout << temp->obj1.getbalance() << "\t";
cout << temp->obj1.getgrade() << "\t";
cout << temp->obj1.car.getreg();
cout << endl;
temp = temp->next;
}
}

if (choice == 3)
{
admin *temp = head3;
cout << endl;
cout << "Name" << "\tReg No" << "\tSlot_no" << endl;
while (temp != NULL)
{
cout << temp->name << "\t";
cout << temp->obj2.car.getreg() << "\t";
cout << temp->obj2.getslot() << "\t";
cout << endl;
temp = temp->next;
}
}
// Function to check if the car is already present or not
bool searchcar(int key, int choice)
{
int found = false;
if (choice == 1)
{
admin *temp = head1;
while (temp != NULL)
{
if (temp->obj.car.getreg() == key)
{
found = true;
break;
}
temp = temp->next;
}

if (found == false)
{
cout << "No car registered with this reg_no" << endl;
return false;
}

else
{
cout << "Car registered" << endl;
if (temp->obj.checkdues() == true)
{
return true;
}
else
{
cout << "Outstanding dues, Would you like to pay right
now?" << endl;
cout << "1. YES" << endl;
cout << "2. NO" << endl;
cout << "Your choice: ";
cin >> x;
if (x == 1)
{
cout << "Enter amount: ";
cin >> x;
temp->obj.increment(x);
system("pause");
return true;
}
else if (x == 2)
{
return false;
}
else
{
cout << "Error" << endl;
}
}
}
}

if (choice == 2)
{
admin *temp = head2;
while (temp != NULL)
{
if (temp->obj1.car.getreg() == key)
{
found = true;
break;
}
temp = temp->next;
}

if (found == false)
{
cout << "No car registered with this reg_no" << endl;
return false;
}

else
{
cout << "Car registered" << endl;
if (temp->obj1.checkgrade() == true)
{
return true;
}
else
return false;
}}

if (choice == 3)
{
admin *temp = head3;
while (temp != NULL)
{
if (temp->obj2.car.getreg() == key)
{
found = true;
break;
}
temp = temp->next;
}

if (found == false)
{
cout << "No car registered with this reg_no" << endl;
return false;
}

else
{
cout << "Car registered" << endl;
cout << "You may park in slot " << temp->obj2.getslot() << endl;
return true;
}
}
}
//Function to cut balance from the total balance
void cutbalance(int key, int choice, int space)
{
int found = false;
if (choice == 1)
{
admin *temp = head1;
while (temp != NULL)
{
if (temp->obj.car.getreg() == key)
{
found = true;
break;
}
temp = temp->next;
}

if (space == 1)
{
temp->obj.setbalance(25);
}

else
{
temp->obj.setbalance(15);
}
}

if (choice == 2)
{
admin *temp = head2;
while (temp != NULL)
{
if (temp->obj1.car.getreg() == key)
{
found = true;
break;
}
temp = temp->next;
}

if (space == 1)
{
temp->obj1.setbalance(25);
}

else
{
temp->obj1.setbalance(15);
}
}

//Deleting car from parking/Exiting


void delcar(int key, int choice)
{
if (choice == 1)
{
admin *Current = head1;
admin *Previous = head1;

while (Current != NULL && Current->obj.car.getreg() != key)


{
Previous = Current;
Current = Current->next;
}

if (Current == NULL)
{
cout << "Error";
return;
}

if (Current == head1)
head1 = head1->next;
else
Previous->next = Current->next;

delete Current;
}

if (choice == 2)
{
admin *Current = head2;
admin *Previous = head2;

while (Current != NULL && Current->obj1.car.getreg() != key)


{
Previous = Current;
Current = Current->next;
}

if (Current == NULL)
{
cout << "Error";
return;
}

if (Current == head2)
head2 = head2->next;
else
Previous->next = Current->next;

delete Current;
}
if (choice == 3)
{
admin *Current = head3;
admin *Previous = head3;

while (Current != NULL && Current->obj2.car.getreg() != key)


{
Previous = Current;
Current = Current->next;
}

if (Current == NULL)
{
cout << "Error";
return;
}

if (Current == head3)
head3 = head3->next;
else
Previous->next = Current->next;

delete Current;
}

};
admin* admin::head1 = NULL;
admin* admin::head2 = NULL;
admin* admin::head3 = NULL;

///////////////////////////////////////MAIN CLASS ////////////////////////////////////


void main()
{

int choice;
string name;
vehicle car;
float balance;
int regno;
int grade;
student s;
staff sta;
faculty f;
admin ad;
int slot;
parking p;
string pass;

cout << "\t\t***Welcome to UET Taxila PARKING SYSTEM***" << endl << endl << endl;
Sleep(1000);
while (1)
{
system("cls");
cout << "1. Login as administrator" << endl;
cout << "2. Enter as student" << endl;
cout << "3. Enter as staff member" << endl;
cout << "4. Enter as faculty member" << endl;
cout << "5. To exit parking" << endl;

cout << "Your choice: ";


cin >> choice;

if (choice == 1)
{
cout << "Enter Password: ";
cin >> pass;

if (pass == "admin")
{
system("cls");
cout << "1. Add car" << endl;
cout << "2. Delete car" << endl;
cout << "3. Display cars" << endl;
cout << "4. Display slots" << endl;
cout << "5. Display all data stored in system" << endl;
cout << "Your choice: ";
cin >> choice;

if (choice == 1)
{
system("cls");
cout << "1. Add student car" << endl;
cout << "2. Add staff car" << endl;
cout << "3. Add faculty car" << endl;
cout << "Your choice: ";
cin >> choice;

if (choice == 1)
{
system("cls");
cout << "Enter Name: ";
cin >> name;
cout << "Enter registration number: ";
cin >> regno;
cout << "Enter the amount of balance payed: ";
cin >> balance;
ad.addstudentcar(name, regno, balance);
system("pause");
}

if (choice == 2)
{
system("cls");
cout << "Enter Name: ";
cin >> name;
cout << "Enter registration number: ";
cin >> regno;
cout << "Enter the amount of balance payed: ";
cin >> balance;
cout << "Enter grade: ";
cin >> grade;
ad.addstaffcar(name, regno, balance, grade);
system("pause");
}

if (choice == 3)
{
system("cls");
cout << "Enter Name: ";
cin >> name;
cout << "Enter registration number: ";
cin >> regno;
cout << "Enter slot number: ";
cin >> slot;
p.facultyslot(slot, regno);
ad.addfacultycar(name, regno, slot)
}

continue;
}

if (choice == 2)
system("cls");
cout << "1. Delete student car" << endl;
cout << "2. Delete staff car" << endl;
cout << "3. Delete faculty car" << endl;
cout << "Your choice: ";
cin >> choice;
if (choice == 1)
{
cout << "Enter reg_no of car: ";
cin >> regno;
ad.delcar(regno, 1);
}

if (choice == 2)
{
cout << "Enter reg_no of car: ";
cin >> regno;
ad.delcar(regno, 2);
}

if (choice == 3)
{
cout << "Enter reg_no of car: ";
cin >> regno;
ad.delcar(regno, 3);
}
}

if (choice == 3)
{
system("cls");
cout << "1. Display student cars" << endl;
cout << "2. Display staff cars" << endl;
cout << "3. Display faculty cars" << endl;
cout << "Your choice: ";
cin >> choice;

if (choice == 1)
{
ad.displaycars(1);
system("pause");

if (choice == 2)
{
ad.displaycars(2);
system("pause");
}

if (choice == 3)
{
ad.displaycars(3);
system("pause");
}
}

if (choice == 4)
{
system("cls");
p.viewpark();

_getch();

if (choice == 5)
{
cout << "\tSTUDENTS" << endl << endl;
ad.displaycars(1);
cout << "\tSTAFF" << endl << endl;
ad.displaycars(2);
cout << "\tFACULTY" << endl << endl;
ad.displaycars(3);
system("pause");
}
continue;
}

else
{
cout << "Wrong password entered" << endl;
system("pause");
}
}

if (choice == 2)
{
system("cls");
cout << "Enter reg_no of car: ";
cin >> regno;
if (ad.searchcar(regno, 1) == true)
{
if (p.allocateparking(1, regno, 1) == 1)
{
ad.cutbalance(regno, 1, 1);
system("pause");

else
{
ad.cutbalance(regno, 1, 0);
system("pause");

}
}

else
{
cout << "Your dues are not clear,please visit the office" << endl;
system("pause");
}

continue;

if (choice == 3)
{
system("cls");
cout << "Enter reg_no of car: ";
cin >> regno;
if (ad.searchcar(regno, 2) == true)
{
if (p.allocateparking(2, regno, 1) == 1)
{
ad.cutbalance(regno, 2, 1);
system("pause");
}

else
{
ad.cutbalance(regno, 2, 0);
system("pause")
}
}

else
{
p.allocateparking(2, regno, 2);
ad.cutbalance(regno, 2, 0);
system("pause");

continue;
}

if (choice == 4)
{
system("cls");
cout << "Enter reg_no of car: ";
cin >> regno;
ad.searchcar(regno, 3);
system("pause");

continue;
}

if (choice == 5)
{
system("cls");
cout << "Enter reg_no of car: ";
cin >> regno;
p.deallocate(regno);

continue;
}

Anda mungkin juga menyukai