26-Seater Aircraft Reservation System

Guys, please help me with this. I don't know what to do.

Problem: Seat Reservation System
You are tasked to create a C++ program that will facilitate a seat reservation system for an Airplane Company with 26-seater aircrafts. The
seats are initialiazed using the letters of the alphabet making 26 seats available for passengers. Additional 2 seats at the first row in the right
wing are reserved for flight attendants. Thus, the entire aircraft passenger area consist of 7 rows with 4 columns. The program should continue to accept passengers until the plane is fully booked. Denote occupied seats with the asterisk(*) symbol and prompt a notification message each time the user tries to reserve a seat that has already been occupied. The program repeats until the user
types a period(.) to exit.

#include <iostream>
using namespace std;

void dispArrayValues(char Seat[][4],const int r, const int c);
void askReservation(char Seat[][4],const int r, const int c);
void Status(char Seat[][4],const int r, const int c);
void Space(char Seat[][4], const int c);



int main() {

const int r=7;
const int c=4;


char Seat[r][c] = {
'A','B','#','#',
'C','D','E','F',
'G','H','I','J',
'K','L','M','N',
'O','P','Q','R',
'S','T','U','V',
'W','X','Y','Z'};

dispArrayValues(Seat,r,c);
cout << endl;
Status(Seat,r,c);
askReservation(Seat,r,c);




return 0;
}



void dispArrayValues(char Seat[][4],const int r, const int c){

cout << "26-SEATER AIRCRAFT RESERVATION SYSTEM" << endl;
cout << endl;

for (int i=0;i<r;i++){
for (int j=0;j<c;j++){
cout << "[" << Seat[i][j] << "]";}
cout << endl;
}
}




void askReservation(char Seat[][4], const int r, const int c) {

char s;
char star='*';

do {
cout << endl;
cout << "\nType the letter of the seat you want to reserve or type a period(.) to exit the program: ";
cin >> s;
cout << endl;


for (int a=0;a<r;a++){
for (int b=0;b<c;b++){
if (Seat[a][b] == (toupper(s))){
Seat[a][b] = star; }
}
}
dispArrayValues(Seat,r,c);
Status(Seat,r,c);

}while(s != '.');

if(s=='.')
cout << "\nProgram Ends." << endl;
}




void Status(char Seat[][4], const int r, const int c){

int available;
int reserve=0;

available = ((r*c)-2);

for (int i=0;i<r;i++){
for (int j=0;j<c;j++){
if(Seat[i][j] == '*'){
reserve = reserve+1;
available = available -1;}}
}

cout << "\nStatus: " << reserve << " Seat(s) Reserved, " << available << " Seat(s) Available" << endl;

}


#include <iostream>
using namespace std;

void dispArrayValues(char Seat[][4],const int r, const int c);
void askReservation(char Seat[][4],const int r, const int c);
void Status(char Seat[][4],const int r, const int c);
void Space(char Seat[][4], const int c);



int main() {

const int r=7;
const int c=4;


char Seat[r][c] = {
'A','B','#','#',
'C','D','E','F',
'G','H','I','J',
'K','L','M','N',
'O','P','Q','R',
'S','T','U','V',
'W','X','Y','Z'};

dispArrayValues(Seat,r,c);
cout << endl;
Status(Seat,r,c);
askReservation(Seat,r,c);




return 0;
}



void dispArrayValues(char Seat[][4],const int r, const int c){

cout << "26-SEATER AIRCRAFT RESERVATION SYSTEM" << endl;
cout << endl;

for (int i=0;i<r;i++){
for (int j=0;j<c;j++){
cout << "[" << Seat[i][j] << "]";}
cout << endl;
}
}




void askReservation(char Seat[][4], const int r, const int c) {

char s;
char star='*';

do {
cout << endl;
cout << "\nType the letter of the seat you want to reserve or type a period(.) to exit the program: ";
cin >> s;
cout << endl;


for (int a=0;a<r;a++){
for (int b=0;b<c;b++){
if (Seat[a][b] == (toupper(s))){
Seat[a][b] = star; }
}
}
dispArrayValues(Seat,r,c);
Status(Seat,r,c);

}while(s != '.');

if(s=='.')
cout << "\nProgram Ends." << endl;
}




void Status(char Seat[][4], const int r, const int c){

int available;
int reserve=0;

available = ((r*c)-2);

for (int i=0;i<r;i++){
for (int j=0;j<c;j++){
if(Seat[i][j] == '*'){
reserve = reserve+1;
available = available -1;}}
}

cout << "\nStatus: " << reserve << " Seat(s) Reserved, " << available << " Seat(s) Available" << endl;

}


#include <iostream>
using namespace std;

void dispArrayValues(char Seat[][4],const int r, const int c);
void askReservation(char Seat[][4],const int r, const int c);
void Status(char Seat[][4],const int r, const int c);
void Space(char Seat[][4], const int c);



int main() {

const int r=7;
const int c=4;


char Seat[r][c] = {
'A','B','#','#',
'C','D','E','F',
'G','H','I','J',
'K','L','M','N',
'O','P','Q','R',
'S','T','U','V',
'W','X','Y','Z'};

dispArrayValues(Seat,r,c);
cout << endl;
Status(Seat,r,c);
askReservation(Seat,r,c);




return 0;
}



void dispArrayValues(char Seat[][4],const int r, const int c){

cout << "26-SEATER AIRCRAFT RESERVATION SYSTEM" << endl;
cout << endl;

for (int i=0;i<r;i++){
for (int j=0;j<c;j++){
cout << "[" << Seat[i][j] << "]";}
cout << endl;
}
}




void askReservation(char Seat[][4], const int r, const int c) {

char s;
char star='*';

do {
cout << endl;
cout << "\nType the letter of the seat you want to reserve or type a period(.) to exit the program: ";
cin >> s;
cout << endl;


for (int a=0;a<r;a++){
for (int b=0;b<c;b++){
if (Seat[a][b] == (toupper(s))){
Seat[a][b] = star; }
}
}
dispArrayValues(Seat,r,c);
Status(Seat,r,c);

}while(s != '.');

if(s=='.')
cout << "\nProgram Ends." << endl;
}




void Status(char Seat[][4], const int r, const int c){

int available;
int reserve=0;

available = ((r*c)-2);

for (int i=0;i<r;i++){
for (int j=0;j<c;j++){
if(Seat[i][j] == '*'){
reserve = reserve+1;
available = available -1;}}
}

cout << "\nStatus: " << reserve << " Seat(s) Reserved, " << available << " Seat(s) Available" << endl;

}



Last edited on
Could you use the code tags next time - much easier to read.

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
#include <iostream>
using namespace std;

void dispArrayValues(string Seat[][5]);
void askReservation(string Seat[][5]);
void Status(string Seat[][5]);


int main() {

string Seat[7][5] = {"[A]","[B]"," ","[#]","[#]",
"\n[C]","[D]"," ","[E]","[F]",
"\n[G]","[H]"," ","[I]","[J]",
"\n[K]","[L]"," ","[M]","[N]",
"\n[O]","[P]"," ","[Q]","[R]",
"\n[S]","[T]"," ","[U]","[V]",
"\n[W]","[X]"," ","[Y]","[Z]"};

dispArrayValues(Seat);
cout << endl;
Status(Seat);
askReservation(Seat);


return 0;
}

void dispArrayValues(string Seat[][5]){

cout << "26-SEATER AIRCRAFT RESERVATION SYSTEM" << endl;
cout << "Left Right" << endl;

for (int i=0;i<7;i++){
for (int j=0;j<5;j++){
cout << Seat[i][j];}
}
}

void askReservation(string Seat[][5]) {

string s;
string star="[*]";
cout << "\nType the letter (with open and close bracket []) of the seat you want to reserve: ";
cin >> s;

for (int a=0;a<7;a++){
for (int b=0;b<5;b++){
if (Seat[a][b] == s){
Seat[a][b] = star; }
}
}
}

void Status(string Seat[][5]){


cout << "\nStatus: " << << " Seat(s) Reserved, " << << "Seat(s) Available" << endl;

}


In the askReservation function I would use a a loop that ends either when the user types a '.' or all seats are reserved.

Thus, the entire aircraft passenger area consist of 7 rows with 4 columns.


Why do you use 5 columns? The same with the square brackets around the seat. Makes it more complicated.

I rather would define it like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
#define NUM_ROWS  7
  #define NUM_COLS  4

  string Seat[NUM_ROWS][NUM_COLS] = 
  {
    "A","B","#","#",
    "C","D","E","F",
    "G","H","I","J",
    "K","L","M","N",
    "O","P","Q","R",
    "S","T","U","V",
    "W","X","Y","Z"
  };
std::string seems like overkill for a simple seat array. char seems like it would be simpler.

lines 12-17: You're going to have problems comparing the first seat in each row because you've included the \n character in the string literal.

I agree with Thomas1965 that you should use a 7x4 array. Leave the center isle to your formatting procedure. It does not represent a seat.

I also agree that the [] do not belong as part of the user input or the seat array. You're just making the program user unfriendly. It's easy enough to format the [] when you display the seat array.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.



Last edited on
Even using multiple dimensions seems like overkill. I would leave the concept of rows to the formatting procedure as well.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void printSeats(const std::vector<char>& seats)
{
    for(int i = 0; i < seats.size(); ++i)
    {
        if( i % 4 == 0) //after every 4 seats, put a line break for a new row
        {
            std::cout << '\n';
        }
        else if(i % 2 == 0) //pair the seats up by printing an aisle in the middle
        {
            std::cout << "   ";
        }

        std::cout << seats.at(i) << ' ';
    }
}
Topic archived. No new replies allowed.