Advertisement
SMASIF

Mid 1 Bus Problem

Jun 20th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #include<iostream>
  2. #include<iomanip>
  3. using namespace std ;
  4. class bus{
  5. private :
  6. string dep,arr ;
  7. int cap,av,id ;
  8. static int c;
  9. public :
  10. bus (): id(c ++),dep ("n/a" ),arr ("n/
  11. a"),cap (0) ,av(0 ){}
  12. ~bus (){}
  13. void readdata()
  14. {
  15. cin >>dep >>arr >>cap >>av ;
  16. }
  17. void showdata()
  18. {
  19. cout <<dep <<" "<<arr <<" "<<cap <<"
  20. "<<av <<endl ;
  21. }
  22. int getid ()
  23. {
  24. return id;
  25. }
  26. string getdep ()
  27. {
  28. return dep;
  29. }
  30. string getarr ()
  31. {
  32. return arr;
  33. }
  34. int getcap ()
  35. {
  36. return cap;
  37. }
  38. int getav ()
  39. {
  40. return av;
  41. }
  42. void selltic (int tic) ;
  43. };
  44. void bus :: selltic ( int tic )
  45. {
  46. if (av >= tic )
  47. {
  48. av = av - tic ;
  49. cout << "RESERVATIONS CONFIRMED."
  50. << endl ;
  51. }
  52. else
  53. cout << "NOT ENOUGH SEATS. TRY
  54. LATER!" << endl ;
  55. }
  56. int findbus (bus B[], int sz, string dep,
  57. string arr )
  58. {
  59. int item ;
  60. for (int i=0 ;i<sz ;i++)
  61. {
  62. if (B[i] .getdep () == dep && B
  63. [i].getarr () == arr)
  64. {
  65. item = i ;
  66. break ;
  67. }
  68. }
  69. return item ;
  70. }
  71. int bus ::c =101;
  72. int main ()
  73. {
  74. int n,i,t,index ;
  75. string a,d;
  76. cout << "Bangla-Indo Joint
  77. Transportation Venture Limited" << endl;
  78. cout << "Phase I : Bus
  79. Registration" <<endl ;
  80. cout << "Enter number of buses: " ;
  81. cin >>n ;
  82. bus B[ n];
  83. for (i= 0;i<n ;i++)
  84. {
  85. cout <<"Enter info of Bus "<< i
  86. +1<<":" ;
  87. B[ i].readdata() ;
  88. }
  89. cout << "Phase II : Tickets
  90. sale" <<endl ;
  91. while ( true)
  92. {
  93. cout <<"Enter Dep. and Arr. city
  94. and tickets: " ;
  95. cin >>d>> a>>t;
  96. if( d == "N/A" && a == "N/A" && t
  97. == 0)
  98. {
  99. break ;
  100. }
  101. else
  102. index = findbus (B,n,d,a );
  103. B[ index ].selltic ( t);
  104. }
  105. cout << right <<setw (6)<< "BUS ID"<< "
  106. "<<left <<setw
  107. (12)<< "DEPARTURE"<< left <<setw
  108. (10)<< "ARRIVAL" <<right <<setw
  109. (10)<< "CAPACITY"<< right <<setw
  110. (12)<< "AVAILABLE"<< endl ;
  111. for (i= 0;i<n ;i++)
  112. {
  113. cout <<right << setw (6)<< B[i]. getid
  114. ()<<" "<<left << setw( 12)<< B[i]. getdep
  115. ()<<left << setw( 10)<< B[i]. getarr
  116. ()<<right << setw (10)<< B[i] .getcap
  117. ()<<right << setw (12)<< B[i] .getav ()<< endl;
  118. }
  119. return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement