Thank You

Pages: 123
closed account (1CohAqkS)
smoking and non smoking
Last edited on
closed account (3hM2Nwbp)
It's not my usual style to do this, but

Longer Version

http://www.cplusplus.com/forum/articles/1295/

Shorter Version

http://www.cplusplus.com/forum/articles/40071/
Last edited on
closed account (1CohAqkS)
please help me im new to C++ and especially to arrays............please help me........plz plz plz...
We'll happily help you, Skills, but only after you've shown to us that you've made an attempt yourself. Think of us as a last resort, not a go-to for problem solutions. :)

-Albatross
closed account (1CohAqkS)
I have written this program.......but it dosent work at some places...please help me.......
#include <stdio.h>
#include <string.h>

struct flight_date {
int day;
int month;
int year;
};

struct flight_time {
int hour;
int minute;
};

struct flight_information {
char flight_num[4];
struct flight_date date;
struct flight_time time;
char gate[2];
}flight_info;


main()
{
int seat[4][5] = {0};
int i,j,choice,num_of_seat,empty_seat=0,row,col,x=4,y=5,z=0;
int booking_id ;
char name[20];

strcpy(flight_info.flight_num, "AK65");
strcpy(flight_info.gate, "G9");
flight_info.date.day = 25;
flight_info.date.month = 12;
flight_info.date.year = 2008;
flight_info.time.hour = 23;
flight_info.time.minute = 45;

printf("------Airline Reservation Menu------\n\n\n");
printf("Press \"1\" -\tBooking\n");
printf("Press \"2\" -\tDisplay Seat Layout & Occupancy\n");
printf("Press \"3\" -\tExit\n");
printf("\nEnter your choice > ");
scanf("%d", &choice);
printf("\n");



switch (choice)
{
case 1:
printf("Amount of seat : ");
scanf("%d", &num_of_seat);

for (i=0; i<4; i++)
{
for (j=0; j<5; j++)
{
if (seat[i][j] == 0)
empty_seat += 1;
}
}
if (num_of_seat > empty_seat)
{
printf("Not enough seats available!\n");
break;
}
else
booking_id = 101;

fflush(stdin);
printf("Please enter your name : ");
scanf("%19[^\n]s", &name);

for (i=0; i<4; i++)
{
for (j=0; j<5; j++)
{
switch(num_of_seat)
{
case 1:
case 2:
case 3:
case 4:
case 5:
seat[i][num_of_seat-1] = booking_id;
break;
case 6:
seat[i+1][num_of_seat-5] = booking_id;
break;
}
}
}

printf("%d\t", seat[0][0]);
printf("%d\t", seat[0][1]);
printf("%d\t", seat[0][2]);
printf("%d\t", seat[0][3]);
printf("%d\t\n", seat[0][4]);

printf("%d\t", seat[1][0]);
printf("%d\t", seat[1][1]);
printf("%d\t", seat[1][2]);
printf("%d\t", seat[1][3]);
printf("%d\t\n", seat[1][4]);
printf("%d\n", booking_id);
break;
case 2:
seat[2][0] = 101;
printf("\tA\tB\tC\tD\tE\n");
for (row=0; row<4; row++)
{
printf("\n%d", row+1);
for (col=0; col<5; col++)
{
printf("\t%d", seat[row][col]);
}
}
break;
case 3:
printf("Bye bye !\nHave A Nice Day !");
break;
default:
printf("Unknown choice , please read the instructions again !");
}

printf("\n\n");
}
closed account (1CohAqkS)
please help me.................plzzzzzzzzzzzzzz help m cryn now plz plz plz.....
Skills wrote:
I have written this program.......but it dosent work at some places...please help me.......
Where are these places?

Please use code tags [code]Your code here[/code] (Right beside where you input your text. Below 'Format:' <>)
closed account (1CohAqkS)
ok guys i have done this and this is correct but i dont know how to do case 4 which is to retrieve seat information please help me my assigment is due in 2days time......please help......

#include <iostream>
#include<iomanip>
using namespace std;
int main ()
{string namez;
int option,roww;
int seat[13][5] = {0};
int i,j,choice,num_of_seat,empty_seat=0,row,col;
char name[20],column;
char opselect,ticketType,;
cout<<"\t\tFJ513 Seat Reservation"<<endl;
cout<<endl;
cout<<"\t1.Display Aircraft Seating Plan"<<endl;
cout<<"\t2.Reserve a Seat"<<endl;
cout<<"\t3.Retrieve Seat Information"<<endl;
cout<<"\t4.Quit"<<endl;
cout<<endl;
cout<<"enter your choice"<<endl;
cin>>option;
switch (option)
{
case 1:
printf("\tA\tB\tC\tD\tE\n");
for (row=0; row<13; row++)
{
printf("\nRow %d", row+1);
for (col=0; col<5; col++)
{
printf("\tx", seat[row][col]);
}}
system ("pause");
break;
case 2:
void getData(char& ticketType, int& row, char& column);
{
cout << "The airplane has 13 rows, with six seats in each row. " << endl;
cout << "Enter ticket type,\n"
<< "F for first class, \n"
<< "E for economy class:" << endl;
cin >> ticketType;
ticketType = static_cast<char>(toupper(ticketType));
switch(ticketType)
{
case 'F':
cout << "Row 1 and 4 are first class,\n" ;
break;
case 'E':
cout << "row 8 through 13 are economy class." << endl;
break;
}
cout << "Enter the row number you want to sit: " << endl ;
cin >> row;
cout << "Enter the seat number (from A to E). " << endl;
cin >> column;
cout<<"enter passenger name:"<<endl;
cin>> namez;
column = static_cast<char>(toupper(column));
}
void printForm(char form[][6], int row, char column);
{
int i, j;
cout << "* indicates that the seat is available; " << endl;
cout << setw(14) << "A" << setw(8) << "B" << setw(8) << "C"
<< setw(8) << "D" << setw(8) << "E"<< endl;
for(i = 0; i < 13; i++)
{
cout << left << setw(3) << "Row " << setw(2)<< i+1 ;
for(j = 0; j < 5; j++)
{
if(i == row - 1 && j == static_cast<int>(column)-65)
cout << right << setw(8) <<namez;
else
cout << right << setw(8) << "*";
}
cout << endl;
} }
system ("pause");
return 0;
}}
closed account (1CohAqkS)
cant any1 help me in doing this??plz be a human begin n help me.plz plz only case 3....plz plz plz.
I strongly suggest to use code tags see my post above

Did you ever compile it? After 'case 2' you have a function within the (main) function which is not allowed. Place those functions before main and call them accordingly.

For your 'case 4' (which is actually 'case 3') call printForm() is what you want? Like I said relocate and then call them.
closed account (1CohAqkS)
yes i have compiled it and it working uptil case 2. and plz can u help me in doing this please.
closed account (zb0S216C)
I do believe that you're defining a method within your case 2. This is not allowed. Place getData( ) outside of main( ). Then, within case 2, call getData( ).

P.S: Please use code tags. Without code tags, your code becomes harder to read.
Last edited on
Ok, I made it compile (not more! and since you don't like code tags...):

#include <iostream>
#include<iomanip>
#include<string>

using namespace std;

void getData(string &namez, char& ticketType, int& row, int& column)
{
cout << "The airplane has 13 rows, with six seats in each row. " << endl;
cout << "Enter ticket type,\n"
<< "F for first class, \n"
<< "E for economy class:" << endl;
cin >> ticketType;
ticketType = static_cast<char>(toupper(ticketType));
switch(ticketType)
{
case 'F':
cout << "Row 1 and 4 are first class,\n" ;
break;
case 'E':
cout << "row 8 through 13 are economy class." << endl;
break;
}
cout << "Enter the row number you want to sit: " << endl ;
cin >> row;
cout << "Enter the seat number (from A to E). " << endl;
cin >> column;
cout<<"enter passenger name:"<<endl;
cin >> namez;
column = static_cast<char>(toupper(column));
}

void printForm(const string &namez, int form[][5], int row, char column)
{
int i, j;
cout << "* indicates that the seat is available; " << endl;
cout << setw(14) << "A" << setw(8) << "B" << setw(8) << "C"
<< setw(8) << "D" << setw(8) << "E"<< endl;
for(i = 0; i < 13; i++)
{
cout << left << setw(3) << "Row " << setw(2)<< i+1 ;
for(j = 0; j < 5; j++)
{
if(i == row - 1 && j == static_cast<int>(column)-65)
cout << right << setw(8) <<namez;
else
cout << right << setw(8) << "*";
}
cout << endl;
}}

int main ()
{
int option;
do
{
string namez;
int roww;
int seat[13][5] = {0};
int i,j,choice,num_of_seat,empty_seat=0,row,col;
char name[20],column;
char opselect,ticketType;
cout<<"\t\tFJ513 Seat Reservation"<<endl;
cout<<endl;
cout<<"\t1.Display Aircraft Seating Plan"<<endl;
cout<<"\t2.Reserve a Seat"<<endl;
cout<<"\t3.Retrieve Seat Information"<<endl;
cout<<"\t4.Quit"<<endl;
cout<<endl;
cout<<"enter your choice"<<endl;
cin>>option;
switch (option)
{
case 1:
printf("\tA\tB\tC\tD\tE\n");
for (row=0; row<13; row++)
{
printf("\nRow %d", row+1);
for (col=0; col<5; col++)
{
printf("\tx", seat[row][col]);
}}
system ("pause");
break;
case 2:
getData(namez, ticketType, row,col);
break;
case 3:
printForm(namez, seat, row,col);
break;
default:
if(option != 4)
cout<<"invalid choice"<< endl;
}
} while(option != 4);

system ("pause");
return 0;
}
<sorry for misunderstanding>
Last edited on
What do you mean "since you don't like code tags"?

pardonnez-moi? Since the OP didn't use code tags and I didn't want to bother reformating all I omitted the code tags just like he did
Sorry, I misread your username (or didn't read it) and assumed it was the OP >_<
lol, this looks EXACTLY like an exam problem :P
closed account (1CohAqkS)
thnak you but there is a error in case 2.........plz help me.
Mixing different types with cin,
is not very safe. There is a thread about it here

http://www.cplusplus.com/forum/articles/6046/

Is a temporarily fix,.. in modified version of your code below I have replaced
I think you have to do it another way, or at least specify that the input to cin should be threated as a hex
when reading the seat information ( not obvious as the letter A - E can be either a hex number or text )

i.e replace

cin >> option;

with

cin >> hex >> option;


You should probably also change it a couple of other places (or even better have a look at the article link above)
The code below compile and works for me, but crashes if the name is a double name.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146

#include <stdio.h>
#include <string.h>
#include<iomanip>
#include <iostream>
#include <cstdlib>

using namespace std;

void getData(string &namez, char& ticketType, int& row, int& column);

struct flight_date 
{
  int day;
  int month;
  int year;
};

struct flight_time 
{
  int hour;
  int minute;
};

struct flight_information {
  char flight_num[4];
  struct flight_date date;
  struct flight_time time;
  char gate[2];
}  flight_info;


void
getData(string &namez, char& ticketType, int& row, int& column)
{
  cout << "The airplane has 13 rows, with six seats in each row. " << endl;
  cout << "Enter ticket type,\n"
       << "F for first class, \n"
       << "E for economy class:" << endl;
  cin >> ticketType;
  ticketType = static_cast<char>(toupper(ticketType));

  switch(ticketType)
    {
    case 'F':
      cout << "Row 1 and 4 are first class,\n" ;
      break;
    case 'E':
      cout << "row 8 through 13 are economy class." << endl;
      break;
    }
  cout << "Enter the row number you want to sit: " << endl ;
  cin >> row;
  cout << "Enter the seat number (from A to E). " << endl;
  cin >> column;
  cout<< "enter passenger name:"<<endl;
  cin  >> namez;
  //getline(cin, namez); // could also work

  column = static_cast<char>(toupper(column));
}

void printForm(const string &namez, int form[][5], int row, char column)
{
int i, j;
cout << "* indicates that the seat is available; " << endl;
cout << setw(14) << "A" << setw(8) << "B" << setw(8) << "C"
<< setw(8) << "D" << setw(8) << "E"<< endl;
for(i = 0; i < 13; i++)
{
cout << left << setw(3) << "Row " << setw(2)<< i+1 ;
for(j = 0; j < 5; j++)
{
if(i == row - 1 && j == static_cast<int>(column)-65)
cout << right << setw(8) <<namez;
else
cout << right << setw(8) << "*";
}
cout << endl;
}}

int main ()
{
int option;

 do
   {
     //   option = 0;
     string namez;
     int roww;
     int seat[13][5] = {0};
     int i,j,choice,num_of_seat,empty_seat=0,row,col;
     char name[20],column;
     char opselect,ticketType;
     cout<<"\t\tFJ513 Seat Reservation"<<endl;
     cout<<endl;
     cout<<"\t1.Display Aircraft Seating Plan"<<endl;
     cout<<"\t2.Reserve a Seat"<<endl;
     cout<<"\t3.Retrieve Seat Information"<<endl;
     cout<<"\t4.Quit"<<endl;
     cout<<endl;
     cout<<"enter your choice"<<endl;
     
     cout << __FILE__ << __LINE__ << " Reading option, option was =  " << option << endl;
     cin >> hex >> option;
     cout << __FILE__ << __LINE__ << " OPTION = " << option << endl;
     //   cout << __FILE__ << __LINE__ << " OPTION = " << option << endl;
     
     switch (option)
       {
       case 1:
	 printf("\tA\tB\tC\tD\tE\n");
	 for (row=0; row<13; row++)
	   {
	     printf("\nRow %d", row+1);
	     for (col=0; col<5; col++)
	       {
		 printf("\tx", seat[row][col]);
	       }
	   }
	 //	 system ("pause");
	 break;
       case 2:
	 getData(namez, ticketType, row,col);
	 break;
       case 3:
	 printForm(namez, seat, row,col);
	 break;
       default:
	 cout << __FILE__ << __LINE__ << " OPTION = " << option << endl;
	 cout<<"invalid choice"<< endl;
	 exit(-1);
	 /*
	 if(option != 4)
	   {
	     cout<<"invalid choice"<< endl;
	   }
	 */ //Not needed
       }
   } while(option != 4);
 
 // system ("pause");
 return 0;
}


closed account (zb0S216C)
there is a error in case 2

Posting the error you're receiving would help.
Pages: 123