Question

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, seat_price;
    populate_seats();

    while (book == "y" || book == "Y"){
        passengers[p][0] = (welcome());

        cout << "\nThe available travel times for flights are:" << endl;
        cout << "    Depart\tArrive" << endl;

        for (int i = 0; i < 5; i++){
            if (flights[i][51] != "50"){
            cout << i + 1 << ". " << flights[i][0] << endl;
            }
            else if (j < 4){
                j++;
            }
            else{
                cout << "\nAll flights are booked" << endl;
                return 0;
            }
        }

        cout << "Choose the time by enetering the option number from the displayed list:" << endl;
        do{
            cin >> flight;
        }
        while(!validate_flight(flight));

        cout << "\nSelect your seat:" << endl;

        int_flight = stoi(flight) - 1;
        print_seats(flights[int_flight]);

        do{
            cin >> seat;
        }
        while (!validate_seat(seat, int_flight));

        for (int i = 0; i < 51; i++){
            if (flights[int_flight][i] == seat){
                flights[int_flight][i] = "**";
                seat_number = i;
                break;
            }
        }

        if (seat_number < 25){
            seat_price = 1920;
            passengers[p][4] = "First class";
        }
        else{
            seat_price = 1600;
            passengers[p][4] = "Economy class";
        }

        passengers[p][1] = flight;
        passengers[p][2] = seat;
        passengers[p][3] = to_string(seat_price);

        flights[int_flight][51] = to_string(stoi(flights[int_flight][51]) + 1);

        print_ticket(passengers[p], int_flight);

        cout << "\nWould you like to book another seat? Y/N: " ;
        do{
            cin >> book;
            cin.get();
        }while(!validate_book(book));

        p++;
        cout << endl;
        }

        for (int i = 0; i < 5; i++){
            cout << "Number of bookings made for " << flights[i][0].substr(0,5);
            cout << ": " << flights[i][51] << endl;
        }
    return 0;
}

string welcome(){
    string passenger;

    cout << "Welcome to the COS1511 Flight Booking System\n" << endl;
    cout << "Enter Full Name" << endl;

    getline(cin,passenger);

    return passenger;
}

void print_seats(string flight[]){
    int k = 0;
    cout << "First class(1920.00)" << endl;
    for (int j = 0; j < 9; j++){
        if (k == 24){
            cout << "Economy class(1600.00)" << endl;
        }
        cout << "|";
        for (int i = 0; i < 3; i++){
            cout << flight[k+1] << "|";
            k++;

                if (k > 49){
                    cout << endl;
                    return;
            }
        }

        cout << "----";

        for (int i = 0; i < 3; i++){
            cout << "|" << flight[k+1];
            k++;
        }
        cout << "|" << endl;
    }
}

void populate_seats(){
    flights[0][0] = "07:00\t09:30";
    flights[1][0] = "09:00\t11:30";
    flights[2][0] = "11:00\t13:30";
    flights[3][0] = "13:00\t15:30";
    flights[4][0] = "15:00\t17:30";

    for (int a = 0; a < 5; a++){
        int b = 0;
        for (int i = 17; i < 26; i++){
            for ( int j = 1; j < 7; j++){

                if (i == 25 && j > 2){
                    break;
                }
                string seat = char('0' + i) + to_string(j);
                flights[a][b+1] = seat;

                b++;
            }
            flights[a][b+1] = "0";
        }
    }
}

void print_ticket(string passenger[], int i){
    int name = passenger[0].length();
    cout << "Travel Ticket for Flight " << i + 1 << endl;
    cout << "----------------------------" << endl;

    cout << left << setw(15) << "Name " << ": " << passenger[0];
    cout << setw(13) << "" << "Travel Ticket Class " << ": " << passenger[4] << endl;

    cout << setw(31 + name) << "" << setw(20) << "Seat No." << ": " << passenger[2] << endl;

    cout << setw(15) << "Departure" << ": " << setw(13 + name) << "Johannesburg";
    cout << setw(20) << "Departure Time" << ": " << flights[i][0].substr(0,5) << endl;

    cout << setw(15) << "Destination" << ": " << setw(13 + name) << "Cape Town";
    cout << setw(20) << "Arrival Time" << ": " << flights[i][0].substr(6,10) << endl;

    cout << "\n----------------------------" << endl;
    cout << "Amount: R" << passenger[3] << endl;
    cout << "Thank you for booking with COS 1511 Booking System." << endl;
    cout << "Your travel agent is Damian Jacobs" << endl;
    cout << "----------------------------" << endl;
}

bool validate_flight(string a){
    for (int i = 1; i < 6; i++){
        if (a == to_string(i)){
            return true;
        }
    }
    cout << "Incorrect option! Please choose from 1-5." << endl;
    return false;
}

bool validate_seat(string a, int b){
    for (int i = 0; i < 51; i++){
        if (flights[b][i] == a){
            return true;
        }
    }
    cout << "Enter a valid seat" << endl;
    return false ;
}

bool validate_book(string a){
    while(a != "y" && a != "n" & a != "Y" && a != "N"){
        cout << "Enter a valid option: Y/N:";
        return false;
    }
    return true;
}

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

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>

using namespace std;

string to_strings(int seat_price)
{
ostringstream str11;
str11 << seat_price;
return str11.str();
}
int stois(string flight)
{
stringstream test(flight);
int nnom;
test>>nnom;
return nnom;
}
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, seat_price;
populate_seats();

while (book == "y" || book == "Y"){
passengers[p][0] = (welcome());

cout << "\nThe available travel times for flights are:" << endl;
cout << " Depart\tArrive" << endl;

for (int i = 0; i < 5; i++){
if (flights[i][51] != "50"){
cout << i + 1 << ". " << flights[i][0] << endl;
}
else if (j < 4){
j++;
}
else{
cout << "\nAll flights are booked" << endl;
return 0;
}
}

cout << "Choose the time by enetering the option number from the displayed list:" << endl;
do{
cin >> flight;
}
while(!validate_flight(flight));

cout << "\nSelect your seat:" << endl;

int_flight = stois(flight) - 1;
print_seats(flights[int_flight]);

do{
cin >> seat;
}
while (!validate_seat(seat, int_flight));

for (int i = 0; i < 51; i++){
if (flights[int_flight][i] == seat){
flights[int_flight][i] = "**";
seat_number = i;
break;
}
}

if (seat_number < 25){
seat_price = 1920;
passengers[p][4] = "First class";
}
else{
seat_price = 1600;
passengers[p][4] = "Economy class";
}

passengers[p][1] = flight;
passengers[p][2] = seat;

passengers[p][3] = to_strings(seat_price);

flights[int_flight][51] = to_strings(stois(flights[int_flight][51]) + 1);

print_ticket(passengers[p], int_flight);

cout << "\nWould you like to book another seat? Y/N: " ;
do{
cin >> book;
cin.get();
}while(!validate_book(book));

p++;
cout << endl;
}

for (int i = 0; i < 5; i++){
cout << "Number of bookings made for " << flights[i][0].substr(0,5);
cout << ": " << flights[i][51] << endl;
}
return 0;
}

string welcome(){
string passenger;

cout << "Welcome to the COS1511 Flight Booking System\n" << endl;
cout << "Enter Full Name" << endl;

getline(cin,passenger);

return passenger;
}

void print_seats(string flight[]){
int k = 0;
cout << "First class(1920.00)" << endl;
for (int j = 0; j < 9; j++){
if (k == 24){
cout << "Economy class(1600.00)" << endl;
}
cout << "|";
for (int i = 0; i < 3; i++){
cout << flight[k+1] << "|";
k++;

if (k > 49){
cout << endl;
return;
}
}

cout << "----";

for (int i = 0; i < 3; i++){
cout << "|" << flight[k+1];
k++;
}
cout << "|" << endl;
}
}

void populate_seats(){
flights[0][0] = "07:00\t09:30";
flights[1][0] = "09:00\t11:30";
flights[2][0] = "11:00\t13:30";
flights[3][0] = "13:00\t15:30";
flights[4][0] = "15:00\t17:30";

for (int a = 0; a < 5; a++){
int b = 0;
for (int i = 17; i < 26; i++){
for ( int j = 1; j < 7; j++){

if (i == 25 && j > 2){
break;
}
string seat = char('0' + i) + to_strings(j);
flights[a][b+1] = seat;

b++;
}
flights[a][b+1] = "0";
}
}
}

void print_ticket(string passenger[], int i){
int name = passenger[0].length();
cout << "Travel Ticket for Flight " << i + 1 << endl;
cout << "----------------------------" << endl;

cout << left << setw(15) << "Name " << ": " << passenger[0];
cout << setw(13) << "" << "Travel Ticket Class " << ": " << passenger[4] << endl;

cout << setw(31 + name) << "" << setw(20) << "Seat No." << ": " << passenger[2] << endl;

cout << setw(15) << "Departure" << ": " << setw(13 + name) << "Johannesburg";
cout << setw(20) << "Departure Time" << ": " << flights[i][0].substr(0,5) << endl;

cout << setw(15) << "Destination" << ": " << setw(13 + name) << "Cape Town";
cout << setw(20) << "Arrival Time" << ": " << flights[i][0].substr(6,10) << endl;

cout << "\n----------------------------" << endl;
cout << "Amount: R" << passenger[3] << endl;
cout << "Thank you for booking with COS 1511 Booking System." << endl;
cout << "Your travel agent is Damian Jacobs" << endl;
cout << "----------------------------" << endl;
}

bool validate_flight(string a){
for (int i = 1; i < 6; i++){
if (a == to_strings(i)){
return true;
}
}
cout << "Incorrect option! Please choose from 1-5." << endl;
return false;
}

bool validate_seat(string a, int b){
for (int i = 0; i < 51; i++){
if (flights[b][i] == a){
return true;
}
}
cout << "Enter a valid seat" << endl;
return false ;
}

bool validate_book(string a){
while(a != "y" && a != "n" & a != "Y" && a != "N"){
cout << "Enter a valid option: Y/N:";
return false;
}
return true;
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
How can I make this compatible with older C++ compilers that DO NOT make use of...
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...

  • #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car {...

    #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...

  • Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem...

    Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem to get my code to work. The output should have the AVEPPG from highest to lowest (sorted by bubbesort). The output of my code is messed up. Please help me, thanks. Here's the input.txt: Mary 15 10.5 Joseph 32 6.2 Jack 72 8.1 Vince 83 4.2 Elizabeth 41 7.5 The output should be: NAME             UNIFORM#    AVEPPG Mary                   15     10.50 Jack                   72      8.10 Elizabeth              41      7.50 Joseph                 32      6.20 Vince                  83      4.20 ​ My Code: #include <iostream>...

  • Can somebody help me with this coding the program allow 2 players play tic Tac Toe....

    Can somebody help me with this coding the program allow 2 players play tic Tac Toe. however, mine does not take a turn. after player 1 input the tow and column the program eliminated. I want this program run until find a winner. also can somebody add function 1 player vs computer mode as well? Thanks! >>>>>>>>>>>>>Main program >>>>>>>>>>>>>>>>>>>>>>> #include "myheader.h" int main() { const int NUM_ROWS = 3; const int NUM_COLS = 3; // Variables bool again; bool won;...

  • I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include...

    I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include <string> #include <iomanip> using namespace std; struct Drink {    string name;    double cost;    int noOfDrinks; }; void displayMenu(Drink drinks[], int n); int main() {    const int size = 5;       Drink drinks[size] = { {"Cola", 0.65, 2},    {"Root Beer", 0.70, 1},    {"Grape Soda", 0.75, 5},    {"Lemon-Lime", 0.85, 20},    {"Water", 0.90, 20} };    cout <<...

  • Coding in c++

    I keep getting errors and i am so confused can someone please help and show the input and output ive tried so many times cant seem to get it. main.cpp #include <iostream> #include <vector> #include <string> #include "functions.h" int main() {    char option;    vector<movie> movies;     while (true)     {         printMenu();         cin >> option;         cin.ignore();         switch (option)         {            case 'A':            {                string nm;                int year;                string genre;                cout << "Movie Name: ";                getline(cin, nm);                cout << "Year: ";                cin >> year;                cout << "Genre: ";                cin >> genre;                               //call you addMovie() here                addMovie(nm, year, genre, &movies);                cout << "Added " << nm << " to the catalog" << endl;                break;            }            case 'R':            {                   string mn;                cout << "Movie Name:";                getline(cin, mn);                bool found;                //call you removeMovie() here                found = removeMovie(mn, &movies);                if (found == false)                    cout << "Cannot find " << mn << endl;                else                    cout << "Removed " << mn << " from catalog" << endl;                break;            }            case 'O':            {                string mn;                cout << "Movie Name: ";                getline(cin, mn);                cout << endl;                //call you movieInfo function here                movieInfo(mn, movies);                break;            }            case 'C':            {                cout << "There are " << movies.size() << " movies in the catalog" << endl;                 // Call the printCatalog function here                 printCatalog(movies);                break;            }            case 'F':            {                string inputFile;                bool isOpen;                cin >> inputFile;                cout << "Reading catalog info from " << inputFile << endl;                //call you readFromFile() in here                isOpen = readFile(inputFile, &movies);                if (isOpen == false)                    cout << "File not found" << endl;...

  • Please help fix my code C++, I get 2 errors when running. The code should be...

    Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...

  • using the source code at the bottom of this page, use the following instructions to make...

    using the source code at the bottom of this page, use the following instructions to make the appropriate modifications to the source code. Serendipity Booksellers Software Development Project— Part 7: A Problem-Solving Exercise For this chapter’s assignment, you are to add a series of arrays to the program. For the time being, these arrays will be used to hold the data in the inventory database. The functions that allow the user to add, change, and delete books in the store’s...

  • The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib>...

    The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...

  • my program wont run on my computer and im not understanding why. please help. #include<iostream> #include<iomanip>...

    my program wont run on my computer and im not understanding why. please help. #include<iostream> #include<iomanip> #include<string> #include "bookdata.h" #include "bookinfo.h" #include "invmenu.h" #include "reports.h" #include "cashier.h" using namespace std; const int ARRAYNUM = 20; BookData bookdata[ARRAYNUM]; int main () { bool userChoice = false; while(userChoice == false) { int userInput = 0; bool trueFalse = false; cout << "\n" << setw(45) << "Serendipity Booksellers\n" << setw(39) << "Main Menu\n\n" << "1.Cashier Module\n" << "2.Inventory Database Module\n" << "3.Report Module\n"...

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