You are on page 1of 25

#include<graphics.

h>
#include<iostream>
#include<fstream>
#include<conio.h>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<stdlib.h>
#include<dos.h>
#include<stdio.h>
using namespace std;
int df();
int tp();
int fact(int q)
{
if(q==0)
return 1;
else
return(fact(q-1)*10);
}
void cins(char *n)
{
char a[40];
int q;
int correct = 1;
cin.ignore();
do{
correct = 1;
gets(a);
for(q=0;a[q]!='\0';q++)
{
if(!isalpha(a[q]) && a[q]!=' ')
{
correct = 0;
cout<<"Wrong Entry !";
cout<<"\nEnter Again : ";
break;
}
}
}while(!correct);
strcpy(n,a);
}
int cini(int &n)
//defining a function to enter only inte
gers
{
char a[40];
int q;
int correct = 1;
fflush(stdin);
do{
correct = 1;
gets(a);
for(q=0;a[q]!='\0';q++)
{
if(!isdigit(a[q]))

{
correct = 0;
cout<<"Wrong Entry !";
cout<<"\nEnter Again : ";
break;
}
}
}while(!correct);
n = atoi(a);
}
void cinsex(char &n)
{
char a;
int correct = 1;
fflush(stdin);
do{
correct = 1;
cin>>a;
if(a=='109'&&a=='111'&&a=='121')
{
correct = 0;
cout<<"Wrong Entry !";
cout<<"\nEnter Again : ";
break;
}
}
while(!correct);
n=a;
}
void padf()
{
char a1[40],l[40]="gagan",c[40]="back";
int flag1=1;
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n\n";
cout<<"enter user name
: ";
do
{
gets(a1);
if(strcmp(a1,l)==0)
matches with preloaded username
{
flag1=1;
int p,flag2=1;
cout<<"enter password
: ";
do
{
cin>>p;
if(p==13456)
matches with preloaded password
{
flag2=1;
df();
n calling the function tp
}
else if(p==0)
{
flag2=1;

//Entering a1 as username
//comparing entered username

//comparing entered password

//if password also match the

//if 0 entered then going ba

ck
break;
}
else
{
flag2=0;
cout<<"wrong password!\nEnter 0 to go back\nEnter again : ";
}
}while(flag2==0);
}
else if(strcmp(a1,c)==0)
{
break;
}
else
{
flag1=0;
cout<<"wrong username!\nEnter back to go back\nOr enter user name ag
ain : ";
}
}
while(flag1==0);
}
void patp()
{
char a2[40],l[40]="gagan",c[40]="back";
int flag1=1;
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n\n";
cout<<"enter user name
: ";
do
{
gets(a2);
//Entering a2 as username
if(strcmp(a2,l)==0)
//comparing entered username matc
hes with preloaded username
{
flag1=1;
int p,flag2=1;
cout<<"enter password
: ";
do
{
cin>>p;
if(p==13456)
//comparing entered password mat
ches with preloaded password
{
flag2=1;
tp();
//if password also match then ca
lling the function tp
}
else if(p==0)
{
flag2=1;
break;
}
else
{
flag2=0;
cout<<"wrong password!\nEnter 0 to go back\nEnter again : ";

}
}while(flag2==0);
}
else if(strcmp(a2,c)==0)
{
break;
}
else
{
flag1=0;
flag1=0;
cout<<"wrong username!\nEnter back to go back\nOr enter user name ag
ain : ";
}
}
while(flag1==0);
}
class defaulter
{
private:
char name[40],vn[40],s;
int f[11],fst,pl,fine[11],totalfine;
public:
defaulter()
{
fine[0]=150;
fine[1]=200;
fine[2]=150;fine[3]=150;fine[4]=200;fine[5]=150;fine[6]=350;fine[7]=350;
fine[8]=250;fine[9]=300;fine[10]=400;
totalfine=0;
int i;
for(i=0;i<11;i++)
f[i]=0;
}
void Add_defaulter()
{
cout<<"Enter name
: ";
cins(name);
cout<<"enter vehicle name
: ";
gets(vn);
cout<<"enter sex
: ";
cinsex(s);
cout<<"enter BAC value using Field Sobriety test (in ppm)
: ";
cini(fst);
//entering an integer in fs
t
if(fst>500)
{
f[10]=1;
}
cout<<"enter pollution level of vehicle
: ";
cini(pl);
totalfine=0;
Add_fault();
};
void Add_fault();
char * get_name()
//defining a function to ret
urn defaulter`s name as it is private
{

return(name);
}
int get_fault(int n)
urn defaulter`s fault as it is private
{
return(f[n]);
}

//defining a function to ret

void ShowData()
{
int z=0;
cout<<"\nname
:";
puts(name);
cout<<"sex
:"<<s<<endl;
cout<<"vehicle name
:";
puts(vn);
cout<<"BAC value (in ppm)
:";
cout<<fst;
cout<<"\npollution level of vehicle :"<<pl<<endl;
cout<<"Broken Rules
:
if(f[0]==1)
{
z++;
cout<<z<<". Without helmet
<<"\n";
}
if(f[1]==1)
{
z++;
cout<<z<<". crossed redlight
<<"\n";
}
if(f[2]==1)
{
z++;
cout<<z<<". more than two person on vehicle
<<"\n";
}
if(f[3]==1)
{
z++;
cout<<z<<". driving on wrong side of the road
<<"\n";
}
if(f[4]==1)
{
z++;
cout<<z<<". without seatbelts
<<"\n";
}
if(f[5]==1)
{
z++;
cout<<z<<". Underage
<<"\n";
}
if(f[6]==1)
{
z++;

fine\n";

"<<fine[0]

"<<fine[1]

"<<fine[2]

"<<fine[3]

"<<fine[4]

"<<fine[5]

cout<<z<<". Stunts

"<<fine[6]

}
if(f[7]==1)
{
z++;
cout<<z<<". Driving faster than speed limit

"<<fine[7]

}
if(f[8]==1)
{
z++;
cout<<z<<". Using mobile on vehicle

"<<fine[8]

}
if(f[9]==1)
{
z++;
cout<<z<<". number plate is not with proper license :

"<<fine[9]

}
if(f[10]==1)
{
z++;
cout<<z<<". drunk and drive

"<<fine[10

<<"\n";

<<"\n";

<<"\n";

<<"\n";

]<<"\n";
totalfine=totalfine+fine[10];
}
cout<<"Total Fine

"<<totalfine<<"\

n";
}
}b;
void defaulter ::Add_fault()
{
int i,j;
char ans;
for(j=0;j<10;j++)
{
f[j]=0;
}
AD:
system("cls");
cout<<"Add fault\n";
cout<<"1. Without helmet\n2. crossed redlight\n3. more than two person on ve
hicle\n4. driving on wrong side of the road\n";
cout<<"5. without seatbelts\n6. Underage\n7. Stunts\n8. Driving faster than
speed limit\n";
cout<<"9. Using mobile on vehicle\n10. number plate is not with proper licen
se\n";
cini(i);
f[i-1]=1;
totalfine=totalfine+fine[i-1];
cout<<"add more fault? (y/n): ";
cin>>ans;
if(ans=='y')
goto AD;
}
void RandomWrite3()

//defining a function

to store data from class defaulter to file df


{
ofstream fdfo;
fdfo.open("df.dat",ios::app|ios::binary);
if(!fdfo)
{
cout<<"File does not exist";
exit(1);
}
fdfo.write(reinterpret_cast <const char*>(&b),sizeof(defaulter));
fdfo.close();
}
void RandomRead3()
//defining a function t
o store data from file df to class defaulter
{
int i=0,j=0;
ifstream fdfi("df.dat",ios::binary);
if(!fdfi)
{
cout<<"File does not exist";
exit(1);
}
string a[40];
while(!fdfi.eof())
{
fdfi.read(reinterpret_cast <char*>(&b),sizeof(defaulter));
if(fdfi.eof())
break;
a[i] = b.get_name();
//entering all names in
array of strings
i++;
}
fdfi.close();
j=i;
sort(a,a+j);
//sorting all members o
f a[]
char n[40];
for(i=0;i<j;i++)
{
fdfi.open("df.dat",ios::binary);
strcpy(n,a[i].c_str());
while(!fdfi.eof())
{
fdfi.read(reinterpret_cast <char *>(&b),sizeof(defaulter));
if(fdfi.eof())
break;
if(strcmpi(b.get_name(),n)==0)
{
b.ShowData();
cout<<"\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\xDB\n\n";
}
}
fdfi.close();
}
}

void sdfbf()
//defining function showda
ta of specific faults
{
int flag=0;
ifstream fdfi("df.dat",ios::binary);
if(!fdfi)
{
cout<<"file does not exist.";
exit(1);
}
int n;
cin.ignore();
cout<<"\nenter fault to search : ";
cout<<"1. Without helmet\n2. crossed redlight\n3. more than two person on ve
hicle\n4. driving on wrong side of the road\n";
cout<<"5. without seatbelts\n6. Underage\n7.Stunts\n8.Driving faster than sp
eed limit\n";
cout<<"9. Using mobile on vehicle\n10. number plate is not with proper licen
se\n11. drunk and drive\n";
cini(n);
//entering selected fault
in i
while(!fdfi.eof())
{
fdfi.read(reinterpret_cast <char *>(&b),sizeof(defaulter));
if(fdfi.eof())
break;
if(b.get_fault(n-1)==1)
{
flag=1;
b.ShowData();
cout<<"\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\n\n";
}
}
if(flag==0)
{
cout<<"record not found.";
}
fdfi.close();
}
void sdfbn()
ch employee by defaulter name
{
int flag=0;
ifstream fdfi("df.dat",ios::binary);
if(!fdfi)
{
cout<<"file does not exist.";
exit(1);
}
char n[40];
cin.ignore();
cout<<"enter name to search : ";
search in c
gets(n);
while(!fdfi.eof())

//defining a function to sear

//entering defaulter name to

{
fdfi.read(reinterpret_cast <char *>(&b),sizeof(defaulter));
if(fdfi.eof())
break;
if(strcmpi(b.get_name(),n)==0)
{
flag=1;
b.ShowData();
cout<<"\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\n\n";
}
}
if(flag==0)
{
cout<<"record not found.";
}
fdfi.close();
}
int df()
//function containing everything about
defaulter`s info
{
int i;
A3:
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n";
cout<<"1. Add Defaulters\n2. Show List in alphabatical order\n3. Search defa
ulter by name\n4. show defaulter by faults\n5. go back\nEnter your choice: ";
cin>>i;
switch(i)
{
case 1:
{
b.Add_defaulter();
RandomWrite3();
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n";
goto A3;
break;
}
case 2:
{
RandomRead3();
system("pause");
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n";
goto A3;
break;
}
case 3:
{
sdfbn();
system("pause");
goto A3;
break;
}
case 4:
{

sdfbf();
system("pause");
goto A3;
break;
}
case 5:
{
break;
}
default:
cout<<"wrong entry please enter again\n";
goto A3;
}
}
class trplc
{
private:
char en[40],eg;
int ec,ea,ee,es;
public:
void setdata()
{
cout<<"enter employee`s name
: ";
cins(en);
//entering a name in en
cout<<"enter employee`s age
: ";
cini(ea);
cout<<"enter employee`s experience: ";
cini(ee);
cout<<"enter employee`s gender
: ";
cinsex(eg);
cout<<"enter employee`s salary
: ";
cini(es);
}
void set_ec(int p)
//defining a function to
set employee code
{
ec=p;
}
int get_ec()
{
return ec;
//defining a function to
return employee code as it is a private variable
}
void showdata()
{
cout<<"\n\nemployee code
: "<<ec<<endl;
cout<<"employee`s name
: ";
puts(en);
cout<<"employee`s age
: "<<ea<<endl;
cout<<"employee`s experience
: "<<ee<<endl;
cout<<"employee`s gender
: "<<eg<<endl;
cout<<"employee`s salary
: "<<es<<endl;
}
char * get_en()
{
return(en);
//defining a function
to return employee namme
}
}a;

void RandomWrite2()
//defining a function
to store data from class trplc to file tp
{
ofstream ftpo;
ftpo.open("tp.dat",ios::app|ios::binary);
if(!ftpo)
{
cout<<"File does not exist";
exit(1);
}
int pos=0;
ftpo.seekp(0,ios::end);
pos=ftpo.tellp()/sizeof(trplc);
// setting employee cod
e automatically
a.set_ec(pos+1);
ftpo.write(reinterpret_cast <const char*>(&a),sizeof(trplc));
ftpo.close();
}
void RandomRead2()
//defining a function t
o store data from file tp to class trplc
{
ifstream ftpi("tp.dat",ios::binary);
if(!ftpi)
{
cout<<"File does not exist";
exit(1);
}
while(!ftpi.eof())
{
ftpi.read(reinterpret_cast <char*>(&a),sizeof(trplc));
if(ftpi.eof())
break;
a.showdata();
//showing currently sto
red data in class trplc
cout<<"\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB";
}
cout<<"\n\n";
ftpi.close();
}
void sbn()
employee by employee name
{
int flag=0;
ifstream ftpi("tp.dat",ios::binary);
if(!ftpi)
{
cout<<"file does not exist.";
exit(1);
}
char n[40];
fflush(stdin);
cout<<"enter Full name to search : ";
gets(n);
ch in c
while(!ftpi.eof())
{

//defining a function to search

//entering employee name to sear

ftpi.read(reinterpret_cast <char *>(&a),sizeof(trplc));


if(ftpi.eof())
break;
if(strcmpi(a.get_en(),n)==0)
//checking if entered name match
es any employee name in file
{
flag=1;
a.showdata();
//if employee name matches than
showing it`s details on terminal
cout<<"\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\n\n";
}
}
if(flag==0)
{
cout<<"record not found.";
}
ftpi.close();
}
void sbc()
//defining a function to search
employee by employee code
{
int flag=0;
ifstream ftpi("tp.dat",ios::binary);
if(!ftpi)
{
cout<<"file does not exist.";
exit(1);
}
int c;
cout<<"enter code to search : ";
cini(c);
//entering employee code to sear
ch in c
while(!ftpi.eof())
{
ftpi.read(reinterpret_cast <char *>(&a),sizeof(trplc));
if(ftpi.eof())
break;
if(a.get_ec()==c)
//checking if entered integer ma
tches any employee code in file
{
flag=1;
a.showdata();
//if employee code matches than
showing it`s details on terminal
cout<<"\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\
xDB\xDB\xDB\n\n";
}
}
if(flag==0)
{
cout<<"record not found.";
}
ftpi.close();
}

int tp()
//function containing everything
about traffic personel`s info
{
int i;
A2:
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n";
cout<<"1. Add Employee \n2. Show list\n3. Search employee by employee code\n
4. search employee by name\n5. go back\nEnter your choice: ";
cini(i);
//entering integer in i
switch(i)
{
case 1:
{
a.setdata();
RandomWrite2();
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n";
goto A2;
break;
}
case 2:
{
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n";
RandomRead2();
system("pause");
goto A2;
break;
}
case 3:
{
sbc();
system("pause");
goto A2;
break;
}
case 4:
{
sbn();
system("pause");
goto A2;
break;
}
case 5:
{
break;
}
default:
cout<<"wrong entry please enter again\n";
goto A2;
}
}
void rb2p()
//function for route b/w 2 places
{
char sl[40],dl[40],rj[]="r",bk[]="b",ss[]="g";
int i,j,k,nor;
int R[3][3][3];
//integer array for distance
R[0][1][0]=4,R[0][1][1]=6;R[0][2][0]=8;R[0][2][1]=10;R[0][2][2]=14;R[1][2][0

]=4;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
R[j][i][k]=R[i][j][k];
}
}
}
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n";
cout<<"Enter Source location : ";
gets(sl);
cout<<"Enter destination
: ";
gets(dl);
if(strcmpi(sl,rj)==0)
{
if(strcmpi(dl,rj)==0)
{
cout<<"You are already there:P\n";
system("pause");
}
else if(strcmpi(dl,bk)==0)
{
cout<<"numbers of routes=2\n";
cout<<"Route
:
nor=2;
for(i=0;i<nor;i++)
{
cout<<"R"<<i+1<<"
]<<endl;
}
system("pause");
}
else if(strcmpi(dl,ss)==0)
{
cout<<"numbers of routes=3\n";
cout<<"Route
:
nor=3;
for(i=0;i<nor;i++)
{
cout<<"R"<<i+1<<"
]<<endl;
}
system("pause");
}
}
if(strcmpi(sl,bk)==0)
{
if(strcmpi(dl,bk)==0)
{
cout<<"You are already there:P\n";
system("pause");
}
else if(strcmpi(dl,rj)==0)
{
cout<<"numbers of routes=2\n";
cout<<"Route
:

Distance\n";

"<<R[0][1][i

Distance\n";

Distance\n";

"<<R[0][2][i

nor=2;
for(i=0;i<nor;i++)
{
cout<<"R"<<i+1<<"

"<<R[1][0][i]<<e

ndl;
}
system("pause");
}
else if(strcmpi(dl,ss)==0)
{
cout<<"numbers of routes=1\n";
cout<<"Route
:
nor=1;
for(i=0;i<nor;i++)
{
cout<<"R"<<i+1<<"

Distance\n";

"<<R[1][2][i

]<<endl;
}
system("pause");
}
}
if(strcmpi(sl,ss)==0)
{
if(strcmpi(dl,ss)==0)
{
cout<<"You are already there:P\n";
system("pause");
}
else if(strcmpi(dl,rj)==0)
{
cout<<"numbers of routes=3\n";
cout<<"Route
:
nor=3;
for(i=0;i<nor;i++)
{
cout<<"R"<<i+1<<"

Distance\n";

"<<R[2][0][i

]<<endl;
}
system("pause");
}
else if(strcmpi(dl,bk)==0)
{
cout<<"numbers of routes=1\n";
cout<<"Route
:
nor=1;
for(i=0;i<nor;i++)
{
cout<<"R"<<i+1<<"

Distance\n";

"<<R[1][2][i

]<<endl;
}
system("pause");
}
}
}
void cb2p()
places
{

//function for congestion level b/w 2

char sl[40],dl[40],rj[]="r",bk[]="b",ss[]="g";
int i,j,k,nor;
int C[3][3][3];
//integer array for congestion level
C[0][1][0]=90,C[0][1][1]=95;C[0][2][0]=70;C[0][2][1]=77;C[0][2][2]=10;C[1][2
][0]=50;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
C[j][i][k]=C[i][j][k];
}
}
}
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n";
cout<<"Enter Source location : ";
gets(sl);
cout<<"Enter destination
: ";
gets(dl);
if(strcmpi(sl,rj)==0)
{
if(strcmpi(dl,rj)==0)
{
cout<<"You are already there:P\n";
system("pause");
}
else if(strcmpi(dl,bk)==0)
{
cout<<"numbers of routes=2\n";
cout<<"Route
:
Congestion\n";
nor=2;
for(i=0;i<nor;i++)
{
cout<<"R"<<i+1<<"
:
"<<C[0][1][i
]<<endl;
}
system("pause");
}
else if(strcmpi(dl,ss)==0)
{
cout<<"numbers of routes=3\n";
cout<<"Route
:
Congestion\n";
nor=3;
for(i=0;i<nor;i++)
{
cout<<"R"<<i+1<<"
:
"<<C[0][2][i
]<<endl;
}
system("pause");
}
}
if(strcmpi(sl,bk)==0)
{
if(strcmpi(dl,bk)==0)
{
cout<<"You are already there:P\n";
system("pause");
}

else if(strcmpi(dl,rj)==0)
{
cout<<"numbers of routes=2\n";
cout<<"Route
:
nor=2;
for(i=0;i<nor;i++)
{
cout<<"R"<<i+1<<"

Congestion\n";

"<<C[1][0][i

]<<endl;
}
system("pause");
}
else if(strcmpi(dl,ss)==0)
{
cout<<"numbers of routes=1\n";
cout<<"Route
:
nor=1;
for(i=0;i<nor;i++)
{
cout<<"R"<<i+1<<"

Congestion\n";

"<<C[1][2][i

]<<endl;
}
system("pause");
}
}
if(strcmpi(sl,ss)==0)
{
if(strcmpi(dl,ss)==0)
{
cout<<"You are already there:P\n";
system("pause");
}
else if(strcmpi(dl,rj)==0)
{
cout<<"numbers of routes=3\n";
cout<<"Route
:
nor=3;
for(i=0;i<nor;i++)
{
cout<<"R"<<i+1<<"

Congestion\n";

"<<C[2][0][i

]<<endl;
}
system("pause");
}
else if(strcmpi(dl,bk)==0)
{
cout<<"numbers of routes=1\n";
cout<<"Route
:
nor=1;
for(i=0;i<nor;i++)
{
cout<<"R"<<i+1<<"
]<<endl;
}
system("pause");
}
}
}

Congestion\n";

"<<C[1][2][i

void best_route()
//function for most preferrable route
{
char sl[40],dl[40],rj[]="r",bk[]="b",ss[]="g";
int i,j,k,C[3][3][3],R[3][3][3],nor;
C[0][1][0]=90,C[0][1][1]=95;C[0][2][0]=70;C[0][2][1]=77;C[0][2][2]=10;C[1][2
][0]=50;
R[0][1][0]=4,R[0][1][1]=6;R[0][2][0]=8;R[0][2][1]=10;R[0][2][2]=14;R[1][2][0
]=4;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
R[j][i][k]=R[i][j][k];
C[j][i][k]=C[i][j][k];
}
}
};
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n";
cout<<"Enter Source location : ";
gets(sl);
cout<<"Enter destination
: ";
gets(dl);
if(strcmpi(sl,rj)==0)
{
if(strcmpi(dl,rj)==0)
{
cout<<"You are already there:P\n";
}
else if(strcmpi(dl,bk)==0)
{
nor=2;
cout<<"numbers of routes="<<nor<<"\n\n";
cout<<"P.N. Route
:
Distance :
Congestion\
n";
cout<<" 1. R1
:
"<<R[0][1][0]<<"
:
"<<C[0][1][0]<<"\n";
cout<<" 2. R2
:
"<<R[0][1][1]<<"
:
"<<C[0][1][1]<<"\n";
}
else if(strcmpi(dl,ss)==0)
{
nor=3;
cout<<"numbers of routes="<<nor<<"\n\n";
cout<<"P.N. Route
:
Distance
:
Congestion
\n";
cout<<" 1. R3
:
"<<R[0][2][2]<<"
:
"<<C[0][2][2]<<"\n";
cout<<" 2. R1
:
"<<R[0][2][0]<<"
:
"<<C[0][2][0]<<"\n";
cout<<" 3. R2
:
"<<R[0][2][1]<<"
:
"<<C[0][2][1]<<"\n";
}
}
else if(strcmpi(sl,bk)==0)
{
if(strcmpi(dl,bk)==0)

{
cout<<"You are already there:P\n";
}
else if(strcmpi(dl,rj)==0)
{
nor=2;
cout<<"numbers of routes="<<nor<<"\n\n";
cout<<"P.N. Route
:
Distance

Congestion\

n";
cout<<" 1. R1
"<<C[0][1][0]<<"\n";
cout<<" 2. R2
"<<C[0][1][1]<<"\n";

"<<R[0][1][0]<<"

"<<R[0][1][1]<<"

}
else if(strcmpi(dl,ss)==0)
{
nor=1;
cout<<"numbers of routes="<<nor<<"\n\n";
cout<<"P.N. Route
:
Distance

Congestion\

n";
cout<<" 1. R1
"<<C[1][2][0]<<"\n";

"<<R[1][2][0]<<"

}
}
else if(strcmpi(sl,ss)==0)
{
if(strcmpi(dl,ss)==0)
{
cout<<"You are already there:P\n";
}
else if(strcmpi(dl,rj)==0)
{
nor=3;
cout<<"numbers of routes="<<nor<<"\n\n";
cout<<"P.N. Route
:
Distance

Congestion

\n";
cout<<" 1. R3
"<<C[0][2][2]<<"\n";
cout<<" 2. R1
"<<C[0][2][0]<<"\n";
cout<<" 3. R2
"<<C[0][2][1]<<"\n";

:
:
:

"<<R[0][2][2]<<"

"<<R[0][2][0]<<"
"<<R[0][2][1]<<"

}
else if(strcmpi(dl,bk)==0)
{
nor=1;
cout<<"numbers of routes="<<nor<<"\n\n";
cout<<"P.N. Route
:
Distance

Congestion\

n";
cout<<" 1. R1
"<<C[1][2][0]<<"\n";

"<<R[1][2][0]<<"

}
}
system("pause");
}
void route()

//function containing everything about rout

e guide
{
int r,flag3=1;
do
{
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n";
cout<<"1. Check Route b/w two places\n2. check congestion level b/w two
places\n3. check most preferable place\n4. go back\n";
cini(r);
switch(r)
{
case 1:
{
rb2p();
break;
}
case 2:
{
cb2p();
break;
}
case 3:
{
best_route();
break;
}
case 4:
{
flag3=0;
break;
}
}
}while(flag3!=0);
}
void tl1()
{
int gd = DETECT, gm ;
initgraph(&gd, &gm,NULL);
int i=getmaxx()/2,j=getmaxy()/2,a,b,num;
//entering i
and j as mid points of the screen.
string m[10];
//entering a
n array of string to change time
m[0]="00";m[1]="01";m[2]="02";m[3]="03";m[4]="04";m[5]="05";m[6]="06";m[7]="
07";m[8]="08";m[9]="09";
int A[]={i-50,j-150,i+50,j-150,i+50,j+150,i-50,j+150,i-50,j-150};//defining
A as array of integers to draw body of traffic lights.
int B[]={i+110,j-40,i+190,j-40,i+190,j+40,i+110,j+40,i+110,j-40};//defining
A as array of integers to draw body of traffic lights.
int C[]={i+113,j-37,i+187,j-37,i+187,j+37,i+113,j+37,i+113,j-37};//defining
A as array of integers to draw body of traffic lights.
char t[10];
setcolor(DARKGRAY);
setfillstyle(SOLID_FILL,DARKGRAY);
fillpoly(5,A);
fillpoly(5,B);
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillpoly(5,C);

pieslice(i,j,0,360,37);
s traffic lights
pieslice(i,j-100,0,360,37);
pieslice(i,j+100,0,360,37);
getch();
setcolor(WHITE);
outtextxy(i-70,j+160,"press a key to go back");
settextstyle(SMALL_FONT,HORIZ_DIR,51);
for(a=0;a<1000;a++)
{
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
pieslice(i,j+100,0,360,37);
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
pieslice(i,j-100,0,360,37);
if(!kbhit()==0)
get out of the function.
break;
for(a=2;a>=0;a--)
{
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillpoly(5,C);
setcolor(RED);
strcpy(t,m[a].c_str());
outtextxy(i+115,j-37,t);
delay(1000);
}
setcolor(0);
setfillstyle(SOLID_FILL,BLACK);
pieslice(i,j-100,0,360,37);
setcolor(YELLOW);
setfillstyle(SOLID_FILL,YELLOW);
pieslice(i,j,0,360,37);
if(!kbhit()==0)
to get out of the function.
break;
for(a=2;a>=0;a--)
{
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillpoly(5,C);
setcolor(RED);
strcpy(t,m[a].c_str());
outtextxy(i+115,j-37,t);
delay(1000);
}
setcolor(0);
setfillstyle(SOLID_FILL,BLACK);
pieslice(i,j,0,360,37);
setcolor(GREEN);
setfillstyle(SOLID_FILL,GREEN);
pieslice(i,j+100,0,360,37);
if(!kbhit()==0)
it() to get out of the function.
break;
for(a=2;a>=0;a--)
{
setcolor(BLACK);

//drawing circles a

//using kbhit() to

//using kbhit()

//using kbh

setfillstyle(SOLID_FILL,BLACK);
fillpoly(5,C);
setcolor(RED);
strcpy(t,m[a].c_str());
outtextxy(i+115,j-37,t);
delay(1000);
}
}
getch();
closegraph();
}
void tl2()
{
int gd = DETECT, gm ;
initgraph(&gd, &gm,NULL);
int i=getmaxx()/2,j=getmaxy()/2,a,b,num;
//entering i and
j as mid points of the screen.
string m[10];
m[0]="00";m[1]="01";m[2]="02";m[3]="03";m[4]="04";m[5]="05";m[6]="06";m[7]="
07";m[8]="08";m[9]="09";
int A[]={i-50,j-150,i+50,j-150,i+50,j+150,i-50,j+150,i-50,j-150};//defining
A as array of integers to draw body of traffic lights.
int B[]={i+110,j-40,i+190,j-40,i+190,j+40,i+110,j+40,i+110,j-40};
int C[]={i+113,j-37,i+187,j-37,i+187,j+37,i+113,j+37,i+113,j-37};
char t[10];
setcolor(DARKGRAY);
setfillstyle(SOLID_FILL,DARKGRAY);
fillpoly(5,A);
fillpoly(5,B);
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillpoly(5,C);
pieslice(i,j,0,360,37);
//drawing circles a
s traffic lights
pieslice(i,j-100,0,360,37);
pieslice(i,j+100,0,360,37);
getch();
setcolor(WHITE);
outtextxy(i-70,j+160,"press a key to go back");
settextstyle(SMALL_FONT,HORIZ_DIR,51);
for(a=0;a<1000;a++)
{
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
pieslice(i,j+100,0,360,37);
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
pieslice(i,j-100,0,360,37);
setcolor(RED);
setfillstyle(SOLID_FILL,WHITE);
if(!kbhit()==0)
//using kbhit() to
get out of the function.
break;
for(a=5;a>=0;a--)
{
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillpoly(5,C);
setcolor(RED);

strcpy(t,m[a].c_str());
outtextxy(i+115,j-37,t);
delay(1000);
}
if(!kbhit()==0)
to get out of the function.
break;
setcolor(0);
setfillstyle(SOLID_FILL,BLACK);
pieslice(i,j-100,0,360,37);
setcolor(YELLOW);
setfillstyle(SOLID_FILL,YELLOW);
pieslice(i,j,0,360,37);
for(a=5;a>=0;a--)
{
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillpoly(5,C);
setcolor(RED);
strcpy(t,m[a].c_str());
outtextxy(i+115,j-37,t);
delay(1000);
}
if(!kbhit()==0)
it() to get out of the function.
break;
setcolor(0);
setfillstyle(SOLID_FILL,BLACK);
pieslice(i,j,0,360,37);
setcolor(GREEN);
setfillstyle(SOLID_FILL,GREEN);
pieslice(i,j+100,0,360,37);
for(a=5;a>=0;a--)
{
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillpoly(5,C);
setcolor(RED);
strcpy(t,m[a].c_str());
outtextxy(i+115,j-37,t);
delay(1000);
}
}
getch();
closegraph();
}

//using kbhit()

//using kbh

void cintime(char *n)


//defining a function to enter only
time
{
char a[6];
int q;
int correct = 1;
do
{
correct = 1;
gets(a);
for(q=0;a[q]!='\0';q++)
{
if(!isdigit(a[q]) && a[q]!=':')

{
correct = 0;
cout<<"Wrong Entry !";
cout<<"\nEnter Again : ";
break;
}
}
if(a[2]!=':')
{
correct = 0;
cout<<"Wrong Entry !\nEnter Again : ";
}
}while(!correct);
strcpy(n,a);
}
int main()
{
int i;
//defining integer to store choice.
system("color 0a");
//setting color of terminal to black and
green.
A:
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n";
cout<<"1. Show traffic light stimulation.\n2. Show traffic personel`s informati
on.\n";
cout<<"3. Show defaulter`s information.\n4. route guide\n5. Exit\nEnter your ch
oice: ";
cini(i);
//entering an integer in i
switch(i)
{
case 1:
{
char t[6];
system("cls");
cout<<"TRAFFIC MANAGEMENT SYSTEM \n\n";
cout<<"Enter Time (in hh:mm) :";
cintime(t);
//entering time in character array t
if(t[0]=='0'||t[0]=='2')
{
tl1();
//calling function tl1
}
else
{
tl2();
//calling function tl2
}
system("pause");
goto A;
break;
}
case 2:
{
patp();
goto A;
break;
}
case 3:

//calling function patp

{
padf();
goto A;
break;

//calling function padf

}
case 4:
{
route();
goto A;
break;

//calling function route

}
case 5:
{
exit(0);
//Closing programme
break;
}
default:
{
cout<<"wrong entry please enter again\n";
goto A;
}
}
}

You might also like