sign up I login
 advanced
refer a friend - earn nickels!!

Ask & Discuss Questions with Community & Experts

Moderation Team
 90 chars left    advanced
Ask iit jee aieee pet cbse icse state board experts Expert Question: how to make a railway reservation program
Forum Index -> Computer Science like the article? email it to a friend.  
Author Message
aryeshvn (0)

New kid on the Block

Olaaa!! Perrrfect answer. 0  [0 rates]

aryeshvn's Avatar

total posts: 2    
offline Offline

i have prepared a c++ program but problem in allocating seats for pasengers in different bogies


once i book a ticket a seat no is given but same seat no is given for next user.


how to check avialibility

    
puneet (3568)

Forum Expert Blazing goIITian

Olaaa!! Perrrfect answer. 620  bad job dude!! I dont approve of this answer! 2  [858 rates]

puneet's Avatar

total posts: 1966    
offline Offline

hii


so wat is the problem ... u keep the number unique na .. like a21 , b21 etc,, this way u will solve the duplicate issue  u mentioend ..


cheers


 


Puneet Agrawal
IIT Delhi
 this reply: 0 points  (with Olaaa!! Perrrfect answer.   in 0 votes )   [?]
 
You have to be logged on to rate
  
adi_dev (181)

Hot goIITian

Olaaa!! Perrrfect answer. 33  [41 rates]

adi_dev's Avatar

total posts: 137    
offline Offline

Here is the program for you--



#include<iostream.h>

#include<conio.h>

#include<stdio.h>



struct rail

{



    int seatNo;

    int isEmpty;



}seat[67];



void reserve(int n);

int arrRowState[15];



void main()

{

    for(int i = 0 ; i <67 ; i++)

    {

       seat[i].seatNo=(i+1);

       seat[i].isEmpty=1;

    }

    for(i=0 ; i<13 ; i++)

       arrRowState[i]=5;



    arrRowState[13]=2;

    arrRowState[14]=67;



    char res='y';

    do

    {

        int n;

        clrscr();

        cout<<"Enter d no of seats u want to reserve : ";

        cin>>n;

        reserve(n);

        cout<<"





Do u want to reserve more seats?";

        res=getchar();

    }while(res!='n');

}



void reserve(int n)

{

    if(n>arrRowState[14])

    {

        cout<<"Too large group to accomodate";

        getch();

        return;

    }



    int flag=0;

    int seatbook;

    for(int i = 0 ; flag==0&&i<=13 ; i++)

    {

        if(arrRowState[i] >= n)

        {

            flag=1;

            //    cout<<"Following Seats Alloted";

            seatbook=(((i)*5)+(6-arrRowState[i]));

            for(int j = 0 ; j < n ; j++)

            {

                cout<<"

"<<seatbook+j<<"

";

                seat[(seatbook+j)].isEmpty=0;

            }

            arrRowState[i]=arrRowState[i]-n;

            arrRowState[14]=arrRowState[14]-n;

        }

    }

    if(flag==0)

    {

        while(n!=0)

        {

            int max,rowNo=0;

            max=arrRowState[0];

            for( int j = 0 ; j<14 ; j++)

            {

                if(arrRowState[j] > max)

                {

                    max=arrRowState[j];

                    rowNo=j;

                }



            }

            if(n>max)

            {

                n=n-max;

                seatbook=(((rowNo)*5)+(6-arrRowState[rowNo]));

                arrRowState[rowNo]=arrRowState[rowNo]-max;

                for( int j = 0 ; j<max ; j++)

                {

                   cout<<"

"<<(seatbook+j)<<"

";

                   seat[(seatbook+j)].isEmpty=0;

                }

            }

            else

            {

                reserve(n);

                n=0;

            }



        }



    }



    getch();

}


 




Hope it helps you.

 this reply: 10 points  (with Olaaa!! Perrrfect answer.   in 2 votes )   [?]
 
You have to be logged on to rate
  
 
Forum Index -> Computer Science
Go to:   

Top Offers for goIITians
Correspondence Courses
Brilliant Tutorials
Narayana Institute
Aakash Institute
Classroom/Crash Courses
Narayana - Kota , Delhi , Others
Brilliant Tutorials - Class , Crash
Aakash Institute - Medical , Engg
Online Test Series
Brilliant Tutorials
Narayana Institute
Aakash Institute
Mahesh Tutorials
AMITY      Sri Chaitanya