the question is to be solved using loops,decisions and arrays!!


QUESTION:

Statement of question:

“AIRLINE RESERVATION"

Write a program to assign seats on a 10-seater plane. Your program should first ask a user to enter 1 for First Class and 2 for Economy class. First 5 seats are economy and last 5 seats are first class. Whenever a seat is reserved the program should display output that which seat ( from 1 to 10) was occupied and in which class.

USE A SINGLE SCPRITED ARRAY TO REPRESENT THE SEATING CHART. INITITALISE ALL ELEMETS TO 0 TO INDICATE THE SEATS ARE EMPTY AND WHEN RESERVED ASSIGN SEAT NUMBER TO 1.
Your program should never assign same seat twice!!!!
If first or economy class is full then your program should suggest the user the other class.
If both classes are full then your program should inform user that flight is full and suggest him to try on next flight.


now pls point out errors in my program one by one

#include <iostream.h>
#include <conio.h>
int main()
{
int arr[10]={0,0,0,0,0,0,0,0,0,0};
int a,i;

do{
cout<<"\nPlease Enter 1 for 'First Class' or 2 for 'Economy Class':";
cin>>a;

if ( a==1)
for ( i=0 ; i<=4 ; i++ )
	{
   if ( arr[i]== 0)
   	{arr[i]=1;
   	break;}
   }


else if ( a==2)

for ( i=5 ; i<=9 ; i++)
	{
   if ( arr[i]==0)
   {arr[i]=1;
   break;}
   }

else
cout<<"Input error!"<<endl;

for ( i=1 ; i<=10 ; i++)
cout<<arr[i]<<" ";
} while 
(arr[0]+arr[1]+arr[2]+arr[3]+arr[4]+arr[5]+arr[6]+arr[7]+arr[8]+arr[9]!=10);


getch();
return 0;}
for ( i=1 ; i<=10 ; i++ )
         cout<<arr[i]<<" ";

You went beyond array bounds. You should do this:

for ( i=0 ; i<10 ; i++ )
         cout<<arr[i]<<" ";

OK PEOPLE QUESTION SOLVED!!!!!!............thread closed!!!!!!1

heres the final answer: :D

#include <iostream.h>
#include <conio.h>
int main()
{
int arr[]={0,0,0,0,0,0,0,0,0,0};      //array initialised to zeros
int a,i;                             // loop variabe,i and class input,a


do{ cout<<"\nPlease Enter 1 for 'First Class' or 2 for 'Economy Class':";cin>>a;

if ( a==1)
for ( i=0 ; i<=4 ; i++ )
	{
   if ( arr[i]== 0)
   	{arr[i]=1;
   	break;}
   else if( arr[0]+arr[1]+arr[2]+arr[3]+arr[4]==5) 
           {cout<<"Class full, please choose '2' for Economy\n";break;}
   }


else if ( a==2)

for ( i=5 ; i<=9 ; i++)
	{
   if ( arr[i]==0)
   {arr[i]=1;
   break;}
   else if (arr[5]+arr[6]+arr[7]+arr[8]+arr[9]==5) 
        {cout<<"Class full, please choose '2' for Economy\n";break;}
   }

else
cout<<"Input error!"<<endl;

for ( i=0 ; i<10 ; i++)
cout<<arr[i]<<" ";
} while
(arr[0]+arr[1]+arr[2]+arr[3]+arr[4]+arr[5]+arr[6]+arr[7]+arr[8]+arr[9]!= 10);


cout<<"\nAll seats reserved. Next flight leaves in 3 hours";

getch();
return 0;}

ALL SUGGESTIONS 4 IMPROVEMENT OF SYNTAX, LOGIC etc R WELCOME!!!
:o

............................................................................

This article has been dead for over six months. Start a new discussion instead.