473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Stuck!! Not Far More Need Help!!

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.  
  7.     string seat[7][4];
  8.     int row,i,j;
  9.     char col,response,ok;
  10.  
  11.   for(int p=1;p<=7;p++){
  12. cout<<p;
  13.  
  14. seat[p][0];
  15. cout<<"\tA";
  16. seat[p][1];
  17. cout<<"\tB";
  18. seat[p][2];
  19. cout<<"\tC";
  20. seat[p][3];
  21. cout<<"\tD\n";
  22.  
  23. }
  24.  
  25.     do
  26.     {
  27.     cout << "\nPlease select seating: ";
  28.     cin >> row>>col;
  29.  
  30.     i = row-1;
  31.  
  32.     if (col=='A'||col=='a'){
  33.     j = 0;
  34.     }
  35.     if (col=='B'||col=='b'){
  36.     j = 1;
  37.     }
  38.     if (col=='C'||col=='c'){
  39.     j = 2;
  40.     }
  41.     if (col=='D'||col=='d'){
  42.     j = 3;
  43.     }
  44.  
  45.     if (seat[i][j]=="X"){
  46.     cout << "This seat has been taken. Please choose a new one." << endl << endl;
  47.  
  48.  
  49.       for(int p=1;p<=7;p++){
  50. cout<<p;
  51. seat[p][0];
  52. cout<<"\tA";
  53. seat[p][1];
  54. cout<<"\tB";
  55. seat[p][2];
  56. cout<<"\tC";
  57. seat[p][3];
  58. cout<<"\tD\n";
  59.     }
  60. }    else{
  61.  
  62.     switch(row){
  63.     case 1: if (col=='A'||col=='a'){
  64.             seat[0][0]="X";
  65.             }
  66.             else if (col=='B'||col=='b'){
  67.             seat[0][1]="X";
  68.             }
  69.             else if (col=='C'||col=='c'){
  70.             seat[0][2]="X";
  71.             }
  72.             else if (col=='D'||col=='d'){
  73.             seat[0][3]="X";
  74.             }
  75.     break;
  76.  
  77.     case 2: if (col=='A'||col=='a'){
  78.             seat[1][0]="X";
  79.             }
  80.             else if (col=='B'||col=='b'){
  81.             seat[1][1]="X";
  82.             }
  83.             else if (col=='C'||col=='c'){
  84.             seat[1][2]="X";
  85.             }
  86.             else if (col=='D'||col=='d'){
  87.             seat[1][3]="X";
  88.             }
  89.     break;
  90.  
  91.     case 3: if (col=='A'||col=='a'){
  92.             seat[2][0]="X";
  93.             }
  94.             else if (col=='B'||col=='b'){
  95.             seat[2][1]="X";
  96.             }
  97.             else if (col=='C'||col=='c'){
  98.             seat[2][2]="X";
  99.             }
  100.             else if (col=='D'||col=='d'){
  101.             seat[2][3]="X";
  102.             }
  103.     break;
  104.  
  105.     case 4: if (col=='A'||col=='a'){
  106.             seat[3][0]="X";
  107.             }
  108.             else if (col=='B'||col=='b'){
  109.             seat[3][1]="X";
  110.             }
  111.             else if (col=='C'||col=='c'){
  112.             seat[3][2]="X";
  113.             }
  114.             else if (col=='D'||col=='d'){
  115.             seat[3][3]="X";
  116.             }
  117.     break;
  118.  
  119.     case 5: if (col=='A'||col=='a'){
  120.             seat[4][0]="X";
  121.             }
  122.             else if (col=='B'||col=='b'){
  123.             seat[4][1]="X";
  124.             }
  125.             else if (col=='C'||col=='c'){
  126.             seat[4][2]="X";
  127.             }
  128.             else if (col=='D'||col=='d'){
  129.             seat[4][3]="X";
  130.             }
  131.     break;
  132.  
  133.     case 6: if (col=='A'||col=='a'){
  134.             seat[5][0]="X";
  135.             }
  136.             else if (col=='B'||col=='b'){
  137.             seat[5][1]="X";
  138.             }
  139.             else if (col=='C'||col=='c'){
  140.             seat[5][2]="X";
  141.             }
  142.             else if (col=='D'||col=='d'){
  143.             seat[5][3]="X";
  144.             }
  145.     break;
  146.  
  147.     case 7: if (col=='A'||col=='a'){
  148.             seat[6][0]="X";
  149.             }
  150.             else if (col=='B'||col=='b'){
  151.             seat[6][1]="X";
  152.             }
  153.             else if (col=='C'||col=='c'){
  154.             seat[6][2]="X";
  155.             }
  156.             else if (col=='D'||col=='d'){
  157.             seat[6][3]="X";
  158.             }
  159.     break;   
  160. }
  161.  
  162.       for(int p=1;p<=7;p++){
  163. cout<<p;
  164. seat[p][0];
  165. cout<<"\tA";
  166. seat[p][1];
  167. cout<<"\tB";
  168. seat[p][2];
  169. cout<<"\tC";
  170. seat[p][3];
  171. cout<<"\tD\n";}
  172.  
  173.     if (seat[0][0]=="X" && 
  174.     seat[1][0]=="X" &&
  175.     seat[2][0]=="X" &&
  176.     seat[3][0]=="X" &&
  177.     seat[4][0]=="X" &&
  178.     seat[5][0]=="X" && 
  179.     seat[6][0]=="X" &&
  180.     seat[0][1]=="X" &&
  181.     seat[1][1]=="X" &&
  182.     seat[2][1]=="X" &&
  183.     seat[3][1]=="X" &&
  184.     seat[4][1]=="X" &&
  185.     seat[5][1]=="X" &&
  186.     seat[6][1]=="X" &&
  187.     seat[0][2]=="X" &&
  188.     seat[1][2]=="X" &&
  189.     seat[2][2]=="X" &&
  190.     seat[3][2]=="X" &&
  191.     seat[4][2]=="X" &&
  192.     seat[5][2]=="X" &&
  193.     seat[6][2]=="X" &&
  194.     seat[0][3]=="X" &&
  195.     seat[1][3]=="X" &&
  196.     seat[2][3]=="X" &&
  197.     seat[3][3]=="X" &&
  198.     seat[4][3]=="X" &&
  199.     seat[5][3]=="X" &&
  200.     seat[6][3]=="X"){
  201.  
  202.  
  203.     system("pause");
  204.     return 0; 
  205.  
  206.     }else{
  207.  
  208.     do {
  209.  
  210.     cout << "Do you want to continue? [y/n]";
  211.     cin >> response;
  212.  
  213.     if(response=='y' || response=='n' || response=='N' || response=='Y'){
  214.     ok='e';
  215.     }
  216.     else{
  217.          ok='p';
  218.     }
  219.  
  220. }while(ok=='p');
  221. }
  222. }
  223.     }while(response=='y' || response =='Y');
  224.  
  225. system("pause");
  226. return 0;   
  227. }

ok so where went wrong?its suppose to show "x" after i choose d seat
Apr 3 '07 #1
5 1484
sicarie
4,677 Expert Mod 4TB
Please read the Posting Guidelines, especially concerning clear thread titles and posting full code.

I would recommend learning functions and code abstraction - if you cut everything out of your first do-while, you have almost nothing else in there. If you could abstract those calls, your main (and your overall program) would be much smaller.

In the first part of your program you make several calls like this:

seat[p][0];

but don't do anything with them. These can be removed.

Other than that, you need to ask a more specific question to get more help, there is quite a bit that can be changed in this code...
Apr 3 '07 #2
ohoh...ok sorry abt dat....
here's d q...

Questiom :-

write a program to assign passengers seats in an airplane. Assume a
small airplane with seat numbering as following:

1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D


The program should display the seat pattern, with an 'X' marking the seats
already assigned. For example, after seats 1A, 2B and 4C are taken, the display
should look like this:

1 x B C D
2 A X C D
3 A B C D
4 A B X D
5 A B C D
6 A B C D
7 A B C D


after displaying the seats available, the program prompts for the seat
desired, the user type in a seat, and then the display of availble seats
is updated. This continues until all the seats are filled or until the used
signals that the program should end.

If the user types in a seat that is already assigned, the program should
say that the seat is occupied ans ask for another choice.


my program will run but it wont display "x" but it does recognizes if the seat taken already
Apr 4 '07 #3
dubZ
7
ohoh...ok sorry abt dat....
here's d q...

Questiom :-

write a program to assign passengers seats in an airplane. Assume a
small airplane with seat numbering as following:

1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D


The program should display the seat pattern, with an 'X' marking the seats
already assigned. For example, after seats 1A, 2B and 4C are taken, the display
should look like this:

1 x B C D
2 A X C D
3 A B C D
4 A B X D
5 A B C D
6 A B C D
7 A B C D


after displaying the seats available, the program prompts for the seat
desired, the user type in a seat, and then the display of availble seats
is updated. This continues until all the seats are filled or until the used
signals that the program should end.

If the user types in a seat that is already assigned, the program should
say that the seat is occupied ans ask for another choice.


my program will run but it wont display "x" but it does recognizes if the seat taken already
Your seat array could be of type char rather than type string. I believe the second dimension (Y dimension) should be 5 to hold the row number in the first column. Then you know that column 1 will be "A's", column 2 will be "B's", etc. You should initialize the array to its default state (with no seats taken), then you can mark seats as being taken. When you are marking seats,I assume that you will never have to worry about the first column since it is just listing the row numbers.

Also, I agree with the previous post that suggests you should break this code down into seperate functions to do the job. It would make it much easier for you to follow and figure out what is going on or going wrong.
Apr 4 '07 #4
Adding a few functions to clean up your program would be very helpful. Some possible functions could include:
  • changing seat to display an 'X'
  • checking to see if a seat is occupied
  • checking to see if all seats are occupied
  • displaying the seat arrangement after each seat choice by the user


To essentially eliminate the need for the switch statement:
(the reason for 65 is thats the ascii code for 'A' - as such, you'd need to use toupper() if a lowercase letter is entered)

Expand|Select|Wrap|Line Numbers
  1. if (seat not taken)
  2.     seat[row-1][static_cast<int>(col - 65)] = 'X';

Also, it would be useful to make a function that checks if a seat is taken:

Expand|Select|Wrap|Line Numbers
  1. if (seats[row-1][static_cast<int>(col - 65)] == 'X') return true;
  2. else return false;
And a function to check if all seats are occupied: This function checks through easch seat in the array. If all (28) == 'X', then it returns true, implying all seats are taken.

Expand|Select|Wrap|Line Numbers
  1. int counter = 0;
  2.  
  3.     for (int i = 0; i < 7; i++)
  4.     {
  5.         for (int j = 0; j < 4; j++)
  6.              if (seat[row-1][static_cast<int>(col - 65)] = 'X') counter++;
  7.     }
  8.  
  9.     if (counter == 28) return true;
  10.     else return false;
Apr 4 '07 #5
huh? i dont quite understand dat...heh...oni 4th week of programming!! but thnks!! will really look into it...this q is frm walter savitch ...problem solving with c++...im doin their ques...d programmin projects...is there anywhere i can get d ans to chck wif wht i've done? the ques there are nice and challengin...but cant check it wif anywer...:(
Apr 4 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Paul Mendez | last post by:
I really need some help Date Code ConCAT Bal_Fwd NS_Fees Amt_Coll Cur_End_Bal 1/15/2004 KW 11KW2003 $500.00 $250.00 $250.00 2/15/2004 KW 12KW2003 $300.00 $500.00 ...
2
by: hillcountry74 | last post by:
Hi, I'm stuck with this regular expression from past 2 days. Desperately need help. I need a regular expression that will allow all characters except these *:~<>' This is my code in...
0
by: tgregg6 | last post by:
I need help with my problem I am stuck and I don't know what to do!!! The problem is: This program calculates the charges for DVD rentals where current releases cost $3.5 and all others cast $2.50....
1
by: flavourofbru | last post by:
Hi, I am stuck at a major part of the code in VC++. My algorithm is as follows: f_name = load(filename); //this also loads a text file. The text files contains numbers sepearted by tab....
1
by: =?Utf-8?B?VHJ1cHRpIERhbGlh?= | last post by:
Hi to all, I am new in this newsgroup and new to .NET also. I am creating an application where I have to perform Mail Merge from my program. I have created a form which contain RTB and user can...
2
by: silhutte75 | last post by:
Writing program to convert celcius to fahrenheit and vice versa. Have eliminated all errors but have four warnings and and stuck. Please help help help. snippet of code: printf("2. Please...
1
by: kev | last post by:
Ok, I am really stuck and I need help badly. If I create any file or folder on the server and run the php file it works with no problem. As soon as I copy a website from another server onto...
5
by: carl2k2 | last post by:
Ok, I need help with putting values of checkboxes in the code, Heres an example of how my form wil l look like: http://neohosting.org/files/aoxatrff1uts8fa08bvf.jpg Ok I wanted it so The...
1
by: NoviceDBLearner | last post by:
The SQL question I want to answer is: Get a list of the exhibitions and the number of artists in every exhibition. SELECT DISTINCT exhibitionname, COUNT(Artist) AS antal FROM Exhibition,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.