Question

Hello, I am working on a project for my C++ class, I have the vast majority...

Hello, I am working on a project for my C++ class, I have the vast majority of the code figured out but am running into a few issues. Mainly updating each * to an X. The problem is as follows:(Airplane Seating Assignment) Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with six seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business class, and rows 8 through 13 are economy class. Your program must prompt the user to enter the following information: a. Ticket type (first class, business class, or economy class) b. Desired seat Output the seating plan in the following form: A B C D E F Row 1 * * X * X X Row 2 * X * X * X Row 3 * * X X * X Row 4 X * X * X X Row 5 * X * X * * Row 6 * X * * * X Row 7 X * * * X X Row 8 * X * X X * Row 9 X * X X * X Row 10 * X * X X X Row 11 * * X * X * Row 12 * * X X * X Row 13 * * * * X * 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.

and my code is as follows:


#include <cstring>
#include <iomanip>
#include <iostream>

void displayPlane(char[][6], int, int);
void fillArray(char[][6]);
using namespace std;
int main(int argc, char **argv) {
char airplaneSeats[13][6];
fillArray(airplaneSeats);
int priceTotal = 0;

char seatType;

cout << "This program will help you choose your seat on an airplane." << endl;
cout << "First class is the first two rows, business is the third to seventh "
"row, and economy is the eigth to thirteenth row."
<< endl;


bool seatTypeValid = false;
while (!seatTypeValid) {
cout << "Do you want to sit in (F)irst class, (B)usiness, or (E)conomy?: ";

cin >> seatType;
if (seatType == 'F' || seatType == 'B' || seatType == 'E') {
seatTypeValid = true;
} else {
cout << "Please enter a valid seat type!" << endl;
}
}
switch (seatType) {
case 'F':
displayPlane(airplaneSeats, 0, 1);
break;
case 'B':
displayPlane(airplaneSeats, 2, 6);
break;
default:
displayPlane(airplaneSeats, 7, 12);
}


bool seatAvailable = false;

int rowNum;
char letter;
int convertedLetter;
  
while (!seatAvailable) {
bool correctRow = false;
while (!correctRow) {
cout << "Enter the row number of your chosen seat: ";
cin >> rowNum;
if (seatType == 'F' && (rowNum > 0 && rowNum <= 2)) {
correctRow = true;
} else if (seatType == 'B' && (rowNum > 2 && row <= 7)) {
correctRow = true;
} else if (seatType == 'E' && (rowNum > 7 && rowNum <= 13)) {
correctRow = true;
} else {
cout << "You entered an invalid number, please enter a number in your "
"chosen class!"
<< endl;
}
}
cout << "Please pick a seat from A-F." << endl;
cin >> letter;
convertedLetter = (int)(letter)-65;
if (airplaneSeats[(rowNum - 1)][convertedLetter] == 'X') {
cout << "That seat is taken, please choose another seat!" << endl;
} else {
seatAvailable = true;
}
}

airplaneSeats[(rowNum - 1)][convertedLetter] = 'X';

return 0;
}
}
void fillArray(char airplaneSeats1[][6]) {
for (int r = 0; r < 13; r++) {
for (int c = 0; c < 6; c++) {
airplaneSeats1[r][c] = '*';
}
}
}
void displayPlane(char airplaneSeats2[][6], int i, int h) {
cout << left << " A B C D E F" << endl;
string rowNums[13] = {"Row 1", "Row 2", "Row 3", "Row 4", "Row 5",
"Row 6", "Row 7", "Row 8", "Row 9", "Row 10",
"Row 11", "Row 12", "Row 13"};
for (int r = i; r <= h; r++) {
cout << setw(6) << rowNums[r] << " ";
for (int c = 0; c < 6; c++) {
cout << airplaneSeats2[r][c] << " ";
}
cout << endl;
}
cout << endl;
}

any help would be greatly appreciated!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Your program worked fine, except one error which i have corrected. This program runs only once, so seat assignment takes place just once. Please tell how this program is to be structured if you want it to behave differently

#include <cstring>
#include <iomanip>
#include <iostream>

void displayPlane(char[][6], int, int);
void fillArray(char[][6]);
using namespace std;
int main(int argc, char** argv)
{
    char airplaneSeats[13][6];
    fillArray(airplaneSeats);
    int priceTotal = 0;

    char seatType;

    cout << "This program will help you choose your seat on an airplane." << endl;
    cout << "First class is the first two rows, business is the third to seventh "
            "row, and economy is the eigth to thirteenth row."
         << endl;

    bool seatTypeValid = false;
    while (!seatTypeValid) {
        cout << "Do you want to sit in (F)irst class, (B)usiness, or (E)conomy?: ";

        cin >> seatType;
        if (seatType == 'F' || seatType == 'B' || seatType == 'E') {
            seatTypeValid = true;
        }
        else {
            cout << "Please enter a valid seat type!" << endl;
        }
    }
    switch (seatType) {
    case 'F':
        displayPlane(airplaneSeats, 0, 1);
        break;
    case 'B':
        displayPlane(airplaneSeats, 2, 6);
        break;
    default:
        displayPlane(airplaneSeats, 7, 12);
    }

    bool seatAvailable = false;

    int rowNum;
    char letter;
    int convertedLetter;

    while (!seatAvailable) {
        bool correctRow = false;
        while (!correctRow) {
            cout << "Enter the row number of your chosen seat: ";
            cin >> rowNum;
            if (seatType == 'F' && (rowNum > 0 && rowNum <= 2)) {
                correctRow = true;
            }
            else if (seatType == 'B' && (rowNum > 2 && rowNum <= 7)) {
                correctRow = true;
            }
            else if (seatType == 'E' && (rowNum > 7 && rowNum <= 13)) {
                correctRow = true;
            }
            else {
                cout << "You entered an invalid number, please enter a number in your "
                        "chosen class!"
                     << endl;
            }
        }
        cout << "Please pick a seat from A-F." << endl;
        cin >> letter;
        convertedLetter = (int)(letter)-65;
        if (airplaneSeats[(rowNum - 1)][convertedLetter] == 'X') {
            cout << "That seat is taken, please choose another seat!" << endl;
        }
        else {
            seatAvailable = true;
        }
    }

    airplaneSeats[(rowNum - 1)][convertedLetter] = 'X';
    displayPlane(airplaneSeats, 0, 12);

    return 0;
}

void fillArray(char airplaneSeats1[][6])
{
    for (int r = 0; r < 13; r++) {
        for (int c = 0; c < 6; c++) {
            airplaneSeats1[r][c] = '*';
        }
    }
}
void displayPlane(char airplaneSeats2[][6], int i, int h)
{
    cout<<"      " << left << " A B C D E F" << endl;
    string rowNums[13] = { "Row 1", "Row 2", "Row 3", "Row 4", "Row 5",
        "Row 6", "Row 7", "Row 8", "Row 9", "Row 10",
        "Row 11", "Row 12", "Row 13" };
    for (int r = i; r <= h; r++) {
        cout << setw(6) << rowNums[r] << " ";
        for (int c = 0; c < 6; c++) {
            cout << airplaneSeats2[r][c] << " ";
        }
        cout << endl;
    }
    cout << endl;
}

Add a comment
Know the answer?
Add Answer to:
Hello, I am working on a project for my C++ class, I have the vast majority...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program is in C++, program is called airplane reservation. It is suppose to display a screen...

    Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...

  • Hello, I am trying to write this program and have received a "Segmentation Fault" error but...

    Hello, I am trying to write this program and have received a "Segmentation Fault" error but cannot seem to figure out where. I haven't been able to find it and have been looking for quite a while. The goal is to basically create a version of Conway's Game of Life. I am able to generate a table if the input values for rows and columns are equal, but if they are not I receive a segmentation fault and cannot continue...

  • Hello, I am working on my final and I am stuck right near the end of...

    Hello, I am working on my final and I am stuck right near the end of the the program. I am making a Tic-Tac-Toe game and I can't seem to figure out how to make the program ask if you would like to play again, and keep the same names for the players that just played, keep track of the player that wins, and display the number of wins said player has, after accepting to keep playing. I am wanting...

  • I have a queue and stack class program that deals with a palindrome, I need someone...

    I have a queue and stack class program that deals with a palindrome, I need someone to help to put in templates then rerun the code. I'd greatly appreciate it. It's in C++. Here is my program: #include<iostream> #include<list> #include<iterator> #include<string> using namespace std; class Queue { public: list <char> queue; Queue() { list <char> queue; } void Push(char item) { queue.push_back(item); } char pop() { char first = queue.front(); queue.pop_front(); return first; } bool is_empty() { if(queue.empty()) { return...

  • How can I make this compatible with older C++ compilers that DO NOT make use of...

    How can I make this compatible with older C++ compilers that DO NOT make use of stoi and to_string? //Booking system #include <iostream> #include <iomanip> #include <string> using namespace std; string welcome(); void print_seats(string flight[]); void populate_seats(); bool validate_flight(string a); bool validate_seat(string a, int b); bool validate_book(string a); void print_ticket(string passenger[], int i); string flights [5][52]; string passengers [4][250]; int main(){     string seat, flight, book = "y";     int int_flight, p = 0, j = 0;     int seat_number,...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • I just need a help in replacing player 2 and to make it unbeatable here is my code: #include<i...

    I just need a help in replacing player 2 and to make it unbeatable here is my code: #include<iostream> using namespace std; const int ROWS=3; const int COLS=3; void fillBoard(char [][3]); void showBoard(char [][3]); void getChoice(char [][3],bool); bool gameOver(char [][3]); int main() { char board[ROWS][COLS]; bool playerToggle=false; fillBoard(board); showBoard(board); while(!gameOver(board)) { getChoice(board,playerToggle); showBoard(board); playerToggle=!playerToggle; } return 1; } void fillBoard(char board[][3]) { for(int i=0;i<ROWS;i++) for(int j=0;j<COLS;j++) board[i][j]='*'; } void showBoard(char board[][3]) { cout<<" 1 2 3"<<endl; for(int i=0;i<ROWS;i++) { cout<<(i+1)<<"...

  • This is for a C++ program: I'm almost done with this program, I just need to...

    This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • Requirements I have already build a hpp file for the class architecture, and your job is to imple...

    Requirements I have already build a hpp file for the class architecture, and your job is to implement the specific functions. In order to prevent name conflicts, I have already declared a namespace for payment system. There will be some more details: // username should be a combination of letters and numbers and the length should be in [6,20] // correct: ["Alice1995", "Heart2you", "love2you", "5201314"] // incorrect: ["222@_@222", "12306", "abc12?"] std::string username; // password should be a combination of letters...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT