help clear mess in single-scripted array

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 27
Reputation: Der_sed is an unknown quantity at this point 
Solved Threads: 0
Der_sed Der_sed is offline Offline
Light Poster

help clear mess in single-scripted array

 
0
  #1
Nov 25th, 2004
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


  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;}
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 27
Reputation: Der_sed is an unknown quantity at this point 
Solved Threads: 0
Der_sed Der_sed is offline Offline
Light Poster

Re: help clear mess in single-scripted array

 
0
  #2
Nov 25th, 2004
firstly tell me y duz that 2 appear in the output

http://img.villagephotos.com/p/2004-8/807060/2.JPG
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,348
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: help clear mess in single-scripted array

 
0
  #3
Nov 25th, 2004
      for ( i=1 ; i<=10 ; i++ )
         cout<<arr[i]<<" ";
You went beyond array bounds. You should do this:
  1. for ( i=0 ; i<10 ; i++ )
  2. cout<<arr[i]<<" ";
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 27
Reputation: Der_sed is an unknown quantity at this point 
Solved Threads: 0
Der_sed Der_sed is offline Offline
Light Poster

Re: help clear mess in single-scripted array

 
0
  #4
Nov 25th, 2004
Thanx For Solvingproblem No.1 Dave!!!!
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 27
Reputation: Der_sed is an unknown quantity at this point 
Solved Threads: 0
Der_sed Der_sed is offline Offline
Light Poster

Re: help clear mess in single-scripted array

 
0
  #5
Nov 25th, 2004
OK PEOPLE QUESTION SOLVED!!!!!!............thread closed!!!!!!1

heres the final answer:


  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



............................................................................
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC