Tuesday 17 July 2018

C++ Car Parking Management System Complete Project Source Code

C++ Car Parking Management System

This code is written by me (c) all rights are reserved, you need permission for 3rd party content use. in C++ using following components are used
a) structure
b) call by value functions
c) selection statement
d) loops

No part of this code is copied, after huge demand of this Car parking system on google search
i basically go through my previous posted project (Basic C++ car Parking Program) where i wrote simple basic car parking code
which is very basic for any one to understand. Now i used advance logics behind system to make
this project look very realistic so i added more features in this project

you are asked to enter 5 car information because only 5 slots are available for this system
if all slots are occupied you can't add new car in parking system, if any car is exit from the system than new car can be added in system. This system can calculate bill on basis of hours car is parked.
You can also see overall history of system log with full detail. You can edit occupied car on slot information by updating hours, name , phone number. You can check how many cars are occupied and how many slots are free currently in system.


following menu options are available

1 Add Your Car
2 Exit Remove Your Car
3 Bill of Parking Car
4 View All Parked Cars Information
5 Parking Slots Available
6 History/Log
7 Edit Parking Info

-------------------------------------------------------------------------------------------------------------------
Output:-


Code:-

Note:- name , phone number with dollar is concatenated because  cin.getline(variable,sizeof(variable),character used to end variable/finish name etc) is used demands example :- variable is name/phone number you want to entersizeofvariable is you want to limit the size of name/phonenumberendcharacter is used to stop wastage of useless space characters or usage of memory so i usedcin.getline(name,15,'$'); $ sign shows end of characterwhich means i enter "umarjaved" at end i need '$' to write otherwise name will not end and i am bound to enter at maximum 15 character for name only

#include<iostream>
#include<conio.h>
using namespace std;
int parking_space = 0;
int rate = 3;
int parking_hist = 0;

struct infos
{
 char name[15];
 char phone[12];
 int Park_slot;
 float hours;
};

struct his_info{
 char name[15];
 char phone[12];
 int Park_slot;
 float hours;
 float amount;
};


infos park_info[5];
his_info hist[99];

//initialization of every single function availble in program
void insert_car();
void exit_car();
void View_allInfos();
void history_infos();
void view_historyParkingInfos();
void update_parkingLog();

void main()
{
cout<<"-----Menu-----"<<endl;
cout<<"----1 Park Your Car----"<<endl;
cout<<"----2 Exit Your Car----"<<endl;
cout<<"----3 Rate of Parking Car----"<<endl;
cout<<"----4 View All Parked Cars Information----"<<endl;
cout<<"----5 Parking Slots Available----"<<endl;
cout<<"----6 History/Log ----"<<endl;
cout<<"----7 Edit Parking Info----"<<endl;
int choice;
cin>>choice;
do
{

switch(choice)
{
case 1:
{
insert_car();
break;
}
case 2:
{
exit_car();
break;
}
case 3:
{
cout<<endl<<"-------------(Info)---------------------------"<<endl<<endl;
cout<<"3 dollars Per Hour"<<endl;
cout<<endl<<"-------------(Info)---------------------------"<<endl<<endl;
break;
}
case 4:
{
View_allInfos();
break;
}
case 5:
{
cout<<endl<<"-------------(Info)---------------------------"<<endl<<endl;
cout<<"Space Slot Total Available = "<<5-parking_space<<endl;
cout<<endl<<"-------------(Info)---------------------------"<<endl<<endl;
break;
}
case 6:
{
view_historyParkingInfos();
break;
}
default:
{
update_parkingLog();
break;
}
}

cout<<"-----Menu-----"<<endl;
cout<<"----1 Park Your Car----"<<endl;
cout<<"----2 Exit Your Car----"<<endl;
cout<<"----3 Rate of Parking Car----"<<endl;
cout<<"----4 View All Parked Cars Information----"<<endl;
cout<<"----5 Parking Slots Available----"<<endl;
cout<<"----6 History/Log ----"<<endl;
cout<<"----7 Edit Parking Info----"<<endl;

cin>>choice;
}while(1);
_getch();

}


void insert_car()
{

    cout<<"Car parking Management System"<<endl;
cout<<"Please Remember rate per hour is "<<rate<<"$"<<endl;

cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cout<<"for how many hours you want to park your car : ";
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cin>>park_info[parking_space].hours;


if(park_info[parking_space].hours<1)
{
cout<<endl<<"-------------ERROR---------------------------"<<endl<<endl;
cout<<"Please enter valid hours and try again"<<endl;
cout<<endl<<"-------------ERROR---------------------------"<<endl<<endl;
insert_car();
}

cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cout<<"Please Pay bill of amount total = "<<rate*park_info[parking_space].hours<<endl;
float bill =0;
cout<<"Pay : ? ";
cin>>bill;
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;

if(bill<rate*park_info[parking_space].hours)
{
cout<<endl<<"-------------ERROR---------------------------"<<endl<<endl;
cout<<"Please enter valid bill amount and try again"<<endl;
cout<<endl<<"-------------ERROR---------------------------"<<endl<<endl;
insert_car();
}
else if(bill>rate*park_info[parking_space].hours)
{
cout<<"Please recieve balance amount : "<<bill - rate*park_info[parking_space].hours<<endl;
}
else
{

}


//add new vehicle owner information to fill the parking slot ticket is currently processing for purchasing
cout<<"Please provide your name : "<<endl;
cin.getline(park_info[parking_space].name,15,'$');
cout<<"Please provide your cell no : "<<endl;
cin.getline(park_info[parking_space].phone,15,'$');
park_info[parking_space].Park_slot = parking_space+1;

cout<<"please park your car at parking slot number :"<<park_info[parking_space].Park_slot;


//copy all new info to history logs as well
history_infos();

parking_space++;
//parking_space++;
}



void exit_car()
{
cout<<"If you wish to remove car from parking slot press Y for Yes and N for No : "<<endl;
char cho;
cin>>cho;
if(cho == 'Y' || cho == 'y')
{
int slot;
cout<<"please enter slot # :"<<endl;
cin>>slot;

int del = 0;
//verifying car is available in slot that is mentioned by operator
for(int j=0;j<=parking_space;j++)
{
if(slot == park_info[j].Park_slot)
{
del = j;
break;
}
}


//swap next values inside the old slots
char *name[15];
char *phn[15];
int slot_pos = 0;

for(int k=del;k<parking_space;k++)
{

if(k==parking_space)
{
strcpy(park_info[k+1].name,'\0');

strcpy(park_info[k+1].phone,'\0');

park_info[k+1].Park_slot = '\0';
break;
}

//if(k<parking_space)
{
strcpy(park_info[k].name,park_info[k+1].name);
//*park_info[k].name  = *park_info[k+1].name;

strcpy(park_info[k].phone,park_info[k+1].phone);
//*park_info[k].phone = *park_info[k+1].phone;

slot_pos = park_info[k+1].Park_slot;
park_info[k].Park_slot = slot_pos-1;
}
}


//program must control or divert & stop the negative value of global variable

if(parking_space > 0)
{
parking_space--;
}

}
else
{

}
}


void View_allInfos()
{
if(parking_space == 0)
{
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cout<<"All Slots are Available no Car is Parked right now"<<endl;
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;

return;
}
else
{
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
for(int i=0;i<parking_space;i++)
{
cout<<endl<<endl;

cout<<"name : "<<park_info[i].name<<endl;
cout<<"cell no : "<<park_info[i].phone<<endl;
cout<<"Slot number :"<<park_info[i].Park_slot<<endl;
cout<<"Hours Allocated for Parking :"<<park_info[i].hours<<endl;
cout<<"Amount Paid for Parking :"<<park_info[i].hours*rate<<endl;
}
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
}
}


void history_infos()
{
strcpy(hist[parking_hist].name,park_info[parking_space].name);
strcpy(hist[parking_hist].phone,park_info[parking_space].phone);
hist[parking_hist].Park_slot = park_info[parking_space].Park_slot;
hist[parking_hist].hours=park_info[parking_space].hours;
hist[parking_hist].amount = park_info[parking_space].hours * rate;
parking_hist++;
}


void view_historyParkingInfos()
{
if(parking_hist == 0)
{
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cout<<"In history no Car is Parked right now"<<endl;
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;

return;
}
else
{

cout<<endl<<"-------------(Info)---------------------------"<<endl<<endl;
for(int i=0;i<parking_hist;i++)
{
cout<<endl<<endl;
cout<<"name : "<<hist[i].name<<endl;
cout<<"cell no : "<<hist[i].phone<<endl;
cout<<"Slot number :"<<hist[i].Park_slot<<endl;
cout<<"Hours Parked : "<<hist[i].hours<<endl;
cout<<"Amount Bill : "<<hist[i].amount<<endl;
}
cout<<endl<<"-------------(Info)---------------------------"<<endl<<endl;
}


}


void update_parkingLog()
{

if(parking_space == 0)
{
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cout<<"Empty no Slot information found to update/edit"<<endl;
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;

return;
}
else
{


char name[15];
char phns[15];
int hr;

int slot;
cout<<"Enter Slot Number Please : ";
cin>>slot;
for(int i =0;i<parking_space;i++)
{
if(slot == park_info[i].Park_slot)
{
cout<<endl<<"Enter Name = "; cin.getline(name,15,'$');
cout<<endl<<"Enter Phone = "; cin.getline(phns,15,'$');
cout<<endl<<"Enter Parking Hours = "; cin>>hr;
strcpy(park_info[i].name,name);
strcpy(park_info[i].phone,phns);
park_info[i].hours = hr;
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cout<<"Successfully Modified Information"<<endl;
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;

break;
}

}
}

}