about-text

SoftOSet is the most remarkable programming site. SoftOSet provides the fresh conceptual and professional programs, articles, books, and other interesting and technical writings. SoftOSet is the most reliable programming site to learn the programs and the basics of the popular programming languages. SoftOSet is the hub of the informative and research based articles.

Online Ticket Booking System Program in C Language


We already know how to make a ticket booking program in C++. Now we will explore how to build an online ticket booking system in C Language. C has remarkable feature of structure to model real world data in a combined form. We have just make use of the structure, switch case statements and some basic programming. So any one who has no expertise in programming can understand this ticket booking system.



Scenario:

A welcome message will print on the screen which allow the user to enter the method off his traveling, either by Airline, bus or train. User will select the method. Then user will asked to add his name and Id, traveling to where from where and then asked for account number. Then class in which he want to travel will be asked and after entering it. The total transportation fee will be print on screen of which 50%, user must have to be paid to confirm his Seat. If he paid more than 50% his seat number will be displayed to him.




Code

//Online ticket selling system using structure and switches and if else statements
//Date :1-2 February 2019
#include<stdio.h>
#include<string.h>

struct System{
char name[20];
char account[20];
char id[20];
char from[20];
char to[20];
    int total;
    int submit;
    int remain;

    
};
int main()
{
  struct  System pia,pr,dae;
char choice,cls;
printf("\n\t\tWelcome To the Online Ticket Buying System\n");
printf("********************************************************************************\n");
printf("\n\n\t\tEnter P for Air Traveling \n\n\t\tEnter R for Traveling By Train\n\n\t\tEnter D for Traveling by Daewoo Express\n");
printf("********************************************************************************\n");

scanf("%c",&choice);
switch(choice)
{
case 'P':
    case 'p':
    printf("\tWelcome in the Pakistan International Airlines Online Tickects Desk\n");
    printf("********************************************************************************\n");

    printf("\t  Enter Your Name\n");
    printf("\t******************\n");
    fflush(stdin);
    gets(pia.name);
    printf("********************************************************************************\n");

    printf("\n\t Enter Your ID Card Number\n");
    printf("\t****************************\n");
    fflush(stdin);
    gets(pia.id);
    printf("********************************************************************************\n");

    printf("Enter the City from which You are Traveling\n");
    printf("***********************************************\n");
    fflush(stdin);
gets(pia.from);
    printf("********************************************************************************\n");

    printf("Enter the City To which You are Traveling\n");
    printf("***********************************************\n");
fflush(stdin);
    gets(pia.to);
    printf("********************************************************************************\n");

    printf("Enter Your Account Number\n");
    printf("***********************************************\n");

    gets(pia.account);
    printf("********************************************************************************\n");

    printf("\t\tEnter E for Econmy class \n\t\tEnter S for Standard Class \n\t\tEnter V for VIP class\n");
        printf("********************************************************************************\n");

    scanf("%c",&cls);
    switch(cls)
          {
          case 'E':
          case 'e':
          printf("********************************************************************************\n");
          printf("\vTotal Transportation Fee for Economy Class from [%s] to [%s] is =12000\n",pia.from,pia.to);
              printf("********************************************************************************\n");

  break;
              
          case 'S':
          case 's':
          printf("********************************************************************************\n");

                    printf("\vTotal Transportation Fee for Economy Class from [%s] to [%s] is =20000\n",pia.from,pia.to);

              printf("********************************************************************************\n");

  break;
              
          case 'V':
          case 'v':
              printf("********************************************************************************\n");
                    printf("\vTotal Transportation Fee for Economy Class from [%s] to [%s] is =35000\n",pia.from,pia.to);

              printf("********************************************************************************\n");

  break;
          default:
              printf("********************************************************************************\n");

          printf("Enter the correct Class\n");
              printf("********************************************************************************\n");

          break;
      }
          printf("********************************************************************************\n");

      printf("\nEnter  Your Amount  to Submit 50 percent is Mandatory \n");
          printf("**************************************************\n");

      scanf("%d",&pia.submit);
          printf("********************************************************************************\n");

      if(cls=='E'||cls=='e')
      {
      pia.remain=12000-pia.submit;
      printf("\t\tYour Remaining Amount is %d",pia.remain);
                printf("********************************************************************************\n");

      if(pia.submit<6000)
      {
  
      printf("We are Not able to Issue the Ticket to you with %d \nPlease Submit at least 50 percent currently\n",pia.submit);
                printf("********************************************************************************\n");
}
      else
      {
  
      printf("\n\\t\tYour Seat is Successfull Booked \n\t\t\tYour Seat no is  25 of %c Class\n",cls);
                 printf("\t\tGood Luck For the Flight \n\t\tHope You will feel Comfortable with PIA\n");
                printf("********************************************************************************\n");

  }
  }
            if(cls=='S'||cls=='s')
      {
      pia.remain=20000-pia.submit;
      printf("Your Remaining Amount is %d",pia.remain);
                printf("********************************************************************************\n");

      if(pia.submit<10000)
      {
  
      printf("We are Not able to Issue the Ticket to you with %d\nPlease Submit at least 50 percent currently\n",pia.submit);
                printf("********************************************************************************\n");
}
  else{
  
      printf("\n\\t\tYour Seat is Successfull Booked \n\t\t\tYour Seat no is  25 of %c Class\n",cls);
                 printf("\t\tGood Luck For the Flight \n\t\tHope You will feel Comfortable with PIA\n");
                printf("********************************************************************************\n");

  }
  }
            if(cls=='V'||cls=='v')
      {
      pia.remain=35000-pia.submit;
      printf("Your Remaining Amount is %d",pia.remain);
                printf("********************************************************************************\n");

      if(pia.submit<17500)
    {
   printf("We are Not able to Issue the Ticket to you with %d \nPlease Submit at least 50 percent currently\n",pia.submit);
                printf("********************************************************************************\n");
}
  else{
  
      printf("\n\\t\tYour Seat is Successfull Booked \n\t\t\tYour Seat no is  25 of %c Class\n",cls);
                 printf("\t\tGood Luck For the Flight \n\t\tHope You will feel Comfortable with PIA\n");
                printf("********************************************************************************\n");

  }
  }
   
    break;
    case 'R':
    case 'r':
    printf("\tWelcome in the Pakistan Railways  Online Tickects Desk\n");
              printf("********************************************************************************\n");

    printf("\t    Enter Your Name\n");
    printf("\t*******************************\n");
fflush(stdin);
    gets(pr.name);
    printf("********************************************************************************\n");

    printf("\t  Enter Your ID Card Number\n");
      printf("\t*******************************\n");
    fflush(stdin);
    gets(pr.id);
printf("********************************************************************************\n");

    printf("\t  Enter the City from which You are Traveling\n");
            printf("\t**********************************************\n");

    gets(pr.from);
printf("********************************************************************************\n");

    printf("\t  Enter the City To which You are Traveling\n");
    printf("\t************************************************\n");

    gets(pr.to);
printf("********************************************************************************\n");

    printf("\t  Enter Your Account Number\n");
    printf("\t*******************************************\n");

    gets(pr.account);
    printf("********************************************************************************\n");

    printf("Enter E for Econmy class \nEnter S for Standard Class \nEnter V for VIP class\n");
    printf("********************************************************************************\n");

scanf("%c",&cls);
    switch(cls)
          {
          case 'E':
          case 'e':
          printf("Total Transportation Fee for Economy Class from %s to %s is =4000\n",pr.from,pr.to);
              printf("********************************************************************************\n");

  break;
              
          case 'S':
          case 's':
          printf("Total Transportation Fee for Economy Class from %s to %s is =7000\n",pr.from,pr.to);
          printf("********************************************************************************\n");

  break;
              
          case 'V':
          case 'v':
          printf("Total Transportation Fee for Economy Class from %s to %s is =10000\n",pr.from,pr.to);
          printf("********************************************************************************\n");

  break;
          default:
          printf("Enter the correct Class\n");
          break;
      }
      
      printf("\nEnter  Your Amount to Submit\n 50 percent is Mandatory \n");
      printf("********************************************************************************\n");

      scanf("%d",&pr.submit);
      if(cls=='E'||cls=='e')
      {
      pr.remain=4000-pr.submit;
      printf("\tYour Remaining Amount is %d",pr.remain);
      printf("********************************************************************************\n");

      if(pr.submit<2000)
     {
  printf("We are Not able to Issue the Ticket to you with %d\nPlease Submit at least 50 percent currently\n",pr.submit);
      printf("********************************************************************************\n");
}
  else{
  
      printf("\n\\t\tYour Seat is Successfull Booked \n\t\t\tYour Seat no is  25 of %c Class\n",cls);
                 printf("\t\tGood Luck For the Traveling\n\t\tHope You will feel Comfortable with Pakistan Railways\n");
      printf("********************************************************************************\n");

  }
  }
            if(cls=='S'||cls=='s')
      {
      pr.remain=7000-pr.submit;
      printf("\t   Your Remaining Amount is %d",pr.remain);
      printf("\t****************************************\n");

      if(pr.submit<3500)
    {
    printf("We are Not able to Issue the Ticket to you with %d\nPlease Submit at least 50 percent currently\n",pr.submit);
    printf("********************************************************************************\n");
}
else{
  
      printf("\n\\t\tYour Seat is Successfull Booked \n\t\t\tYour Seat no is  25 of %c Class\n",cls);
                 printf("\t\tGood Luck For the Traveling \n\t\tHope You will feel Comfortable with Pakistan Railways\n");
      printf("********************************************************************************\n");

  }
  }
            if(cls=='V'||cls=='v')
      {
      pr.remain=10000-pr.submit;
      printf("Your Remaining Amount is %d",pr.remain);
      printf("********************************************************************************\n");
 
  if(pr.submit<5000)
      {
  printf("We are Not able to Issue the Ticket to you with %d\nPlease Submit at least 50 percent currently\n",pr.submit);
    printf("********************************************************************************\n");
}
  else{
  
      printf("\n\\t\tYour Seat is Successfull Booked \n\t\t\tYour Seat no is  25 of %c Class\n",cls);
                 printf("\t\tGood Luck For the Traveling \n\t\tHope You will feel Comfortable with Pakistan Railways\n");
    printf("********************************************************************************\n");

  }
  }
   
    break;
    case 'D':
    case 'd':
    printf("\tWelcome in the Pakistan's Daewoo Express Online Tickects Desk\n");
    printf("********************************************************************************\n");

    printf("\t  Enter Your Name");
    printf("\t************************\n");
fflush(stdin);
    gets(dae.name);
    printf("********************************************************************************\n");

    printf("\t  Enter Your ID Card Number\n");
    printf("\t************************\n");

    fflush(stdin);
    gets(dae.id);
    printf("********************************************************************************\n");

    printf("\t  Enter the City from which You are Traveling\n");
    printf("\t******************************************************\n");

    gets(dae.from);
        printf("********************************************************************************\n");

    printf("\t  Enter the City To which You are Traveling\n");
    printf("\t  *************************************************\n");

    gets(dae.to);
    printf("********************************************************************************\n");

    printf("\t  Enter Your Account Number\n\n");
    printf("\t***********************************\n");

    gets(dae.account);
    printf("********************************************************************************\n");

    printf("Enter E for Econmy class \nEnter S for Standard Class \nEnter V for VIP class\n");
    printf("********************************************************************************\n");

    scanf("%c",&cls);
    switch(cls)
          {
          case 'E':
          case 'e':
          printf("Total Transportation Fee for Economy Class from %s to S is =4000\n",dae.from,dae.to);
              printf("********************************************************************************\n");
  break;
              
          case 'S':
          case 's':
            printf("Total Transportation Fee for Economy Class from %s to S is =7000\n",dae.from,dae.to);
              printf("********************************************************************************\n");

  break;
              
          case 'V':
          case 'v':
         
    printf("Total Transportation Fee for Economy Class from %s to S is =10000\n",dae.from,dae.to);
              printf("********************************************************************************\n");
  break;
          default:
          printf("Enter the correct Class\n");
          break;
      }
      printf("\n\t  Enter  Your Amount to Submit\n 50 percent is Mandatory \n");
    printf("\t********************************************************\n");

     scanf("%d",dae.submit);
    printf("********************************************************************************\n");

      if(cls=='E'||cls=='e')
      {
      dae.remain=4000-dae.submit;
      printf("\t  Your Remaining Amount is %d",dae.remain);
          printf("\t******************************************\n");

      if(dae.submit<2000)
     {
  printf("We are Not able to Issue the Ticket to you with %d\nPlease Submit at least 50 percent currently\n",dae.submit);
          printf("********************************************************************************\n");
}
  else{
  
      printf("\n\\t\tYour Seat is Successfull Booked \n\t\t\tYour Seat no is  25 of %c Class\n",cls);
                 printf("\t\tGood Luck For the Traveling \n\t\tHope You will feel Comfortable with Daewoo Express\n");
          printf("********************************************************************************\n");

  }
  }
            if(cls=='S'||cls=='s')
      {
      dae.remain=7000-dae.submit;
      printf("\t  Your Remaining Amount is %d",dae.remain);
          printf("\t********************************************\n");

      if(dae.submit<3500)
     {
  printf("We are Not able to Issue the Ticket to you with %d\nPlease Submit at least 50 percent currently\n",dae.submit);
          printf("********************************************************************************\n");
}
  else{
  
      printf("\n\\t\tYour Seat is Successfull Booked \n\t\t\tYour Seat no is  25 of %c Class\n",cls);
                 printf("\t\tGood Luck For the Traveling \n\t\tHope You will feel Comfortable with Daewoo Express\n");
      printf("********************************************************************************\n");
 
      }
  }
            if(cls=='V'||cls=='v')
      {
      dae.remain=10000-dae.submit;
 
      printf("\t  Your Remaining Amount is %d",dae.remain);
    printf("\t***************************************************\n");
    
  if(dae.submit<5000)
    {
  printf("We are Not able to Issue the Ticket to you with %d\nPlease Submit at least 50 percent currently\n",dae.submit);
        printf("********************************************************************************\n");
}
  else
      {
  
      printf("\n\\t\tYour Seat is Successfull Booked \n\t\t\tYour Seat no is  25 of %c Class\n",cls);
                 printf("\t\tGood Luck For the Travelling \n\t\tHope You will feel Comfortable with Daewoo Express\n");
    printf("********************************************************************************\n");
  
      }
  }
   
    break;
    default:
    printf("We don't have Tickets of %c Locally Purchase it \nor\n Select Form Our Menu \n",choice);
    break;
}
return 0;
}




Sample Output

and here are are the some sample output for this online ticket booking program.

In this use case we are booking the seat for P.I.A.










NOTE: 

This code is compiled on Dev C++ IDE so in order to gain the correct output use the same compiler. And if you are facing the difficulties in executing this code or any other code contact us, our team will surely help you.

Thank You

Post a Comment

Feel Free to Comment Us

Previous Post Next Post

Recents