Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<iomanip>
- using namespace std ;
- class bus{
- private :
- string dep,arr ;
- int cap,av,id ;
- static int c;
- public :
- bus (): id(c ++),dep ("n/a" ),arr ("n/
- a"),cap (0) ,av(0 ){}
- ~bus (){}
- void readdata()
- {
- cin >>dep >>arr >>cap >>av ;
- }
- void showdata()
- {
- cout <<dep <<" "<<arr <<" "<<cap <<"
- "<<av <<endl ;
- }
- int getid ()
- {
- return id;
- }
- string getdep ()
- {
- return dep;
- }
- string getarr ()
- {
- return arr;
- }
- int getcap ()
- {
- return cap;
- }
- int getav ()
- {
- return av;
- }
- void selltic (int tic) ;
- };
- void bus :: selltic ( int tic )
- {
- if (av >= tic )
- {
- av = av - tic ;
- cout << "RESERVATIONS CONFIRMED."
- << endl ;
- }
- else
- cout << "NOT ENOUGH SEATS. TRY
- LATER!" << endl ;
- }
- int findbus (bus B[], int sz, string dep,
- string arr )
- {
- int item ;
- for (int i=0 ;i<sz ;i++)
- {
- if (B[i] .getdep () == dep && B
- [i].getarr () == arr)
- {
- item = i ;
- break ;
- }
- }
- return item ;
- }
- int bus ::c =101;
- int main ()
- {
- int n,i,t,index ;
- string a,d;
- cout << "Bangla-Indo Joint
- Transportation Venture Limited" << endl;
- cout << "Phase I : Bus
- Registration" <<endl ;
- cout << "Enter number of buses: " ;
- cin >>n ;
- bus B[ n];
- for (i= 0;i<n ;i++)
- {
- cout <<"Enter info of Bus "<< i
- +1<<":" ;
- B[ i].readdata() ;
- }
- cout << "Phase II : Tickets
- sale" <<endl ;
- while ( true)
- {
- cout <<"Enter Dep. and Arr. city
- and tickets: " ;
- cin >>d>> a>>t;
- if( d == "N/A" && a == "N/A" && t
- == 0)
- {
- break ;
- }
- else
- index = findbus (B,n,d,a );
- B[ index ].selltic ( t);
- }
- cout << right <<setw (6)<< "BUS ID"<< "
- "<<left <<setw
- (12)<< "DEPARTURE"<< left <<setw
- (10)<< "ARRIVAL" <<right <<setw
- (10)<< "CAPACITY"<< right <<setw
- (12)<< "AVAILABLE"<< endl ;
- for (i= 0;i<n ;i++)
- {
- cout <<right << setw (6)<< B[i]. getid
- ()<<" "<<left << setw( 12)<< B[i]. getdep
- ()<<left << setw( 10)<< B[i]. getarr
- ()<<right << setw (10)<< B[i] .getcap
- ()<<right << setw (12)<< B[i] .getav ()<< endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement