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++


Yes, today we will explore how to build an online ticket booking system in C++. C++ has remarkable feature of the objects and classes to model the real world entities. But we have use none of these. 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<iostream>
using namespace std;
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()
{
    System pia,pr,dae;
char choice,cls;
cout<<"\n\t\tWelcome To the Online Ticket Buying System\n"<<endl;
cout<<"********************************************************************************"<<endl;
cout<<"\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"<<endl;
cout<<"********************************************************************************"<<endl;

cin>>choice;
switch(choice)
{
case 'P':
    case 'p':
    cout<<"\tWelcome in the Pakistan International Airlines Online Tickects Desk\n"<<endl;
    cout<<"********************************************************************************"<<endl;

    cout<<"\t  Enter Your Name"<<endl;
    cout<<"\t******************\n"<<endl;
    cin>>pia.name;
    cout<<"********************************************************************************"<<endl;

    cout<<"\n\t Enter Your ID Card Number"<<endl;
    cout<<"\t****************************"<<endl;
    fflush(stdin);
    cin>>pia.id;
    cout<<"********************************************************************************"<<endl;

    cout<<"Enter the City from which You are Traveling\n"<<endl;
    cout<<"***********************************************"<<endl;
    cin>>pia.from;
    cout<<"********************************************************************************"<<endl;

    cout<<"Enter the City To which You are Traveling\n"<<endl;
    cout<<"***********************************************"<<endl;

    cin>>pia.to;
    cout<<"********************************************************************************"<<endl;

    cout<<"Enter Your Account Number\n"<<endl;
    cout<<"***********************************************"<<endl;

    cin>>pia.account;
    cout<<"********************************************************************************"<<endl;

    cout<<"\t\tEnter E for Econmy class \n\t\tEnter S for Standard Class \n\t\tEnter V for VIP class\n"<<endl;
        cout<<"********************************************************************************"<<endl;

    cin>>cls;
    switch(cls)
          {
          case 'E':
          case 'e':
          cout<<"********************************************************************************"<<endl;
          cout<<"\vTotal Transportation Fee for Economy Class from ["<<pia.from<<"] to ["<<pia.to<<"] is =12000\n"<<endl;
              cout<<"********************************************************************************"<<endl;

  break;
              
          case 'S':
          case 's':
          cout<<"********************************************************************************"<<endl;

          cout<<"Total Transportation Fee for Standard Class from ["<<pia.from<<"] to ["<<pia.to<<"] is =20000\n"<<endl;
              cout<<"********************************************************************************"<<endl;

  break;
              
          case 'V':
          case 'v':
              cout<<"********************************************************************************"<<endl;
          cout<<"Total Transportation Fee for VIP Class from ["<<pia.from<<"] to ["<<pia.to<<"] is =35000\n"<<endl;
              cout<<"********************************************************************************"<<endl;

  break;
          default:
              cout<<"********************************************************************************"<<endl;

          cout<<"Enter the correct Class\n"<<endl;
              cout<<"********************************************************************************"<<endl;

          break;
      }
          cout<<"********************************************************************************"<<endl;

      cout<<"\nEnter  Your Amount  to Submit 50% is Mandatory \n"<<endl;
          cout<<"**************************************************"<<endl;

      cin>>pia.submit;
          cout<<"********************************************************************************"<<endl;

      if(cls=='E'||cls=='e')
      {
      pia.remain=12000-pia.submit;
      cout<<"\t\tYour Remaining Amount is "<<pia.remain<<endl;
                cout<<"********************************************************************************"<<endl;

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

  }
  }
            if(cls=='S'||cls=='s')
      {
      pia.remain=20000-pia.submit;
      cout<<"Your Remaining Amount is "<<pia.remain<<endl;
                cout<<"********************************************************************************"<<endl;

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

  }
  }
            if(cls=='V'||cls=='v')
      {
      pia.remain=35000-pia.submit;
      cout<<"Your Remaining Amount is "<<pia.remain<<endl;
                cout<<"********************************************************************************"<<endl;

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

  }
  }
   
    break;
    case 'R':
    case 'r':
    cout<<"\tWelcome in the Pakistan Railways  Online Tickects Desk\n"<<endl;
              cout<<"********************************************************************************"<<endl;

    cout<<"\t    Enter Your Name"<<endl;
    cout<<"\t*******************************"<<endl;

    cin>>pr.name;
    cout<<"********************************************************************************"<<endl;

    cout<<"\t  Enter Your ID Card Number"<<endl;
      cout<<"\t*******************************"<<endl;
    fflush(stdin);
    cin>>pr.id;
cout<<"********************************************************************************"<<endl;

    cout<<"\t  Enter the City from which You are Traveling"<<endl;
            cout<<"\t**********************************************"<<endl;

    cin>>pr.from;
cout<<"********************************************************************************"<<endl;

    cout<<"\t  Enter the City To which You are Traveling\n"<<endl;
    cout<<"\t************************************************"<<endl;

    cin>>pr.to;
cout<<"********************************************************************************"<<endl;

    cout<<"\t  Enter Your Account Number\n"<<endl;
    cout<<"\t*******************************************"<<endl;

    cin>>pr.account;
    cout<<"********************************************************************************"<<endl;

    cout<<"Enter E for Econmy class \nEnter S for Standard Class \nEnter V for VIP class\n"<<endl;
    cout<<"********************************************************************************"<<endl;

cin>>cls;
    switch(cls)
          {
          case 'E':
          case 'e':
          cout<<"Total Transportation Fee for Economy Class from ["<<pr.from<<"] to ["<<pr.to<<"] is =4000\n"<<endl;
              cout<<"********************************************************************************"<<endl;

  break;
              
          case 'S':
          case 's':
          cout<<"Total Transportation Fee for Standard Class from ["<<pr.from<<"] to ["<<pr.to<<"] is =7000\n"<<endl;
          cout<<"********************************************************************************"<<endl;

  break;
              
          case 'V':
          case 'v':
          cout<<"Total Transportation Fee for VIP Class from ["<<pr.from<<"] to ["<<pr.to<<"] is =10000\n"<<endl;
          cout<<"********************************************************************************"<<endl;

  break;
          default:
          cout<<"Enter the correct Class\n"<<endl;
          break;
      }
      
      cout<<"\nEnter  Your Amount to Submit\n 50% is Mandatory \n"<<endl;
      cout<<"********************************************************************************"<<endl;

      cin>>pr.submit;
      if(cls=='E'||cls=='e')
      {
      pr.remain=4000-pr.submit;
      cout<<"\tYour Remaining Amount is "<<pr.remain<<endl;
      cout<<"********************************************************************************"<<endl;

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

  }
  }
            if(cls=='S'||cls=='s')
      {
      pr.remain=7000-pr.submit;
      cout<<"\t   Your Remaining Amount is "<<pr.remain<<endl;
      cout<<"\t****************************************"<<endl;

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

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

  }
  }
   
    break;
    case 'D':
    case 'd':
    cout<<"\tWelcome in the Pakistan's Daewoo Express Online Tickects Desk\n"<<endl;
    cout<<"********************************************************************************"<<endl;

    cout<<"\t  Enter Your Name"<<endl;
    cout<<"\t************************"<<endl;

    cin>>dae.name;
    cout<<"********************************************************************************"<<endl;

    cout<<"\t  Enter Your ID Card Number"<<endl;
    cout<<"\t************************"<<endl;

    fflush(stdin);
    cin>>dae.id;
    cout<<"********************************************************************************"<<endl;

    cout<<"\t  Enter the City from which You are Traveling"<<endl;
    cout<<"\t******************************************************"<<endl;

    cin>>dae.from;
        cout<<"********************************************************************************"<<endl;

    cout<<"\t  Enter the City To which You are Traveling"<<endl;
    cout<<"\t  *************************************************"<<endl;

    cin>>dae.to;
    cout<<"********************************************************************************"<<endl;

    cout<<"\t  Enter Your Account Number\n"<<endl;
    cout<<"\t***********************************"<<endl;

    cin>>dae.account;
    cout<<"********************************************************************************"<<endl;

    cout<<"Enter E for Econmy class \nEnter S for Standard Class \nEnter V for VIP class\n"<<endl;
    cout<<"********************************************************************************"<<endl;

    cin>>cls;
    switch(cls)
          {
          case 'E':
          case 'e':
          cout<<"Total Transportation Fee for Economy Class from ["<<dae.from<<"] to ["<<dae.to<<"] is =4000\n"<<endl;
              cout<<"********************************************************************************"<<endl;
  break;
              
          case 'S':
          case 's':
          cout<<"Total Transportation Fee for Standard Class from ["<<dae.from<<"] to ["<<dae.to<<"] is =7000\n"<<endl;
              cout<<"********************************************************************************"<<endl;

  break;
              
          case 'V':
          case 'v':
         
  cout<<"Total Transportation Fee for VIP Class from ["<<dae.from<<"] to ["<<dae.to<<"] is =10000\n"<<endl;
              cout<<"********************************************************************************"<<endl;
  break;
          default:
          cout<<"Enter the correct Class\n"<<endl;
          break;
      }
      cout<<"\n\t  Enter  Your Amount to Submit\n 50% is Mandatory "<<endl;
    cout<<"\t********************************************************"<<endl;

      cin>>dae.submit;
    cout<<"********************************************************************************"<<endl;

      if(cls=='E'||cls=='e')
      {
      dae.remain=4000-dae.submit;
      cout<<"\t  Your Remaining Amount is "<<dae.remain<<endl;
          cout<<"\t******************************************"<<endl;

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

  }
  }
            if(cls=='S'||cls=='s')
      {
      dae.remain=7000-dae.submit;
      cout<<"\t  Your Remaining Amount is "<<dae.remain<<endl;
          cout<<"\t********************************************"<<endl;

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














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