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/
Comments