943,582 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 994
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 11th, 2008
-1

'*' to 'X'..................

Expand Post »
i have here a code.....

can anybody tell me how to change the '*' to 'X' when a user will input his desired seat.....

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int userInput();
int main()

{
clrscr();
int x,y;
const int row= 12,seat= 5;
char plane[row][seat];
cout<<"\t\tAirplane Seat Arrangement"<<endl;
cout<<"\tA\tB\tC\tD\tE\tF"<<endl;
{for (y=1;y<=13;y++)
{ cout<<"Row "<<y<<"\t";
{for(x=0;x<=5;x++)
{ plane[y][x]='*';
cout<<plane[y][x]<<"\t";
}
cout<<endl;
}
}
}
userInput();
cout<<"Congratulations!! You Now Have A Seat...."
<<" Happy Trip!!!";

getch();
return 0;
}

int userInput()
{int tt,tr,nsa;
int a,b;
const int row= 12,seat= 5;
char plane[row][seat];
char tc;
char A=1;
char B=2;
char C=3;
char D=4;
char E=5;
char F=6;
cout<<"\nEnter TICKET TYPE [1]First Class [2]Economy Class : ";
cin>>tt;
switch(tt)
{case 1:
{
{cout<<"Enter TICKET [1-2]ROW NUMBER : ";
cin>>tr;
{ if ((tr>=1)&&(tr<=2))
cout<<"Input Accepted..."<<endl<<endl;
else
cout<<"Invalid Input!!!"<<endl<<endl;
cout<<"Note : Letter is CASE SENSITIVE!!!"<<endl;
cout<<"Enter TICKET [A-F]COLUMN LETTER : ";
cin>>tc;
if ((tc>='A')&&(tc<='F'))
cout<<"Input Accepted..."<<endl<<endl;
else
cout<<"Invalid Input!!!"<<endl<<endl; }
}
{
for (a=0;a<=2;a++)
for (b=0;b<=5;b++)
plane[a][b] ='X'; }
cout<<plane[a][b];
}
break;
case 2:
{cout<<"[1]Non-Smoking Area [2]Smoking Area : ";
cin>>nsa;
switch(nsa)
{case 1:
{cout<<"Enter TICKET [3-7]ROW NUMBER : ";
cin>>tr;
{ if ((tr>=3)&&(tr<=7))
cout<<"Input Accepted..."<<endl<<endl;
else
cout<<"Invalid Input!!!"<<endl<<endl;
cout<<"Note : Letter is CASE SENSITIVE!!!"<<endl;
cout<<"Enter TICKET [A-F]COLUMN LETTER : ";
cin>>tc;
if ((tc>='A')&&(tc<='F'))
cout<<"Input Accepted..."<<endl<<endl;
else
cout<<"Invalid Input!!!"<<endl<<endl;
} }break;
case 2:
{cout<<"Enter TICKET [8-13]ROW NUMBER : ";
cin>>tr;
{ if ((tr>=8)&&(tr<=13))
cout<<"Input Accepted..."<<endl<<endl;
else
cout<<"Invalid Input!!!"<<endl<<endl;
cout<<"Note : Letter is CASE SENSITIVE!!!"<<endl;
cout<<"Enter TICKET [A-F]COLUMN LETTER : ";
cin>>tc;
if ((tc>='A')&&(tc<='F'))
cout<<"Input Accepted..."<<endl<<endl;
else
cout<<"Invalid Input!!!"<<endl<<endl;
}break;
default:
cout<<"INVALID INPUT!!!"<<endl;break;
} }
}
default:
cout<<"INVALID INPUT!!!"<<endl;break;
}
return userInput();
}
Reputation Points: 6
Solved Threads: 0
Light Poster
sniper29 is offline Offline
48 posts
since Jun 2008
Jun 11th, 2008
0

Re: '*' to 'X'..................

how can i change the ' * ' if a user inputs

his desired seat.... and change it to ' x '.....
Reputation Points: 6
Solved Threads: 0
Light Poster
sniper29 is offline Offline
48 posts
since Jun 2008
Jun 11th, 2008
0

Re: '*' to 'X'..................

Ummm. What are you suposed to do?? what is the whole point of using a "*" then changing it to x?? can you put your question more clearly
Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007
Jun 11th, 2008
0

Re: '*' to 'X'..................

i am near to finish if i can do that......

for those who can help me....

thhank you...

(Airplane Seating Assignment) Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with 6 seats in each row. Rows 1 and 2 are first class; the remaining rows are economy class. Also, rows 1 through 7 are nonsmoking. Your program must prompt the user to enter the following information:

Here, * indicates that the seat is available; X indicates that the seat is occupied. Make this a menu-driven program; show the user’s choices and allow the user to make the appropriate choices.
Reputation Points: 6
Solved Threads: 0
Light Poster
sniper29 is offline Offline
48 posts
since Jun 2008
Jun 11th, 2008
0

Re: '*' to 'X'..................

why dont you use something like a "1" and "0"..if the seat is booked then set it to 1 else to 0..
Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007
Jun 11th, 2008
0

Re: '*' to 'X'..................

C++ Syntax (Toggle Plain Text)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<iomanip.h>
  4. int userInput();
  5. int main()
  6.  
  7. {
  8. clrscr();
  9. int x,y;
  10. const int row= 12,seat= 5;
  11. char plane[row][seat];
  12. cout<<"\t\tAirplane Seat Arrangement"<<endl;
  13. cout<<"\tA\tB\tC\tD\tE\tF"<<endl;
  14. {for (y=1;y<=13;y++)
  15. { cout<<"Row "<<y<<"\t";
  16. {for(x=0;x<=5;x++)
  17. { plane[y][x]='*';
  18. cout<<plane[y][x]<<"\t";
  19. }
  20. cout<<endl;
  21. }
  22. }
  23. }
  24. userInput();
  25. cout<<"Congratulations!! You Now Have A Seat...."
  26. <<" Happy Trip!!!";
  27.  
  28. getch();
  29. return 0;
  30. }
  31.  
  32. int userInput()
  33. {int tt,tr,nsa;
  34. int a,b;
  35. const int row= 12,seat= 5;
  36. char plane[row][seat];
  37. char tc;
  38. char A=1;
  39. char B=2;
  40. char C=3;
  41. char D=4;
  42. char E=5;
  43. char F=6;
  44. cout<<"\nEnter TICKET TYPE [1]First Class [2]Economy Class : ";
  45. cin>>tt;
  46. switch(tt)
  47. {case 1:
  48. {
  49. {cout<<"Enter TICKET [1-2]ROW NUMBER : ";
  50. cin>>tr;
  51. { if ((tr>=1)&&(tr<=2))
  52. cout<<"Input Accepted..."<<endl<<endl;
  53. else
  54. cout<<"Invalid Input!!!"<<endl<<endl;
  55. cout<<"Note : Letter is CASE SENSITIVE!!!"<<endl;
  56. cout<<"Enter TICKET [A-F]COLUMN LETTER : ";
  57. cin>>tc;
  58. if ((tc>='A')&&(tc<='F'))
  59. cout<<"Input Accepted..."<<endl<<endl;
  60. else
  61. cout<<"Invalid Input!!!"<<endl<<endl; }
  62. }
  63. {
  64. for (a=0;a<=2;a++)
  65. for (b=0;b<=5;b++)
  66. plane[a][b] ='X'; }
  67. cout<<plane[a][b];
  68. }
  69. break;
  70. case 2:
  71. {cout<<"[1]Non-Smoking Area [2]Smoking Area : ";
  72. cin>>nsa;
  73. switch(nsa)
  74. {case 1:
  75. {cout<<"Enter TICKET [3-7]ROW NUMBER : ";
  76. cin>>tr;
  77. { if ((tr>=3)&&(tr<=7))
  78. cout<<"Input Accepted..."<<endl<<endl;
  79. else
  80. cout<<"Invalid Input!!!"<<endl<<endl;
  81. cout<<"Note : Letter is CASE SENSITIVE!!!"<<endl;
  82. cout<<"Enter TICKET [A-F]COLUMN LETTER : ";
  83. cin>>tc;
  84. if ((tc>='A')&&(tc<='F'))
  85. cout<<"Input Accepted..."<<endl<<endl;
  86. else
  87. cout<<"Invalid Input!!!"<<endl<<endl;
  88. } }break;
  89. case 2:
  90. {cout<<"Enter TICKET [8-13]ROW NUMBER : ";
  91. cin>>tr;
  92. { if ((tr>=8)&&(tr<=13))
  93. cout<<"Input Accepted..."<<endl<<endl;
  94. else
  95. cout<<"Invalid Input!!!"<<endl<<endl;
  96. cout<<"Note : Letter is CASE SENSITIVE!!!"<<endl;
  97. cout<<"Enter TICKET [A-F]COLUMN LETTER : ";
  98. cin>>tc;
  99. if ((tc>='A')&&(tc<='F'))
  100. cout<<"Input Accepted..."<<endl<<endl;
  101. else
  102. cout<<"Invalid Input!!!"<<endl<<endl;
  103. }break;
  104. default:
  105. cout<<"INVALID INPUT!!!"<<endl;break;
  106. } }
  107. }
  108. default:
  109. cout<<"INVALID INPUT!!!"<<endl;break;
  110. }
  111. return userInput();
  112. }

You need to format and use code tags.


[code=cplusplus]
// paste code here
[/code]


Your code is very hard to read due to to the lack of indentation. You also have a whole bunch of extra brackets that do nothing. The compiler doesn't care about the extra brackets, but combined with the lack of indentation, it makes it hard to tell where code blocks begin and end.

You already have your array set up. When a person buys a seat, he/she will be assigned a row and a seat. '*' means the seat is empty, 'X' means it is taken. So when you reserve a seat at row myRowNum and seat mySeatNum, you'll do this:
C++ Syntax (Toggle Plain Text)
  1. plane[myRowNum][mySeatNum] = 'X';

Depending on how you want to organize your program, you'll need to change the userInput function so that it can somehow do something with that row and seat number once you get valid input. You'll either need to pass it your array or pass the row and seat numbers by reference so you can use them when the function returns to main(), or something similar.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,372 posts
since Jan 2008
Jun 11th, 2008
0

Re: '*' to 'X'..................

awhere will i put it?????

i had already tried it and it dont do anything....

will i put it after the row and seat number is entered????

im just a begginer hehehe.....

sori for my bad writing style on c++...
Reputation Points: 6
Solved Threads: 0
Light Poster
sniper29 is offline Offline
48 posts
since Jun 2008
Jun 11th, 2008
0

Re: '*' to 'X'..................

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void userInput();
int main()

{
clrscr();
int x,y;
const int row= 12,seat= 5;
char plane[row][seat];
cout<<"\t\tAirplane Seat Assignment"<<endl;
cout<<"\tA\tB\tC\tD\tE\tF"<<endl;
{for (y=1;y<=13;y++)
{ cout<<"Row "<<y<<"\t";
{for(x=0;x<=5;x++)
{ plane[y][x]='*';
cout<<plane[y][x]<<"\t";
}
cout<<endl;
}
}
}
userInput();
cout<<"Congratulations!! You Now Have A Seat...."
<<" Happy Trip!!!";

getch();
return 0;
}
void userInput()
{
const int row= 12,seat= 5;
char plane[row][seat];
int code = plane[row][seat];
int tt,nsa;
char tc;
char A=1;
char B=2;
char C=3;
char D=4;
char E=5;
char F=6;
cout<<"\nEnter TICKET TYPE [1]First Class [2]Economy Class : ";
cin>>tt;
switch(tt)
{
case 1:
{
cout<<"Enter TICKET [1-2]ROW NUMBER : ";
cin>>tt;
{ if((tt>=1)&&(tt<=2))
cout<<"Row Accepted"<<endl<<endl;
else
cout<<"Invalid"<<endl<<endl;
}
cout<<"Note : Letter is CASE SENSITIVE!!!"<<endl;
cout<<"Enter TICKET [A-F]COLUMN LETTER : ";
cin>>tc;
{ if ((tc>='A')&&(tc<='F'))
cout<<"Column Accepted"<<endl<<endl;
else
cout<<"Invalid"<<endl<<endl;
}
plane[tt][tc] = 'X';
cout<<plane<<endl;
} break;
case 2:
{
cout<<"Enter if [1]Non-Smoking Area or [2]Smoking Area : ";
cin>>nsa;
switch(nsa)
{
case 1:
{
cout<<"Enter TICKET [3-7]ROW NUMBER : ";
cin>>tt;
{ if((tt>=3)&&(tt<=7))
cout<<"Row Accepted"<<endl<<endl;
else
cout<<"Invalid"<<endl<<endl;
}
cout<<"Note : Letter is CASE SENSITIVE!!!"<<endl;
cout<<"Enter TICKET [A-F]COLUMN LETTER : ";
cin>>tc;
{ if ((tc>='A')&&(tc<='F'))
cout<<"Column Accepted"<<endl<<endl;
else
cout<<"Invalid"<<endl<<endl;
}
} break;
case 2:
{cout<<"Enter TICKET [8-13]ROW NUMBER : ";
cin>>tt;
{ if((tt>=8)&&(tt<=13))
cout<<"Row Accepted"<<endl<<endl;
else
cout<<"Invalid"<<endl<<endl;
}
cout<<"Note : Letter is CASE SENSITIVE!!!"<<endl;
cout<<"Enter TICKET [A-F]COLUMN LETTER : ";
cin>>tc;
{ if ((tc>='A')&&(tc<='F'))
cout<<"Column Accepted"<<endl<<endl;
else
cout<<"Invalid"<<endl<<endl;
}
} break;

}
} break;
default:
cout<<"INVALID"<<endl;break;
}
}


here now is my code......

and it output:
0x239f24dc

whats wrong with my code????
Reputation Points: 6
Solved Threads: 0
Light Poster
sniper29 is offline Offline
48 posts
since Jun 2008
Jun 11th, 2008
0

Re: '*' to 'X'..................

Lot's of things.

My first tip, never write more than a few lines, and clearly never more than a single action, without compiling and testing. By doing that you would find that you are overwriting your array and getting junk. Be sure you can initialize all elements of the variable plane to valid default values and display the state of the plane before you do anything else.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Jun 11th, 2008
1

Re: '*' to 'X'..................

Can you please use code tags and indent your code well for proper reading. I bet alot of people here are not trying to read the code because it is really not easy to read. Stop having the mentality that you are a newbie and you dont know anythin. Remeber people learn from their mistakes and if it has already been pointed out then please try to change. More infomation here and here. Please make a point to read both links
Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007

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: how do we create thread with visual studio for window
Next Thread in C++ Forum Timeline: EMERGENCY!!! I am having a meltdown...





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


Follow us on Twitter


© 2011 DaniWeb® LLC