Vous êtes sur la page 1sur 14

1/19/2015

C++ProjectonRailwayTicketReservation

Chemistry,C++,Physics,Maths,Biology,SocialScience
Home
Biology
C++
Chemistry
IP
Maths
Physics
SocialScience

Home>C++>C++ProjectonRailwayTicketReservation
Typetexttosearchhere...

C++ProjectonRailwayTicketReservation
RailwayTicketReservation
C++
Project
Work
RAILWAYTICKETRESERVATION
Name:TaherShabbirHusainClass:XIIB
School:IndianPublicSchool
Year:20092010
Certifiedtobethebonafideworkdoneby
Mr./MissTAHERSHABBIRHUSSAINofclassXIIB
intheCOMPUTERLABduringtheyear20092010
DateP.G.T.inCOMPUTERSCIENCE
INDIANPUBLICSCHOOLSalmiyaKuwait
SubmittedforALLINDIASENIORSCHOOLCERTIFICATEPRACTICAL
ExaminationheldinCOMPUTERLABatINDIANPUBLICSCHOOL
Salmiya,Kuwait.
Examiner
Date
Seal
IwouldliketoexpressmysinceregratitudetocomputerscienceteacherMs.Latha.iVi.Sw.a.m,forher
http://projects.icbse.com/cpp346

1/14

1/19/2015

C++ProjectonRailwayTicketReservation

vitalsupport,guidanceandencouragementwithoutwhichthisprojectwouldnothavecomeforth.I
wouldalsoliketoexpressmygratitudetotheschoolforlettingmeusetheschoollaboratory.
S.No.ContentsPageNo.
I.Objective5
II.Introduction6
III.1Summary17
IV.Working8
V.1ProgramCode110
VI.Output29
TodevelopaC++projecttomanagearailwayticketreservationserviceusingobject
orientedprogramminganddatafilehandling.
TheC++programminglanguagewasdevelopedatAT&TBelllaboratoriesintheearlyigSosbyBiarne
Stroustrup.HefoundoutClackingforsimulatinganddecidedtoextendthelanguagebyadding
featuresfromhisfavouritelanguage.SimtaSjwasoneoftheearliestobjectorientedlanguages.Biarne
StroustrupcalleditCwithclassesoriginally.ThenameC++wascoinedbyRickMascittiwhere++is
theCincrementoperator.Eversinceitsbirth,C++evolvedtocopewithproblemsencounteredbyusers,
andthroughdiscussionsatAT&T.
Themajorreasonsforitssuccessisthesupportforobjectorientedprogramming,whichismostnearto
realworldsituations.
However,thematurationoftheC++languageisattestedby2recentevents:
TheformationofanANSI(AmericanNationalStandardInstitute)C++committee,and
ThepublicationoftheAnnotatedC++ReferenceManualbyEllisandStroustrup.Onecaneasilyjudge
theimportanceofC++asgiventhefollowinglines:
Objectorientedtechnologyisregardedastheultimateparadigmforthemodelingoftheinformationin
thedataoflogic.TheC++isnowshowntofulfillthisgoal.
Thisisaprojectbasedontrainreservation.Theprogramhelpsustoenter,displayoralterthedetailsof
differenttrains.
Moreover&mostimportantlytheprogramhelpsustoreserveorcancelatrainticket.
Theprogramalsohelpsustoknowthepresentstatusofareservedticket,i.e.whethertheticketis
confirmedornot.
Itincludesvariousfunctionprogramstodotheabovementionedtasks.
Datafilehandlinghasbeeneffectivelyusedintheprogram.
Thisprogramusestheconceptofobjectorientedprogramminganddatafilehandling.
Thedatabaseisacollectionofinterrelateddatatoservemultipleapplications.Thatisdatabaseprograms
createfilesofinformation.Soweseethatfilesareworkedwithmost,insidetheprogram.
DBMS
ThesoftwarerequiredforthemanagementofdataiscalledasDBMS.Ithas3models
Relationmodel
Hierarchicalmodel
Networkmodel
RELATIONALMODELItsbasedontheconceptonrelation.Relationisthetablethatconsistsofrows
andcolumns.Therowsofthetablearecalledtupleandthecolumnsofthetablearecalledattribute.
Numbersofrowsinthetableiscalledascardinality.Numberofcolumnsinthetableiscalledasdegree.
HIERARCHICALMODELInthistypeofmodel,wehavemultiplerecordsforeachrecord.Aparticular
recordhasoneparent
record.Nochidrecordcanexistwithoutparentrecord.Inthis,therecordsareorganizedintree(ike
http://projects.icbse.com/cpp346

2/14

1/19/2015

C++ProjectonRailwayTicketReservation

structure
NETWORKMODEL:Inthis,thedataisrepresentedbycollectionofrecordsandrelationshipis
representedby(inkorassociation.
CHARACTERISTICSOFDBMS:
Itreducestheredundancy
Reductionofdataininconsistency
Datasharing
Datastandardization
DIFFERENTTYPESOFFILES:BASEDONACCESS:
Sequentialfile
Serialfile
Random(directaccess)fileBASEDONSTORAGE:
Textfile
BinaryFile

//PROGRAMTRAINRESERVATION#indude<iostream.h>#include<conio.h>#include<string.h>#include<dos.h>#i

classtrain{
private:
inttrainno,nofafseat,nofasseat,noffsseat,nofacseat,nofssseat;chartrainname[60],startingpoint[60],destinati
train(){
trainno=0;
nofafseat=0;
nofasseat=0;
noffsseat=0;
nofacseat=0;
nofssseat=0;
strcpy(trainname,"/0");
strcpy(startingpoint,"/0");
strcpy(destination,"/0");
}
voidinput();//Toinputthedetailsvoiddisplay();//Todisplaythedetailsintreturntr();int

intreturnas();intreturnfs();intreturnac();intreturnss();
}tr;
inttrain::returntr(){
returntrainno;
}
inttrain::returnaf()
{
returnnofafseat;
}
inttrain::returnas(){
returnnofasseat;
}
inttrain::returnfs()
{
returnnoffsseat;
}
inttrain::returnac()
{
returnnofacseat;
}
inttrain::returnss()
{
returnnofssseat;
http://projects.icbse.com/cpp346

3/14

1/19/2015

C++ProjectonRailwayTicketReservation

}
11

voidtrain::input()
{
clrscr();
gotoxy(10,10);
cout<<"ENTERTHETRAINNUMBER";
gotoxy(57,10);
cin>>trainno;
gotoxy(10,12);
cout<<"ENTERTHENUMBEROFA/CFIRSTCLASSSEATS";
gotoxy(57,12);
cin>>nofafseat;gotoxy(10,14);
cout<<"ENTERTHENUMBEROFA/CSECONDCLASSSEATS";
gotoxy(57,14);
cin>>nofasseat;
gotoxy(10,16);
cout<<"ENTERTHENUMBEROFFIRSTCLASSSLEEPERSEATS";
gotoxy(57,16);
cin>>noffsseat;gotoxy(10,18);
cout<<"ENTERTHENUMBEROFA/CCHAIRCARSEATS";gotoxy(57,18);
cin>>nofacseat;
gotoxy(10,20);
cout<<"ENTERTHENUMBEROFSECONDCLASSSLEEPERSEATS";
gotoxy(57,20);
cin>>nofssseat;
gotoxy(10,22);
cout<<"ENTERTHETRAINNAME";
gotoxy(57,22);
gets(trainname);
gotoxy(10,24);
cout<<"ENTERTHESTARTINGPOINT";
gotoxy(57,24);

gets(startingpoint);gotoxy(10,26);
cout<<"ENTERTHEDESTINATION";
gotoxy(57,26);
gets(destination);

voidtrain::display(){
clrscr();
gotoxy(10,10);cout<<"TRAINNUMBER";gotoxy(47,10);
cout<<trainno;
gotoxy(10,12);cout<<"TRAINNAME";gotoxy(47,12);
puts(trainname);
gotoxy(10,14);
cout<<"NOOFA/CFIRSTCLASSSEATS";
gotoxy(47,14);
cout<<nofafseat;
gotoxy(10,16);
cout<<"NOOFA/CSECONDCLASSSEATS";
gotoxy(47,16);
cout<<nofasseat;
gotoxy(10,18);
cout<<"NOOFFIRSTCLASSSLEEPERSEATS";
gotoxy(47,18);
cout<<noffsseat;
gotoxy(10,20);
http://projects.icbse.com/cpp346

4/14

1/19/2015

C++ProjectonRailwayTicketReservation

cout<<"NOOFA/CCHAIRCLASSSEATS";
gotoxy(47,20);
cout<<nofacseat;
gotoxy(10,22);

cout<<"NOOFSECONDCLASSSLEEPERSEATS";
gotoxy(47,22);
cout<<nofssseat;
gotoxy(10,24);
cout<<"STARTINGPOINT";
gotoxy(47,24);
puts(startingpoint);
gotoxy(10,26);cout<<"DESTINATION";gotoxy(47,26);
puts(destination);
gotoxy(10,28);
cout<<"PRESSANYKEYTOCONTINUE";
getch();
}

classtickets
{
intresno,toaf,nofaf,toas,nofas,tofs,noffs,toac,nofac,toss,nofss,age;
charstatus[40],name[40];
public:
tickets();
voidreservation();
//Forticketreservation
voidcancellation();//Forticketcancellationintret();
voiddisplay();//Todisplayreservationdetails
}tick;

tickets::tickets(){
resno=0;
toaf=0;
nofaf=0;
toas=0;
nofas=0;

tofs=0;
noffs=0;
toac=0;
nofac=0;
toss=0;
nofss=0;
age=0;
strcpy(status,"/0");strcpy(name,"/0");
}

inttickets::ret()
{
returnresno;
}

voidtickets::display()
{
intf=0;clrscr();
ifstreamfn("Ticket1.dat",ios::out);fn.seekg(0);
if(!fn)
{
cout<<"ERRORINTHEFILE";
}
http://projects.icbse.com/cpp346

5/14

1/19/2015

C++ProjectonRailwayTicketReservation

X:
gotoxy(10,10);
cout<<"ENTERTHERESERVATIONNO";gotoxy(10,12);
intn;cin>>n;
while(!fn.eof())
{
fn.read((char*)&tick,sizeof(tick));

gotoxy(10,10);
if(n==resno)
{
clrscr();
f=1;
gotoxy(10,10);
cout<<"NAME";gotoxy(30,10);cout<<name;gotoxy(10,12);
cout<<"AGE";gotoxy(30,12);
cout<<age;
gotoxy(10,14);
cout<<"PRESENTSTATUS";
gotoxy(30,14);
cout<<status;gotoxy(10,16);
cout<<"RESERVATIONNUMBER";
gotoxy(30,16);
cout<<resno;
gotoxy(10,18);
cout<<"PRESSANYKEYTOCONTINUE";
getch();
}
}
if(f==0){
clrscr();
gotoxy(10,10);
cout<<"UNRECOGINIZEDRESERVATIONNO!!!WANNA
RETRY?(Y/N)";chara;
gotoxy(10,12);
cin>>a;
if(a==y||a==Y){
clrscr();
gotoX;
}
else{
gotoxy(10,12);
cout<<"PRESSANYKEYTOCONTINUE";getch();
}
}
fn.close();
}

voidtickets::reservation()
{
clrscr();
gotoxy(10,10);cout<<"RESERVATION";gotoxy(10,12);
cout<<"ENTERTHETRAINNO:";
inttno,f=0;cin>>tno;ofstreamfile;
ifstreamfin("Train1.dat",ios::out);fin.seekg(0);
if(!fin)
{
clrscr();
gotoxy(10,10);cout<<"ERRORINTHEFILE";
clrscr();
while(!fin.eof())
http://projects.icbse.com/cpp346

6/14

1/19/2015

C++ProjectonRailwayTicketReservation

{
fin.read((char*)&tr,sizeof(tr));intz;
z=tr.returntr();if(tno==z)
{
f=1;
nofaf=tr.returnaf();
nofas=tr.returnas();
noffs=tr.returnfs();
nofac=tr.returnac();
nofss=tr.returnss();
}
}
if(f==1)
{
file.open("Ticket1.dat",ios::app);
S:
clrscr();
gotoxy(10,10);cout<<"NAME:";
gets(name);
gotoxy(10,12);cout<<"AGE:";
cin>>age;clrscr();
gotoxy(10,10);
cout<<"SELECTTHECLASSWHICHYOUWISHTO
TRAVEL";gotoxy(10,12);
cout<<"1.A/CFIRSTCLASS";gotoxy(10,14);
cout<<"2.A/CSECONDCLASS";
gotoxy(10,16);
cout<<"3.FIRSTCLASSSLEEPER";
gotoxy(10,18);cout<<"4.A/CCHAIRCAR";
gotoxy(10,20);
cout<<"5.SECONDCLASSSLEEPER";
gotoxy(10,22);
cout<<"ENTERYOURCHOICE";gotoxy(30,22);
intc;cin>>c;switch(c){
case1:
toaf++;
resno=rand();if((nofaftoaf)>0)
{
strcpy(status,"confirmed");
gotoxy(10,24);
cout<<"STATUS";
gotoxy(30,24);
puts(status);
gotoxy(10,26);cout<<"RESERVATIONNO";
gotoxy(30,26);cout<<resno;
getch();
file.write((char*)&tick,sizeof(tick));break;

strcpy(status,"pending");
gotoxy(10,24);

cout<<"STATUS";
gotoxy(30,24);puts(status);
gotoxy(10,26);cout<<"RESERVATIONNO";
gotoxy(30,26);cout<<resno;
getch();
file.write((char*)&tick,sizeof(tick));break;
http://projects.icbse.com/cpp346

7/14

1/19/2015

C++ProjectonRailwayTicketReservation

case2:
toas++;
resno=rand();
if((nofastoas)>0)
{
strcpy(status,"confirmed");
gotoxy(10,24);
cout<<"STATUS";
gotoxy(30,24);
puts(status);
gotoxy(10,26);cout<<"RESERVATIONNO";
gotoxy(30,26);cout<<resno;
getch();
file.write((char*)&tick,sizeof(tick));break;

strcpy(status,"pending");
gotoxy(10,24);cout<<"STATUS";
gotoxy(30,24);
puts(status);
gotoxy(10,26);
cout<<"RESERVATIONNO";
gotoxy(30,26);
cout<<resno;
getch();
file.write((char*)&tick,sizeof(tick));break;
}

case3:
tofs++;resno=rand();
if((noffstofs)>0)
{
strcpy(status,"confirmed");
gotoxy(10,24);
cout<<"STATUS";
gotoxy(30,24);
puts(status);
gotoxy(10,26);cout<<"RESERVATIONNO";
gotoxy(30,26);cout<<resno;
getch();
file.write((char*)&tick,sizeof(tick));break;
}
else
{
strcpy(status,"pending");
gotoxy(10,24);
cout<<"STATUS";
gotoxy(30,24);
puts(status);
gotoxy(10,26);
cout<<"RESERVATIONNO";
gotoxy(30,26);
cout<<resno;
getch();
file.write((char*)&tick,sizeof(tick));break;
}
http://projects.icbse.com/cpp346

8/14

1/19/2015

C++ProjectonRailwayTicketReservation

case4:
toac++;
resno=rand();
if((nofactoac)>0)
{
strcpy(status,"confirmed");
gotoxy(10,24);
cout<<"STATUS";
gotoxy(30,24);
puts(status);
gotoxy(10,26);
cout<<"RESERVATIONNO";
gotoxy(30,26);
cout<<resno;
getch();
file.write((char*)&tick,sizeof(tick));break;
}
else
{
strcpy(status,"pending");
gotoxy(10,24);
cout<<"STATUS";
gotoxy(30,24);
puts(status);
gotoxy(10,26);cout<<"RESERVATIONNO";gotoxy(30,26);
cout<<resno;
getch();
file.write((char*)&tick,sizeof(tick));break;
}

case5:
toss++;resno=rand();if((nofsstoss)>0){
strcpy(status,"confirmed");
gotoxy(10,24);
cout<<"STATUS";
gotoxy(30,24);
puts(status);
gotoxy(10,26);cout<<"RESERVATIONNO";
gotoxy(30,26);cout<<resno;
getch();
file.write((char*)&tick,sizeof(tick));break;
}
else
{
strcpy(status,"pending");
gotoxy(10,24);
cout<<"STATUS";
gotoxy(30,24);
puts(status);
gotoxy(10,26);

cout<<"RESERVATIONNO";
gotoxy(30,26);
cout<<resno;
getch();
file.write((char*)&tick,sizeof(tick));break;
}
}
gotoxy(10,28);
cout<<"DOYOUWISHTOCONTINUEBOOKINGTICKETS(Y/N)?";gotoxy(57,30);charn;
http://projects.icbse.com/cpp346

9/14

1/19/2015

C++ProjectonRailwayTicketReservation

cin>>n;
if(n=='y'||n=='Y'){
gotoS;
}
}
}
if(f==0)
{
clrscr();
gotoxy(10,10);
cout<<"ERRORINTHETRAINNUMBERENTERED!!!";getch();
}
file.close();
}

voidtickets::cancellation()
{
clrscr();ifstreamfin;
fin.open("Ticket1.dat",ios::out);

ofstreamfile;
file.open("Temp1.dat",ios::app);
fin.seekg(0);
gotoxy(10,10);
cout<<"ENTERTHERESERVATIONNO";
intr,f=0;
cin>>r;
if(!fin)

cout<<"ERRORINTHEFILE!!!";
}
while(!fin.eof())
{
fin.read((char*)&tick,sizeof(tick));intz;
z=ret();if(z!=r)
{
file.write((char*)&tick,sizeof(tick));
}
if(z==r){
f=1;
}
}
file.close();fin.close();
remove("Ticket1.dat");rename("Temp1.dat","Ticket1.dat");
if(f==0){
gotoxy(10,12);
cout<<"NOSUCHRESERVATIONISMADE!!!PLEASE
RETRY ";
getch();

}
else
{
gotoxy(10,12);
cout<<"RESERVATIONCANCELLED";getch();
}
}

voidmain(){
intch,r=1000,j;
clrscr();
http://projects.icbse.com/cpp346

10/14

1/19/2015

C++ProjectonRailwayTicketReservation

gotoxy(33,22);
cout<<"WELCOME";
Z:
clrscr();gotoxy(25,8);
cout<<"RAILWAYTICKETRESERVATION";gotoxy(25,9);
cout<<"==========================";
gotoxy(20,15);cout<<"1.TRAINDETAILS";
gotoxy(20,17);
cout<<"2.UPDATETRAINDETAILS";
gotoxy(20,19);
cout<<"3.RESERVINGATICKET";
gotoxy(20,21);
cout<<"4.CANCELLINGATICKET";
gotoxy(20,23);
cout<<"5.DISPLAYTHEPRESENTTICKETSTATUS";
gotoxy(20,25);
cout<<"6.EXIT";
gotoxy(20,27);
cout<<"ENTERYOURCHOICE:";

cin>>ch;charn;
switch(ch){
case1:{
ifstreamfin("Train1.dat",ios::out);
fin.seekg(0);
clrscr();
if(!fin)
{
clrscr();
gotoxy(10,10);
cout<<"ERRORINTHEFILE!!!";
}
else{
clrscr();
while(!fin.eof()){
fin.read((char*)&tr,sizeof(tr));tr.display();
}
}
fin.close();gotoZ;
}
case2:
clrscr();
gotoxy(20,10);
cout<<"ENTERTHEPASSWORD";
cin>>j;
gotoxy(20,30);
cout<<"CHECKINGPLEASEWAIT
";
getch();

http://projects.icbse.com/cpp346

11/14

1/19/2015

C++ProjectonRailwayTicketReservation

{
Y:
ofstreamfout("Train1.dat",ios::app);tr.input();
fout.write((char*)&tr,sizeof(tr));
fout.close();
gotoxy(10,30);
cout<<"DOYOUWISHTOCONTINUEUPDATING?(Y/N)";
cin>>n;
if(n==y||n==Y)
gotoY;gotoZ;
}
else
gotoZ;

http://projects.icbse.com/cpp346

12/14

1/19/2015

C++ProjectonRailwayTicketReservation

case3:
tick.reservation();gotoZ;

case4:
tick.cancellation();gotoZ;

case5:
tick.display();gotoZ;

case6:
exit(0);
}
getch();

</stdlib></process></fstream></stdio></dos></string></conio></iostream>

Comments(1)Trackbacks(0)LeaveacommentTrackback
1.
saurabh
October7th,2010at14:29|#1
Reply|Quote
somecommentsagainstsomeofthestatementsregardingfilehandlingwouldbeveryusefulto
otherswhomayviewtheaboveprogram.
1. Notrackbacksyet.
Name(required)
EMail(willnotbepublished)(required)
Website

Subscribetocommentsfeed
SubmitComment

InformationPractices(IP)ProjectonTravelAgencyforClass12thBiologyProjectonUltravioletRays
Kindlysendandshareyourprojectstoadmin@icbse.com

ProjectWork
BiologyProjectonUltravioletRays
C++ProjectonReportCardMaking
C++ProjectonTelephoneDirectoryManagementSystem
C++ProjectonPayrollManagement
http://projects.icbse.com/cpp346

13/14

1/19/2015

C++ProjectonRailwayTicketReservation

MathematicsProjectonGeometryinRealLife

Archives
July2010
March2010
July2009
May2009
April2009
March2009

Tags
BankingC++ProjectFileC++ProjectFileStructureCBSEDisasterManagementProjectCBSEMathsProjectCBSEMathsProjectonProbabilityCBSE
MathsProjectTopicsCDCafeDisasterManagement

Project
CBSEMathsProjectClassIX
CBSEScienceProjectsClassIX
CBSESocialScienceProjects
CCEProjects

TopContributors
1. AbhisekDe
2. Abhyodayasiddhartha
3. GarimaBhardwaj
4. Saurabh
5. Swathi

Top
Copyright2010SchoolProjects

http://projects.icbse.com/cpp346

14/14

Vous aimerez peut-être aussi