[text] bus management system

Viewer

copydownloadembedprintName: bus management system
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. char ch[10][130]={"Cardinal Express","Belgium Express","Aura Express","Chester Express","Newport Express","Ceres Express"};
  5. char name[32][100]={'\0'};
  6. char number[32][2]={'\0'};
  7. int num1[32]={0};
  8. int trno;
  9. void bus();//for list of bus
  10. void name_number(int booking,char numstr[100]);
  11. void booking();//for booking the tickets
  12. int read_number(int trno);//for reading the number from the file
  13. void read_name(int trno);//for reading the name from the file
  14. void status();//for printing the status by user input
  15. void status_1(int trno);//for printing the status while booking ticket
  16. void cancle();
  17.  
  18. int main()
  19. {
  20.         login();
  21.     int num,i;
  22.     do{
  23.     system("cls");
  24.     printf("\n\n\n");
  25.    printf("====================================== WELCOME TO BUS RESERVATION SYSTEM ======================================\n\n\n");
  26.     printf("\t\t\t\t\t[1]=> View Bus List\n");
  27.     printf("\n");
  28.     printf("\t\t\t\t\t[2]=> Book Tickets\n");
  29.     printf("\n");
  30.     printf("\t\t\t\t\t[3]=> Cancel Booking\n");
  31.     printf("\n");
  32.     printf("\t\t\t\t\t[4]=> Bus Status Board\n");
  33.     printf("\n");
  34.     printf("\t\t\t\t\t[5]=> Exit\n\n");
  35.     printf("===============================================================================================================\n\n");
  36.     printf("\t\t\tEnter Your Choice:: ");
  37.     scanf("%d",&num);
  38.     switch(num)
  39.     {
  40.     case 1:
  41.         bus();
  42.         break;
  43.     case 2:
  44.         booking();
  45.         break;
  46.     case 3:
  47.         cancle();
  48.         break;
  49.     case 4:
  50.         status();
  51.         break;
  52.     }
  53. getch();
  54.     }while(num != 5);
  55.     system("CLS");
  56.     printf("\t----------------------------------------------------------------------------------------------------------\n");
  57.     printf("\t\t\t\t\tThank You For Using This System\t\t\t\t\t\t\n");
  58.     printf("\t----------------------------------------------------------------------------------------------------------\n");
  59.     getch();
  60.     return 0;
  61. }
  62.  
  63.  
  64. void bus()
  65. {
  66.     system("cls");
  67.     printf("\n\n\n");
  68.     printf("=========================================== BUS RESERVATION SYSTEM ============================================\n\n\n");
  69.     printf("\t\t\t\t\t[1]  =>  %s\n",ch[0]);
  70.     printf("\n");
  71.     printf("\t\t\t\t\t[2]  =>  %s\n",ch[1]);
  72.     printf("\n");
  73.         printf("\t\t\t\t\t[3]  =>  %s\n",ch[2]);
  74.     printf("\n");
  75.         printf("\t\t\t\t\t[4]  =>  %s\n",ch[3]);
  76.     printf("\n");
  77.         printf("\t\t\t\t\t[5]  =>  %s\n",ch[4]);
  78. }
  79.  
  80. void booking()
  81. {
  82.  
  83.     int i=0;
  84.     char numstr[100];
  85. system("cls");
  86. printf("=========================================== BUS RESERVATION SYSTEM ============================================\n\n\n");//for entering train number
  87. bus();//for seeing train least
  88. printf("Enter the Bus number:--->");
  89. scanf("%d",&trno);
  90. system("cls");
  91. printf("=========================================== BUS RESERVATION SYSTEM ============================================\n\n\n");//for selecting coach
  92. printf("Your Bus Number is %d ********** %s",trno,ch[trno-1]);
  93. status_1(trno);
  94.  FILE *f1, *fopen();//for reading the seats from the user.
  95.  char str1[80]="32",str2[4],str3[4];
  96.  int seat1,seat2,booking=0;
  97. if(trno == 1)
  98. {
  99.  f1 = fopen("tr1.txt","r+");
  100.  fgets(str1,80,f1);
  101.  fclose(f1);
  102. }else if(trno == 2)
  103. {
  104.  f1 = fopen("tr2.txt","r+");
  105.  fgets(str1,80,f1);
  106.  fclose(f1);
  107. }else if(trno == 3)
  108. {
  109.  f1 = fopen("tr3.txt","r+");
  110.  fgets(str1,80,f1);
  111.  fclose(f1);
  112. }
  113. else if(trno == 4)
  114. {
  115.  f1 = fopen("tr4.txt","r+");
  116.  fgets(str1,80,f1);
  117.  fclose(f1);
  118. }
  119. else if(trno == 5)
  120. {
  121.  f1 = fopen("tr5.txt","r+");
  122.  fgets(str1,80,f1);
  123.  fclose(f1);
  124. }
  125. seat1=atoi(str1);//covert the string into number
  126. if(seat1 <= 0)
  127. {
  128.  printf("There is no blank seat in this bus ");
  129. }else
  130. {
  131. printf("\n\n\n\t\t\t\tAvailable Seats:------>%d\n",seat1);
  132. printf("\n\t\t\t\tNumber of Tickets:----->");
  133. scanf("%d",&booking);
  134. printf("\n");
  135.  
  136. seat1=seat1-booking;
  137. itoa(trno,numstr,10);
  138. name_number(booking,numstr);
  139. printf("\n\t\t\t\tThe Total booking amount is %d",10*booking);
  140. itoa(seat1, str1, 10);
  141.  
  142. if(trno == 1)
  143. {
  144.  f1 = fopen("tr1.txt","w");
  145.  fputs(str1,f1);
  146.  fclose(f1);
  147. }
  148. else if(trno == 2)
  149. {
  150.  f1 = fopen("tr2.txt","w");
  151.  fputs(str1,f1);
  152.   fclose(f1);
  153. }
  154. else if(trno == 3)
  155. {
  156.  f1 = fopen("tr3.txt","w");
  157.  fputs(str1,f1);
  158.   fclose(f1);
  159. }
  160. else if(trno == 4)
  161. {
  162.  f1 = fopen("tr4.txt","w");
  163.  fputs(str1,f1);
  164.   fclose(f1);
  165. }
  166. else if(trno == 5)
  167. {
  168.  f1 = fopen("tr5.txt","w");
  169.  fputs(str1,f1);
  170.  fclose(f1);
  171. }
  172. }
  173. }
  174.  
  175.  
  176.  
  177. void name_number(int booking,char numstr[100])
  178. {
  179. char tempstr[100],tempstr1[12]="status",tempstr2[12]="number";
  180. int number;
  181.     FILE *a,*b;
  182.     int i=0;
  183.    strcat(numstr,".txt");
  184.    strcat(tempstr1,numstr);
  185.    strcat(tempstr2,numstr);
  186.    a = fopen(tempstr1,"a");
  187.    b = fopen(tempstr2,"a");
  188. for(i=0; i<booking; i++)
  189. {
  190.     printf("============================Enter the details for ticket no %d============================\n\n\n",i+1);
  191.       printf("\t\t\t\tEnter the seat number:--->");
  192.       scanf("%d",&number);
  193.       printf("\t\t\t\tEnter the name of person:--->");
  194.       scanf("%s",name[number-1]);
  195.     printf("\n======================================================================================================\n\n");
  196.     printf("\n");
  197.       itoa(number, tempstr, 10);
  198.       fprintf(a,"%s ",name[number-1]);
  199.       fprintf(b,"%s ",tempstr);
  200.  
  201. }
  202. fclose(a);
  203. fclose(b);
  204. }
  205.  
  206.  
  207.  
  208. int read_number(int trno)
  209. {
  210. char tempstr[100],tempstr2[12]="number";
  211. FILE *a,*b;
  212. char numstr[100];
  213. int i=0,j=0,k;
  214. itoa(trno,numstr,10);
  215. strcat(numstr,".txt");
  216. strcat(tempstr2,numstr);
  217. a = fopen(tempstr2,"a+");
  218.    while(!feof(a))
  219.    {
  220.       number[i][j] = fgetc(a);
  221.  
  222.       if(number[i][j] == ' ')
  223.       {
  224.           j=0;
  225.           i++;
  226.       }
  227.       else
  228.       {
  229.       j++;
  230.       }
  231.    }
  232.    k=i;
  233.    for(i=0; i<k; i++)
  234.    {
  235.        num1[i] = atoi(number[i]);
  236.    }
  237.    fclose(a);
  238.    return k;
  239. }
  240.  
  241.  
  242. void read_name(int trno)
  243. {
  244. char tempstr1[12]="status";
  245. FILE *b;
  246. char numstr[100];
  247. int i=0,j=0,k=0;
  248. itoa(trno,numstr,10);
  249. strcat(numstr,".txt");
  250. strcat(tempstr1,numstr);
  251. b = fopen(tempstr1,"a+");
  252.    while(!feof(b))
  253.    {
  254.       name[i][j] = fgetc(b);
  255.  
  256.       if(name[i][j] == ' ')
  257.       {
  258.           j=0;
  259.           i++;
  260.       }
  261.       else
  262.       {
  263.         j++;
  264.       }
  265.  
  266.    }
  267.    name[i][j]='\0';
  268.    k=i;
  269.    fclose(b);
  270. }
  271.  
  272. void status()
  273. {
  274. system("cls");
  275. printf("=========================================== BUS RESERVATION SYSTEM ============================================\n\n\n");
  276.     int i,trno,index=0,j;
  277.     printf("Enter the number of bus:---->");
  278.     scanf("%d",&trno);
  279.     j=read_number(trno);
  280.     read_name(trno);
  281.     printf("____________________________________________________________________________________________________________________\n");
  282.     printf("                                      Bus.no-->%d---->%s                                                            \n",trno,ch[trno-1]);
  283.     printf("____________________________________________________________________________________________________________________\n");
  284.     char tempname[33][10]={"Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty "};
  285.     for(i=0; i<j; i++)
  286.     {
  287.         strcpy(tempname[num1[i]],name[i]);
  288.     }
  289.     for(i=0; i<8; i++)
  290.     {
  291.         printf("\t\t\t\t");
  292.         for(j=0; j<4; j++)
  293.             {
  294.         printf("%d.%s\t",index+1,tempname[index+1]);
  295.         index++;
  296.             }
  297.             printf("\n");
  298.     }
  299. }
  300.  
  301. void status_1(int trno)
  302. {
  303.     printf("Your Bus Number is %d ********** %s",trno,ch[trno-1]);
  304.     system("cls");
  305. printf("=========================================== BUS RESERVATION SYSTEM ============================================\n\n\n");
  306.     int i,index=0,j;
  307.     j=read_number(trno);
  308.     read_name(trno);
  309.     char tempname[33][10]={"Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty "};
  310.     for(i=0; i<j; i++)
  311.     {
  312.         strcpy(tempname[num1[i]],name[i]);
  313.     }
  314.     for(i=0; i<8; i++)
  315.     {
  316.         printf("\t\t\t\t");
  317.         for(j=0; j<4; j++)
  318.             {
  319.         printf("%d.%s\t",index+1,tempname[index+1]);
  320.         index++;
  321.             }
  322.             printf("\n");
  323. }
  324. }
  325.  
  326.  
  327. void cancle()
  328. {
  329.  int seat_no,i,j;
  330.  char numstr[100],tempstr2[15]="number",tempstr1[15]="status";
  331.  printf("Enter the bus number:---->");
  332.  scanf("%d",&trno);
  333.  itoa(trno,numstr,10);
  334.  strcat(numstr,".txt");
  335.  strcat(tempstr1,numstr);
  336.  strcat(tempstr2,numstr);
  337.  read_number(trno);
  338.  read_name(trno);
  339.  status_1(trno);
  340.  printf("Enter the seat number:--->");
  341.  scanf("%d",&seat_no);
  342.  FILE *a,*b;
  343.  a = fopen(tempstr1,"w+");
  344.  b = fopen(tempstr2,"w+");
  345.  for(i=0; i<32; i++)
  346.  {
  347.      if(num1[i] == seat_no)
  348.      {
  349.          for(j=0; j<32; j++)
  350.          {
  351.              if(num1[j] != seat_no && num1[j] != 0)
  352.              {
  353.                  fprintf(b,"%d ",num1[j]);
  354.                  fprintf(a,"%s",name[j]);
  355.              }
  356.              else if(num1[j] == seat_no && num1[j] != 0)
  357.              {
  358.                  strcpy(name[j],"Empty ");
  359.              }
  360.          }
  361.      }
  362.  }
  363. fclose(a);
  364. fclose(b);
  365. printf("\n\n");
  366.     printf("======================================================================================================\n");
  367.  printf("\t\t\t\tYour 10$ has been Returned\t\t\t\n");
  368.     printf("======================================================================================================\n");
  369. }
  370.  
  371.  
  372. void login()
  373. {
  374.         int a=0,i=0;
  375.     char uname[10],c=' ';
  376.     char pword[10],code[10];
  377.     char user[10]="admin";
  378.     char pass[10]="admin";
  379.     do
  380. {
  381.         system("cls");
  382.  
  383.     printf("\n  =========================  LOGIN FORM  =========================  ");
  384.     printf(" \n                       ENTER USERNAME:-");
  385.         scanf("%s", &uname);
  386.         printf(" \n                       ENTER PASSWORD:-");
  387.         while(i<10)
  388.         {
  389.             pword[i]=getch();
  390.             c=pword[i];
  391.             if(c==13) break;
  392.             else printf("*");
  393.             i++;
  394.         }
  395.         pword[i]='\0';
  396.  
  397.         i=0;
  398.  
  399.                 if(strcmp(uname,"admin")==0 && strcmp(pword,"admin")==0)
  400.         {
  401.         printf("  \n\n\n       WELCOME TO OUR SYSTEM !!!! LOGIN IS SUCCESSFUL");
  402.         printf("\n\n\n\t\t\t\tPress any key to continue...");
  403.         getch();//holds the screen
  404.         break;
  405.         }
  406.         else
  407.         {
  408.                 printf("\n        SORRY !!!!  LOGIN IS UNSUCESSFUL");
  409.                 a++;
  410.  
  411.                 getch();//holds the screen
  412.  
  413.         }
  414. }
  415.         while(a<=2);
  416.         if (a>2)
  417.         {
  418.                 printf("\nSorry you have entered the wrong username and password for four times!!!");
  419.  
  420.                 getch();
  421.  
  422.                 }
  423.                 system("cls");
  424. }
  425.  

Editor

You can edit this paste and save as new:


File Description
  • bus management system
  • Paste Code
  • 27 Apr-2024
  • 10.8 Kb
You can Share it: