944,052 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2703
  • C++ RSS
Nov 25th, 2004
0

help clear mess in single-scripted array

Expand Post »
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


C++ Syntax (Toggle Plain Text)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. int main()
  4. {
  5. int arr[10]={0,0,0,0,0,0,0,0,0,0};
  6. int a,i;
  7.  
  8. do{
  9. cout<<"\nPlease Enter 1 for 'First Class' or 2 for 'Economy Class':";
  10. cin>>a;
  11.  
  12. if ( a==1)
  13. for ( i=0 ; i<=4 ; i++ )
  14. {
  15. if ( arr[i]== 0)
  16. {arr[i]=1;
  17. break;}
  18. }
  19.  
  20.  
  21. else if ( a==2)
  22.  
  23. for ( i=5 ; i<=9 ; i++)
  24. {
  25. if ( arr[i]==0)
  26. {arr[i]=1;
  27. break;}
  28. }
  29.  
  30. else
  31. cout<<"Input error!"<<endl;
  32.  
  33. for ( i=1 ; i<=10 ; i++)
  34. cout<<arr[i]<<" ";
  35. } while
  36. (arr[0]+arr[1]+arr[2]+arr[3]+arr[4]+arr[5]+arr[6]+arr[7]+arr[8]+arr[9]!=10);
  37.  
  38.  
  39. getch();
  40. return 0;}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Der_sed is offline Offline
31 posts
since Nov 2004
Nov 25th, 2004
0

Re: help clear mess in single-scripted array

firstly tell me y duz that 2 appear in the output

http://img.villagephotos.com/p/2004-8/807060/2.JPG
Reputation Points: 10
Solved Threads: 0
Light Poster
Der_sed is offline Offline
31 posts
since Nov 2004
Nov 25th, 2004
0

Re: help clear mess in single-scripted array

      for ( i=1 ; i<=10 ; i++ )
         cout<<arr[i]<<" ";
You went beyond array bounds. You should do this:
C++ Syntax (Toggle Plain Text)
  1. for ( i=0 ; i<10 ; i++ )
  2. cout<<arr[i]<<" ";
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Nov 25th, 2004
0

Re: help clear mess in single-scripted array

Thanx For Solvingproblem No.1 Dave!!!!
Reputation Points: 10
Solved Threads: 0
Light Poster
Der_sed is offline Offline
31 posts
since Nov 2004
Nov 25th, 2004
0

Re: help clear mess in single-scripted array

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

heres the final answer:


C++ Syntax (Toggle Plain Text)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. int main()
  4. {
  5. int arr[]={0,0,0,0,0,0,0,0,0,0}; //array initialised to zeros
  6. int a,i; // loop variabe,i and class input,a
  7.  
  8.  
  9. do{ cout<<"\nPlease Enter 1 for 'First Class' or 2 for 'Economy Class':";cin>>a;
  10.  
  11. if ( a==1)
  12. for ( i=0 ; i<=4 ; i++ )
  13. {
  14. if ( arr[i]== 0)
  15. {arr[i]=1;
  16. break;}
  17. else if( arr[0]+arr[1]+arr[2]+arr[3]+arr[4]==5)
  18. {cout<<"Class full, please choose '2' for Economy\n";break;}
  19. }
  20.  
  21.  
  22. else if ( a==2)
  23.  
  24. for ( i=5 ; i<=9 ; i++)
  25. {
  26. if ( arr[i]==0)
  27. {arr[i]=1;
  28. break;}
  29. else if (arr[5]+arr[6]+arr[7]+arr[8]+arr[9]==5)
  30. {cout<<"Class full, please choose '2' for Economy\n";break;}
  31. }
  32.  
  33. else
  34. cout<<"Input error!"<<endl;
  35.  
  36. for ( i=0 ; i<10 ; i++)
  37. cout<<arr[i]<<" ";
  38. } while
  39. (arr[0]+arr[1]+arr[2]+arr[3]+arr[4]+arr[5]+arr[6]+arr[7]+arr[8]+arr[9]!= 10);
  40.  
  41.  
  42. cout<<"\nAll seats reserved. Next flight leaves in 3 hours";
  43.  
  44. getch();
  45. return 0;}




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



............................................................................
Reputation Points: 10
Solved Threads: 0
Light Poster
Der_sed is offline Offline
31 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: hi friends pls help me out
Next Thread in C++ Forum Timeline: Quit abruptly in MFC app





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC