Note - Double Click to Copy Code Contact Us!

Online Bus booking and Reservation System using C++

Tech Doubility
Online Bus booking and Reservation System



  1. #include <conio.h>
  2. #include <cstdio>
  3. #include <iostream>
  4. #include <string.h>
  5. #include <cstdlib>
  6.  
  7. using namespace std;
  8.  
  9. static int p = 0;
  10.  
  11. class a
  12.  
  13. {
  14.  
  15. char busn[5], driver[10], arrival[5], depart[5], from[10], to[10], seat[8][4][10];
  16.  
  17. public:
  18.  
  19. void install();
  20.  
  21. void allotment();
  22.  
  23. void empty();
  24.  
  25. void show();
  26.  
  27. void avail();
  28.  
  29. void position(int i);
  30.  
  31. }
  32.  
  33. bus[10];
  34.  
  35. void vline(char ch)
  36.  
  37. {
  38.  
  39. for (int i=80;i>0;i--)
  40.  
  41. cout<<ch;
  42.  
  43. }
  44.  
  45. void a::install()
  46.  
  47. {
  48.  
  49. cout<<"Enter bus no: ";
  50.  
  51. cin>>bus[p].busn;
  52.  
  53. cout<<"\nEnter Driver's name: ";
  54.  
  55. cin>>bus[p].driver;
  56.  
  57. cout<<"\nArrival time: ";
  58.  
  59. cin>>bus[p].arrival;
  60.  
  61. cout<<"\nDeparture: ";
  62.  
  63. cin>>bus[p].depart;
  64.  
  65. cout<<"\nFrom: \t\t\t";
  66.  
  67. cin>>bus[p].from;
  68.  
  69. cout<<"\nTo: \t\t\t";
  70.  
  71. cin>>bus[p].to;
  72.  
  73. bus[p].empty();
  74.  
  75. p++;
  76.  
  77. }
  78.  
  79. void a::allotment()
  80.  
  81. {
  82.  
  83. int seat;
  84.  
  85. char number[5];
  86.  
  87. top:
  88.  
  89. cout<<"Bus no: ";
  90.  
  91. cin>>number;
  92.  
  93. int n;
  94.  
  95. for(n=0;n<=p;n++)
  96.  
  97. {
  98.  
  99. if(strcmp(bus[n].busn, number)==0)
  100.  
  101. break;
  102.  
  103. }
  104.  
  105. while(n<=p)
  106.  
  107. {
  108.  
  109. cout<<"\nSeat Number: ";
  110.  
  111. cin>>seat;
  112.  
  113. if(seat>32)
  114.  
  115. {
  116.  
  117. cout<<"\nThere are only 32 seats available in this bus.";
  118.  
  119. }
  120.  
  121. else
  122.  
  123. {
  124.  
  125. if (strcmp(bus[n].seat[seat/4][(seat%4)-1], "Empty")==0)
  126.  
  127. {
  128.  
  129. cout<<"Enter passanger's name: ";
  130.  
  131. cin>>bus[n].seat[seat/4][(seat%4)-1];
  132.  
  133. break;
  134.  
  135. }
  136.  
  137. else
  138.  
  139. cout<<"The seat no. is already reserved.\n";
  140.  
  141. }
  142.  
  143. }
  144.  
  145. if(n>p)
  146.  
  147. {
  148.  
  149. cout<<"Enter correct bus no.\n";
  150.  
  151. goto top;
  152.  
  153. }
  154.  
  155. }
  156.  
  157.  
  158. void a::empty()
  159.  
  160. {
  161.  
  162. for(int i=0; i<8;i++)
  163.  
  164. {
  165.  
  166. for(int j=0;j<4;j++)
  167.  
  168. {
  169.  
  170. strcpy(bus[p].seat[i][j], "Empty");
  171.  
  172. }
  173.  
  174. }
  175.  
  176. }
  177.  
  178. void a::show()
  179.  
  180. {
  181.  
  182. int n;
  183.  
  184. char number[5];
  185.  
  186. cout<<"Enter bus no: ";
  187.  
  188. cin>>number;
  189.  
  190. for(n=0;n<=p;n++)
  191.  
  192. {
  193.  
  194. if(strcmp(bus[n].busn, number)==0)
  195.  
  196. break;
  197.  
  198. }
  199.  
  200. while(n<=p)
  201.  
  202. {
  203.  
  204. vline('*');
  205.  
  206. cout<<"Bus no: \t"<<bus[n].busn
  207.  
  208. <<"\nDriver: \t"<<bus[n].driver<<"\t\tArrival time: \t"
  209.  
  210. <<bus[n].arrival<<"\tDeparture time:"<<bus[n].depart
  211.  
  212. <<"\nFrom: \t\t"<<bus[n].from<<"\t\tTo: \t\t"<<
  213.  
  214. bus[n].to<<"\n";
  215.  
  216. vline('*');
  217.  
  218. bus[0].position(n);
  219.  
  220. int a=1;
  221.  
  222. for (int i=0; i<8; i++)
  223.  
  224. {
  225.  
  226. for(int j=0;j<4;j++)
  227.  
  228. {
  229.  
  230. a++;
  231.  
  232. if(strcmp(bus[n].seat[i][j],"Empty")!=0)
  233.  
  234. cout<<"\nThe seat no "<<(a-1)<<" is reserved for "<<bus[n].seat[i][j]<<".";
  235.  
  236. }
  237.  
  238. }
  239.  
  240. break;
  241.  
  242. }
  243.  
  244. if(n>p)
  245.  
  246. cout<<"Enter correct bus no: ";
  247.  
  248. }
  249.  
  250. void a::position(int l)
  251.  
  252. {
  253.  
  254. int s=0;p=0;
  255.  
  256. for (int i =0; i<8;i++)
  257.  
  258. {
  259.  
  260. cout<<"\n";
  261.  
  262. for (int j = 0;j<4; j++)
  263.  
  264. {
  265.  
  266. s++;
  267.  
  268. if(strcmp(bus[l].seat[i][j], "Empty")==0)
  269.  
  270. {
  271.  
  272. cout.width(5);
  273.  
  274. cout.fill(' ');
  275.  
  276. cout<<s<<".";
  277.  
  278. cout.width(10);
  279.  
  280. cout.fill(' ');
  281.  
  282. cout<<bus[l].seat[i][j];
  283.  
  284. p++;
  285.  
  286. }
  287.  
  288. else
  289.  
  290. {
  291.  
  292. cout.width(5);
  293.  
  294. cout.fill(' ');
  295.  
  296. cout<<s<<".";
  297.  
  298. cout.width(10);
  299.  
  300. cout.fill(' ');
  301.  
  302. cout<<bus[l].seat[i][j];
  303.  
  304. }
  305.  
  306. }
  307.  
  308. }
  309.  
  310. cout<<"\n\nThere are "<<p<<" seats empty in Bus No: "<<bus[l].busn;
  311.  
  312. }
  313.  
  314. void a::avail()
  315.  
  316. {
  317.  
  318.  
  319. for(int n=0;n<p;n++)
  320.  
  321. {
  322.  
  323. vline('*');
  324.  
  325. cout<<"Bus no: \t"<<bus[n].busn<<"\nDriver: \t"<<bus[n].driver
  326.  
  327. <<"\t\tArrival time: \t"<<bus[n].arrival<<"\tDeparture Time: \t"
  328.  
  329. <<bus[n].depart<<"\nFrom: \t\t"<<bus[n].from<<"\t\tTo: \t\t\t"
  330.  
  331. <<bus[n].to<<"\n";
  332.  
  333. vline('*');
  334.  
  335. vline('_');
  336.  
  337. }
  338.  
  339. }
  340.  
  341. int main()
  342.  
  343. {
  344.  
  345. system("cls");
  346.  
  347. int w;
  348.  
  349. while(1)
  350.  
  351. {
  352.  
  353. //system("cls");
  354.  
  355. cout<<"\n\n\n\n\n";
  356.  
  357. cout<<"\t\t\t1.Install\n\t\t\t"
  358.  
  359. <<"2.Reservation\n\t\t\t"
  360.  
  361. <<"3.Show\n\t\t\t"
  362.  
  363. <<"4.Buses Available. \n\t\t\t"
  364.  
  365. <<"5.Exit";
  366.  
  367. cout<<"\n\t\t\tEnter your choice:-> ";
  368.  
  369. cin>>w;
  370.  
  371. switch(w)
  372.  
  373. {
  374.  
  375. case 1: bus[p].install();
  376.  
  377. break;
  378.  
  379. case 2: bus[p].allotment();
  380.  
  381. break;
  382.  
  383. case 3: bus[0].show();
  384.  
  385. break;
  386.  
  387. case 4: bus[0].avail();
  388.  
  389. break;
  390.  
  391. case 5: exit(0);
  392.  
  393. }
  394.  
  395. }
  396.  
  397. return 0;
  398.  
  399. }

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.