Question #49857

Write a program to assign passengers seats on a train journey that travels from Paris to London. Assume the train consists of (78 seats distributed amongst different classes) with the following specifications: 3 classes, 13 rows and 6 seat in each row: (A, B, C, D, E, and F). Row 1- 2: First class, Row 3-7: Business class, and Row 8-13: Economy class. o First ($400 per ticket) o Business ($300 per ticket) o Economy ($100 per ticket)
two dimensional array must be use and asterisks must be using in the the available seat.

Thank you.
1

Expert's answer

2014-12-08T14:11:24-0500

Answer on Question#49857 - <programming> - <c++>

Program

#include <iostream>
#define MAX_ROW 13
#define MAX_COL 6
#define FIRST_CLASS_LAST 2
#define BUSINESS_CLASS_LAST 7
#define ECONOMY_CLASS 13
using namespace std;
//0 - available ; 1 - busy
void printSeats(int mass[MAX_ROW][MAX_COL])
{
    int i,j;
    cout << "\tA\tB\tC\tD\tE\tF\n";
    for(i=0;i < MAX_ROW;i++)
    {
        cout << (i+1);
        for(j=0;j < MAX_COL;j++)
            if(mass[i][j] == 0)
                cout << "\t*";
            else
                cout << "\tb";
        cout << endl;
    }
}
float cost(int i)
{
    if(i < FIRST_CLASS_LAST)
        return 400;
    else
        if(i < BUSINESS_CLASS_LAST)
            return 300;
        else
            return 100;
}
float sumSeats(int mass[MAX_ROW][MAX_COL])
{
    float s = 0;
    int i,j;
    for(i=0;i < MAX_ROW;i++)
        for(j=0;j < MAX_COL;j++)
            s += mass[i][j]*cost(i);
    return s;
}
int main()
{
    int i, j, sum;
    char seat;
    int mass[MAX_ROW][MAX_COL] = {0};
    while(true)
    {
        printSeats(mass);
        cout << "Input row and seat: ";
        cin >> i >> seat;
        if((seat >='A') && (seat <='E') && (i >= 1) && (i <= MAX_ROW))
        {
            if(mass[i-1][seat-'A'] == 0)
            {
                mass[i-1][seat-'A'] = 1;
                cout << "Now seat" << i << seat << " reserve for You, cost: " << cost(i-1);
            }
            else
                cout << "Now seat" << i << seat << " reserved before, choice another one";
        }
        else
            cout << "Row must be between 1 to " << MAX_ROW << ", seats in A, B, C, D, E, F";
        cout << endl;
        cout << "Total cost of seats: " << sumSeats(mass) << endl;
        cout << "Do you want continue? (y/n) ";
        cin >> seat;
        if((seat == 'n') || (seat == 'N'))
            break;
    }
    return 0;
}


Example of execute program:



12 * * * * * *

13 * * * * * *

Input row and seat: 1 A

Now seat 1A reserve for You, cost: 400

Total cost of seats: 400

Do you want continue? (y/n) y



Input row and seat: 10 C

Now seat 10C reserve for You, cost: 100

Total cost of seats: 500

Do you want continue? (y/n) y



Input row and seat: 1 A

Now seat 1A reserved before, choice another one

Total cost of seats: 500

Do you want continue? (y/n)

http://www.AssignmentExpert.com/

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!
LATEST TUTORIALS
APPROVED BY CLIENTS