1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
#include <conio.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <GdiPlusGraphics.h>
#include <stdlib.h>
#include <dos.h>
static int p=0;
class a
{
char busn[5],driver[10],arrival[5],depart[5],from[10],to[10],
seat[8][4][10];
public:
void install();
void allotment();
void empty();
void show();
void avail();
void position(int i);
}bus[10];//here we declare the number of buses we can have.
void vline(char ch)
{
for (int i=200;i>0;i--)//Here i's value will depend on your computer.
cout << ch;
}
void a::install()
{
cout << "Enter bus no: ";
cin >> bus[p].busn;
cout << "\n Enter Driver's name: ";
cin >> bus[p].driver;
cout << "\n Arrival time: ";
cin >> bus[p].arrival;
cout << "\n Departure: ";
cin >> bus[p].depart;
cout << "\n From: \t\t\t";
cin >> bus[p].from;
cout << "\n To: \t\t\t";
cin >> bus[p].to;
bus[p].empty();
p++;
}
void a::allotment()
{
int seat;
char number[5];
top:
cout<<"Bus no: ";
cin>>number;
int n;
for(n=0;n<=p;n++)
{
if(strcmp(bus[n].busn,number)==0)
break;
}
while(n<=p)
{
cout<<"\n Seat number: ";
cin>>seat;
if (seat>32)
{
cout<<"\n There are only 32 seats available in this bus.";
}
else
{
if (strcmp(bus[n].seat[seat/4][(seat%4)-1],"Empty")==0)
{
cout<<"Enter passanger's name: ";
cin>>bus[n].seat[seat/4][(seat%4)-1];
break;
}
else
cout<<"The seat no. is already reserved.\n";
}
}
if (n>p)
{
cout<<"Enter correct bus no.\n";
goto top;
}
}
void a::empty()
{
for(int i=0;i<8;i++)
{
for(int j=0;j<4;j++)
{
strcpy(bus[p].seat[i][j],"Empty");
}
}
}
void a::show()
{
int n;
char number[5];
cout<<"Enter bus no: ";
cin>>number;
for(n=0;n<=p;n++)
{
if(strcmp(bus[n].busn,number)==0)
break;
}
while (n<=p)
{
vline('*');
cout<<" Bus no: \t"<<bus[n].busn
<<"\n Driver: \t"<<bus[n].driver<<"\t\t Arrival time:\t"
<<bus[n].arrival<<"\t Departure time:\t"<<bus[n].depart
<<"\n From:\t\t"<<bus[n].from<<"\t\t To: \t\t\t"<<
bus[n].to<<"\n";
vline('*');
bus[0].position(n);
int a=1;
for (int i=0;i<8;i++)
{
for(int j=0;j<4;j++)
{
a++;
if(strcmp(bus[n].seat[i][j],"Empty")!=0)
cout<<"\n The seat no "<<a-1<<" is reserved for "<<bus[n].seat[i][j]<<" .";
}
}break;
} if(n>p)
cout<<"enter correct bus no.";
}
void a::position(int l)
{
int s=0,p=0;
for(int i=0;i<8;i++)
{
cout<<"\n";
for(int j=0;j<4;j++)
{
s++;
if(strcmp(bus[l].seat[i][j],"Empty")==0)
{
cout.width(5);
cout.fill(' ');
cout<<s<<".";
cout.width(10);
cout.fill(' ');
cout<<bus[l].seat[i][j];
p++;
}
else
{
cout.width(5);
cout.fill(' ');
cout<<s<<".";
cout.width(10);
cout.fill(' ');
cout<<bus[l].seat[i][j];
}
}
}
cout <<"\n\n There are "<<p<<" seats empty in Bus No: "<<bus[l].busn;
}
void a::avail()
{
for(int n=0;n<p;n++)
{
vline('*');
cout<<"Bus no: \t"<<bus[n].busn<<"\nDriver: \t"<<bus[n].driver<<"\t\tArrival time:\t"<<bus[n].arrival<<"\tDeparture Time: \t"<<bus[n].depart<<"\n From: \t\t"<<bus[n].from<<"\t\t To: \t\t\t"<<bus[n].to<<"\n";
vline('*');
vline('_');
}
}
void main()
{
clrscr();
int w;
int gd=DETECT,gm;
initgraph(&gd,&gm,"d:\\tc\\bgi");//enter the path of ur c compiler where u installed it.
setbkcolor(GREEN);
while(1)
{
cout<<"\n\n\n\n";
cout<<"\t\t\t 1.Install\n\t\t\t 2.Reservation\n\t\t\t 3.Show \n\t\t\t 4.Buses Available. \n\t\t\t 5.Exit";
cout<<"\n\t\t\t Enter your choice:-> ";
cin>>w;
switch(w)
{
case 1:
bus[p].install();
break;
case 2:
bus[p].allotment();
break;
case 3:
bus[0].show();
break;
case 4:
bus[0].avail();
break;
case 5:
exit(0);
}
}
}
|