Lost universe of Programing
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Lost universe of Programing

USERNAME :- Forum Post:-114
 
HomePortalGalleryLatest imagesRegisterLog in

 

 Railway seat reservation question which comes in sapient

Go down 
AuthorMessage
Administrator
Admin
Admin
Administrator


Male
Number of posts : 160
Age : 38
Location : Lucknow
Job/hobbies : Software Engeener
What U like To do ? : Because Its Rock with me.
Registration date : 2008-01-06

Railway seat reservation question which comes in sapient Empty
PostSubject: Railway seat reservation question which comes in sapient   Railway seat reservation question which comes in sapient I_icon_minitime3/13/2008, 8:35 pm

Quote :
in a trian compartment there are 67 seats...13 rows of 5 (3 by2) setats and the last row has 2 sets. a person cannot book more than 5 seats. if
a person is bokin then it should be such that maximum people of the group get to sit in the same row.
Code:
#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();
}
Back to top Go down
https://aspx.forumotion.com
 
Railway seat reservation question which comes in sapient
Back to top 
Page 1 of 1
 Similar topics
-
» Question:How do I uninstall illegal software?

Permissions in this forum:You cannot reply to topics in this forum
Lost universe of Programing :: --=| SOURCE CODE |=-- :: C/C++ SOURCE CODE-
Jump to: