| | |
help clear mess in single-scripted array
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2004
Posts: 27
Reputation:
Solved Threads: 0
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
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
C++ Syntax (Toggle Plain Text)
#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;}
•
•
Join Date: Nov 2004
Posts: 27
Reputation:
Solved Threads: 0
firstly tell me y duz that 2 appear in the output
http://img.villagephotos.com/p/2004-8/807060/2.JPG
http://img.villagephotos.com/p/2004-8/807060/2.JPG
for ( i=1 ; i<=10 ; i++ )
cout<<arr[i]<<" "; C++ Syntax (Toggle Plain Text)
for ( i=0 ; i<10 ; i++ ) cout<<arr[i]<<" ";
•
•
Join Date: Nov 2004
Posts: 27
Reputation:
Solved Threads: 0
OK PEOPLE QUESTION SOLVED!!!!!!............thread closed!!!!!!1
heres the final answer:
ALL SUGGESTIONS 4 IMPROVEMENT OF SYNTAX, LOGIC etc R WELCOME!!!
:o
............................................................................
heres the final answer:
C++ Syntax (Toggle Plain Text)
#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
............................................................................
![]() |
Similar Threads
- How do I turn this into a single dimensional array? (C#)
- Putting Single numbers in each array (C++)
- Help (Java)
Other Threads in the C++ Forum
- Previous Thread: hi friends pls help me out
- Next Thread: Quit abruptly in MFC app
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






