C' Program For Railway Ticket Reservation System
C' Program For Railway Ticket Reservation System
1.0 Rational
This program is based on the Online RAILWAY ticket reservation system using C-
Programming It accepts and display data of online railway ticket reservations.
2.0 Aim of micro Project:
Develop a C-program to accept and display records for online RAILWAY ticket
reservation system.
1) Data Analysis
We have visited 4 to 5 Websites and collected sample of online Railway ticket
website by comparing all the sample we have finalized data:
• View train
• Book ticket
• View Reserved tickets
• Search ticket
• Exit
2) Algorithm:
• Case 1
Step1:-Start
Step2:- Define structure with member as name, gender,ticketno
Source, destination, price .
Step 3:-
• Case 2
Step1:Start.
Step2:Call to case 2.
Step3:Display Enter number of passengers.
Step4: Display Enter ticket details
Step5: Repeat step6 till i<num
Step6: Input and accept values for
variables.
Step7: Display passengers details entered
successfully.
Step8: Stop
• Case3
Step1:Start.
Step2: Call to case 3
Step3: Display ticket record.
Step4: Repeat step5 till i<num
Step5: Display all variables
increment I by 1
Go to step 4
Step6: Stop.
Case4:-
Step1:- Start
Step2:- Call to case 4
Step3:- Display Enter ticket no. To search.
Step4:- if (t[i].ticketno==tno)
Display all details and goto step5
Otherwise
Increment i by 1
Go to step4
else
Display entered ticket number is invalid
Case5:-
Step1:- Start
Step2:- Call to Case5
Step3:- Display do you want to exit
Step4:- if(ex=='y')
3) Implementation :
Program:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct ticket
{
char name[10];
char gender[10];
int ticketno;
char source[10];
char destination[10];
int price;
};
void main()
{
char username[10];
int password;
struct ticket t[5];
int i,us,pa,ch,tno,ex,num;
clrscr();
printf("**********Railway Ticket Reservation********\n");
printf("\n\t Enter the username:");
scanf("%s",&us);
printf("\n\t Enter the password:");
scanf("%d",&pa);
if(us=='a')
{
if(pa==12345)
{
clrscr();
printf("Logged in Successfully!!\n");
do
{
printf("\n\t\t\t *****Menu*****");
printf("\n 1.View Train \n 2.Book Ticket \n 3.View Reserved Tickets \n 4.Search Ticket \n 5.Exit");
printf("\n Enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("***********View Train************\n");
printf("\n--------------------------------------------------------------------------------");
printf("\n Train \t\t\tSource&Destinations \tcharges \t\tTime");
printf("\n--------------------------------------------------------------------------------");
printf("\nFast Train \tThane to CSMT \tRs.20 \t\t09:05 AM");
printf("\nSlow Train \tThane to CSMT \tRs.30 \t\t09:20 AM");
printf("\nExpress Train \tKalyan to Chennai \tRs.50 \t\t12:12 AM");
printf("\nRajdhani Express\tMumbai to Gujarat \tRs.1000 \t\t01:30 AM");
printf("\nSlow Train \tParel to Thane \tRs.20 \t\t01:45 AM");
break;
case 2:
printf("\n Enter the number of passengers:");
scanf("%d",&num);
printf("\n\t\t**** Enter ticket details****");
for(i=0;i<num;i++)
{
printf("\n Enter name:");
scanf("%s",&t[i].name);
printf("\n Enter gender:");
scanf("%s",&t[i].gender);
printf("\n Enter ticketno:");
scanf("%d",&t[i].ticketno);
printf("\n Enter source:");
scanf("%s",&t[i].source);
printf("\n Enter destination:");
scanf("%s",&t[i].destination);
printf("\n Enter price:");
scanf("%d",&t[i].price);
}
printf("\n Passenger details entered succesfully.");
break;
case 3:
printf("\n\t\t**** Ticket record***");
printf("\nName \tGender \t\t Ticket no \tSource \t\tDestination");
for(i=0;i<num;i++)
{
printf("\n%-12s",t[i].name);
printf("%-15s",t[i].gender);
printf("%-12d",t[i].ticketno);
printf("%-15s",t[i].source);
printf("%-30s",t[i].destination);
}
break;
case 4:
printf("\t\t******Search Ticket*****\n");
printf("\n Enter ticket no to search:");
scanf("%d",&tno);
for(i=0;i<5;i++)
{
if(t[i].ticketno==tno)
{
printf("\n\t Ticketno=%d",t[i].ticketno);
printf("\n\t Name=%s",t[i].name);
printf("\n\t Gender=%s",t[i].gender);
printf("\n\t source=%s",t[i].source);
printf("\n\t Destination=%s",t[i].destination);
printf("\n\t Price=%d",t[i].price);
}
else{
printf("\n\t Entered Ticket number is invalid\n");
break;
}
}
break;
case 5:
printf("Do you want to exit:(y/n)");
scanf("%s",&ex);
if(ex=='y')
{
exit(0);
}
else{
break;
}
default:
printf("\n Invalid choice");
}
printf("\n Do you want to continue:(1/2)");
scanf("%d",&ch);
}
while(ch==1);
}
else
{
printf("\n Incorrect password. Please try again");
}
}
else
{
printf("\n Incorrect username. Please try again");
}
getch();
}
3. Notes - 1
*************MENU*************
1.View Train
2.Book Ticket
3.View Reserved Tickets
4.Search Ticket
5.Exit
Enter your choice:1
***********View Train************
--------------------------------------------------------------------------------
Train Source&Destinations charges Time
--------------------------------------------------------------------------------
Fast Train Thane to CSMT Rs.20 09:05 AM
Slow Train Thane to CSMT Rs.30 09:20 AM
Express Train Kalyan to Chennai Rs.50 12:12 AM
Rajdhani Express Mumbai to Gujarat Rs.1000 01:30 AM
Slow Train Parel to Thane Rs.20 01:45 AM
Do you want to continue:(1/2)1
*************MENU*************
1.View Train
2.Book Ticket
3.View Reserved Tickets
4.Search Ticket
5.Exit
Enter your choice:2
Enter the number of passengers:2
Enter gender:male
Enter ticketno:3
Enter source:kalyan
Enter destination:nerul
Enter price:89
Enter name:Ruchita
Enter gender:Female
Enter ticketno:76
Enter source:Kalva
Enter destination:thane
Enter price:70
Ticketno=3
Name=Omkar
Gender=male
source=kalyan
Destination=nerul
Price=89
Entered Ticket number is invalid
Our application is used in real time ticket reservation in different Railway ticket
reservation websites such as IRCTC, Make my trip, Railyatri etc.