Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int ROWS = 13;
- const int SEATS_PER_ROW = 6;
- void displaySeatMap(int seatMap[][SEATS_PER_ROW]) {
- cout << "\tA B C D E F" << endl;
- for (int row = 0; row < ROWS; row++) {
- cout << "Row " << (row + 1) << "\t";
- for (int seat = 0; seat < SEATS_PER_ROW; seat++) {
- if (seatMap[row][seat] == 0)
- cout << "* ";
- else
- cout << "X ";
- }
- cout << endl;
- }
- }
- bool reserveSeat(int seatMap[][SEATS_PER_ROW], int row, int seat) {
- if (seatMap[row][seat] == 0) {
- seatMap[row][seat] = 1;
- cout << "Seat reserved successfully!" << endl;
- return true;
- } else {
- cout << "Sorry, the seat is already occupied." << endl;
- return false;
- }
- }
- int main() {
- int seatMap[ROWS][SEATS_PER_ROW] = {0}; // Initialize seat map with 0 (available)
- while (true) {
- cout << "Please select a ticket type:" << endl;
- cout << "1. First class" << endl;
- cout << "2. Business class" << endl;
- cout << "3. Economy class" << endl;
- cout << "4. Quit" << endl;
- int choice;
- cin >> choice;
- if (choice == 4) {
- cout << "Thank you for using the program. Exiting..." << endl;
- break;
- }
- int row;
- if (choice == 1 || choice == 2) {
- cout << "Please enter the row number (1-2): ";
- cin >> row;
- } else if (choice == 3) {
- cout << "Please enter the row number (3-13): ";
- cin >> row;
- }
- if (row < 1 || row > ROWS) {
- cout << "Invalid row number. Please try again." << endl;
- continue;
- }
- row--; // Decrement row number to match array index
- int seat;
- cout << "Please enter the seat letter (A-F): ";
- char seatLetter;
- cin >> seatLetter;
- if (seatLetter < 'A' || seatLetter > 'F') {
- cout << "Invalid seat letter. Please try again." << endl;
- continue;
- }
- seat = seatLetter - 'A'; // Convert seat letter to array index
- if (reserveSeat(seatMap, row, seat)) {
- displaySeatMap(seatMap);
- } else {
- cout << "Seat reservation failed. Please try again." << endl;
- }
- }
- return 0;
- }
- /*
- This program uses a 2D array seatMap to represent the seat reservation map. Initially, all elements in the seatMap are set to 0, indicating that all seats are available. The reserveSeat function checks if the selected seat is available and reserves it if it is. The displaySeatMap function is used to print the current seat reservation map.
- In the main function, a menu is displayed to the user, allowing them to choose the ticket type (first class, business class, or economy class) or to quit the program. The user is then prompted to enter the row number
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement