Answer to Question #288701 in C++ for kazumi

Question #288701

Create a folder named LastName_FirstName (ex. Diaz_Jess) on your local drive. 2. Using NetBeans IDE, create a new project. 3. Name the class as SeatReservation and save the project in your folder 4. Write a simple bus seat reservation program. The bus has 10 rows, with 4 seats in each row. The program should perform the following: Step 1. The program should ask the user to enter what row and seat number to reserve. Indicate an ‘X’ mark if the seat is reserved. Step 2. Repeat Step 1; the program will stop until the user enters a negative number. 5. Compile and execute the program. 6. Debug syntax and logical errors, if there are any in the program. 7. Inform your instructor once you are done


1
Expert's answer
2022-01-19T10:36:05-0500
#include <iostream>


struct seat
{
    bool free = true;
};


class SeatReservation
{
    seat bus[10][4];
    int row;
    int number;
public:
    void ask()
    {
        do 
        {
            std::cout << "Enter row and seat number: ";
            std::cin >> this->row >> this->number;
            if (row < 0 || number < 0)
            {
                continue;
            }
            if (bus[row][number].free)
            {
                bus[row][number].free = false;
                std::cout << "Great. The seat is reserved for you" << std::endl;
            }
            else
            {
                std::cout << "This seat is already under reservation" << std::endl;
            }
        } 
        while (row < 0 || number < 0);
        
        
    }


};


int main(int argc, char* argv[])
{
    SeatReservation sv;
    sv.ask();
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment