| | |
'*' to 'X'..................
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2008
Posts: 48
Reputation:
Solved Threads: 0
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();
}
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();
}
•
•
Join Date: Jun 2008
Posts: 48
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Jan 2008
Posts: 3,828
Reputation:
Solved Threads: 501
C++ Syntax (Toggle Plain Text)
#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(); }
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)
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.
•
•
Join Date: Jun 2008
Posts: 48
Reputation:
Solved Threads: 0
#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????
#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????
•
•
Join Date: Jul 2005
Posts: 1,688
Reputation:
Solved Threads: 266
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.
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.
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
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
![]() |
Other Threads in the C++ Forum
- Previous Thread: how do we create thread with visual studio for window
- Next Thread: EMERGENCY!!! I am having a meltdown...
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






