Question

C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...

C++

#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>

using namespace std;

const int ROWS = 8; //for rows in airplane
const int COLS = 4;

void menu(); //displays options
void displaySeats(char[][COLS]);
void reserveSeat(char [ROWS][COLS]);

int main() {

    int number=0; //holder variable
    char seatChar[ROWS][COLS];

    for (int i = 0; i < ROWS; i++)
    {
        for (int j = 0; j < COLS; j++) {
            seatChar[i][j] = '-';
        }
    }

    int choice; //input from menu

    bool repeat = true; //needed for switch loop

    while (repeat = true) {
        menu();
        cout << "-----------------------" << endl;
        cout << "Please enter Your Choice (1-3): " << endl;
        cin >> choice;
        cout << "----------------------" << endl;

        switch (choice) {

            case 1:
                cout << "Seating chart looks like this:" << endl;
                displaySeats(seatChar);
                break;

            case 2:
                reserveSeat(seatChar);
                break;

            case 3:
                exit(0);
            default:
                cout << "You need to enter a number 1-7" << endl;

        }//end of switch
    }

    return 0;
}

void menu() {

    cout << "  AIR TICKETS SYSTEM " << endl;
    cout << "click [ 1 ] to Display Seat Chart" << endl;
    cout << "click [ 2 ]Reserve Seat" << endl;
    cout << "click [ 3 ] Quit" << endl;

}

void displaySeats(char seats[ROWS][COLS] )
{
    char letter;
    cout<<" 1 2 3 4"<<endl;
    for (int i = 0; i < ROWS; i++) {
        cout <<i+1<<" ";
        for (int j = 0; j < COLS; j++) {
            cout << seats[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
}

void reserveSeat(char seat[ROWS][COLS]) {
    int row;
    int col;
    cout << "Please enter a seat in the form ROW 1-8 and 1-4 for the column: [example 2 2]: " << endl;
    cin >> row >> col;
    row--; col--;

    while (((row > ROWS) || (row <= 0)) &&(col > COLS || col<=0)) {
        cout << "You entered a seat that does not exist!" << endl;
        cout << "Please try again" << endl;
        cout << "Please enter a number 1-8 for the row and 1-4 for the column: " << endl;
        cin >> row >> col;
        row--; col--;
    }
    while (seat[row][col] == 'X') {
        cout << "Seat is already taken." << endl;
        cout << "Please try again!" << endl;
        cout << "Please enter a number 1-8 for the row and 1-4 for the column: " << endl;
        cin >> row >> col;
        row--; col--;
    }

    seat[row][col] = 'X';
    cout << "Your seat was successful reserved!" << endl;
}

//////////////////

Use OO paradigm to redo this code. Create a class with at least a data member for storing seats availability. The data member must be a twodimensional array. Your class must also contain a constructor and at least two member functions: one for seat booking and the other for displaying seat availability status.

Homework Answers

Answer #1

#include<iostream>
using namespace std;

class Seats{
public:
const static int ROWS = 8; //for rows in airplane
const static int COLS = 4;
char seatChar[ROWS][COLS];
Seats(){
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < this->COLS; j++) {
this->seatChar[i][j] = '-';
}
}
}
// ------------------------------------
void getAccess(){
int choice; //input from menu

bool repeat = true; //needed for switch loop

while (repeat = true) {
this->menu();
cout << "-----------------------" << endl;
cout << "Please enter Your Choice (1-3): " << endl;
cin >> choice;
cout << "----------------------" << endl;

switch (choice) {

case 1:
cout << "Seating chart looks like this:" << endl;
this->displaySeats(seatChar);
break;

case 2:
this->reserveSeat(seatChar);
break;

case 3:
exit(0);
default:
cout << "You need to enter a number 1-7" << endl;

}//end of switch
}


}
// ----------------------------------------------
void menu() {

cout << " AIR TICKETS SYSTEM " << endl;
cout << "click [ 1 ] to Display Seat Chart" << endl;
cout << "click [ 2 ]Reserve Seat" << endl;
cout << "click [ 3 ] Quit" << endl;

}
// -----------------------------------------
void displaySeats(char seats[ROWS][COLS] )
{
char letter;
cout<<" 1 2 3 4"<<endl;
for (int i = 0; i < ROWS; i++) {
cout <<i+1<<" ";
for (int j = 0; j < COLS; j++) {
cout << seats[i][j] << " ";
}
cout << endl;
}
cout << endl;
}
// ----------------------------------------------------
void reserveSeat(char seat[ROWS][COLS]) {
int row;
int col;
cout << "Please enter a seat in the form ROW 1-8 and 1-4 for the column: [example 2 2]: " << endl;
cin >> row >> col;
row--; col--;

while (((row > ROWS) || (row <= 0)) &&(col > COLS || col<=0)) {
cout << "You entered a seat that does not exist!" << endl;
cout << "Please try again" << endl;
cout << "Please enter a number 1-8 for the row and 1-4 for the column: " << endl;
cin >> row >> col;
row--; col--;
}
while (seat[row][col] == 'X') {
cout << "Seat is already taken." << endl;
cout << "Please try again!" << endl;
cout << "Please enter a number 1-8 for the row and 1-4 for the column: " << endl;
cin >> row >> col;
row--; col--;
}

seat[row][col] = 'X';
cout << "Your seat was successful reserved!" << endl;
}
// ----------------------------------

};

int main(){
// create object seats and get access
Seats seats;
seats.getAccess();

return 0;
}

------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,

IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~

Know the answer?
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
Similar Questions
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Your code here ----------------- } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Code here } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to manipulate the elements...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
#include <iostream>using namespace std;int main(){ char meal_choice; //user's choice int servings, total_calories; // Display greeting: cout...
#include <iostream>using namespace std;int main(){ char meal_choice; //user's choice int servings, total_calories; // Display greeting: cout << "Welcome to the Calorie Count-ulator!\n"; // Get user input: cout << "Enter your meal choice ([P]izza, [S]alad, [H]amburger)\n"; cin >> meal_choice; cout << "Enter the amount of servings (1-9):\n"; cin >> servings; // TODO: Use a switch statement to evaluate the user's meal choice // Handle error checking where appropriate // Exit the program: return 0;}
#include<iostream> using namespase std; int main() {     int i=1;     int j=-5;     int k=80;...
#include<iostream> using namespase std; int main() {     int i=1;     int j=-5;     int k=80;     float f=2.22;     float h=-7.5;     char a='S';     char b='M';     cout<<i<<"\t"<<j<<"\t"<<k<<endl;     Cout<<f<<"\t"<<h<<endl;     cout<<a<<"\t"<<b<<endl;     return 0;     }
//evil_server.cpp #include <string> #include <cstdlib> #include <iostream> #include "evil_server.h" using namespace std; EvilServer :: EvilServer() {...
//evil_server.cpp #include <string> #include <cstdlib> #include <iostream> #include "evil_server.h" using namespace std; EvilServer :: EvilServer() {    hacked[0] = hacked[1] = hacked[2] = false;    passwords[agent_index(MrMean)] = random_pw(MrMean);    passwords[agent_index(MsChief)] = random_pw(MsChief);    passwords[agent_index(DrEvil)] = random_pw(DrEvil); } void EvilServer :: change_pw(EvilAgent agent, string new_pw) {    int index = agent_index(agent);    if (new_pw == passwords[index])        return;    hacked[index] = false;    passwords[index] = new_pw; } string EvilServer :: random_pw(EvilAgent agent) {    string password;    int length;   ...
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath>...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath> using namespace std; void divisors(int num); int main () {    char repeat;    int num;       while (repeat !='n')    {        cout << "Enter a number: ";        cin >> num;        divisors(num);        cout << "Continue? (y or n): ";        cin >> repeat;    }    return 0; } void divisors(int num) {   ...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std;...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std; int main() {        int x;        cout << "Selection option " << endl;        cin >> x;        if (x == 1)               cout << "You select option 1" << endl;        else if (x >= 2 || x <= 4)               cout << "You select options 2 or 3 or 4" << endl;               else if (x == 10)               cout << "You select option 10" << endl;               else...
Consider the following program: #include #include #include using namespace std; int main() { int num1; int...
Consider the following program: #include #include #include using namespace std; int main() { int num1; int num2; cout << fixed << showpoint << setprecision(2); cout << "Enter two integers: "; cin >> num1 >> num2; cout << endl; if (num1 != 0 && num2 != 0) cout << sqrt(abs(num1 + num2) + 0.5) << endl; else if (num1 != 0) cout << floor(num1 + 0.5) << endl; else if (num2 != 0) cout << ceil(num2 + 0.5) << endl; else...