1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#include<iostream>
#include<cctype>
#include<iomanip>
using namespace std;
void initialize(char form[][10]);
void getData(char& ticketType, int& row,
char& column);
void printForm(char form[][10], int row, char column);
int main()
{
char ch, ticketType, column;
int row;
char form[6][10];
initialize(form);
cout << "This program assigns seats for an auditorium.\n"
<< "Do you want to start now? Y/y for yes, N/n for no." << endl;
cin >> ch;
ch = static_cast<char>(toupper(ch));
while (ch == 'Y')
{
getData(ticketType, row, column);
printForm(form, row, column);
cout << "This program assigns seats for an auditorium.\n"
<< "Do you want to start now? Y/y for yes, N/n for no." << endl;
cin >> ch;
ch = static_cast<char>(toupper(ch));
if (ch == 'N')
return 0;
}// end while
system("PAUSE");
return 0;
}
void initialize(char form[][10])
{
for (int i = 0; i < 6; i++)
for (int j = 0; j<10; j++)
form[i][j] = '*';
}
void getData(char& ticketType, int& row, char& column)
{
cout << "The airplane has 6 rows, with 10 seats in each row. " << endl;
cout << "Enter ticket type,\n"
<< "F for Floor, \n"
<< "B for Balcony,\n"
<< "U for Upper Balcony:" << endl;
cin >> ticketType;
ticketType = static_cast<char>(toupper(ticketType));
while (ticketType != 'F' && ticketType != 'B'
&& ticketType && ticketType != 'U')
{
cout << "Invalid ticket type." << endl;
cout << "Enter ticket type,\n"
<< "F for Floor, \n"
<< "B for Balcony,\n"
<< "E for Upper Balcony:" << endl;
cin >> ticketType;
ticketType = static_cast<char>(toupper(ticketType));
}
switch (ticketType)
{
case 'F':
cout << "Row 1 and 2 are floor seats,\n";
break;
case 'B':
cout << "row 3 and 4 are balcony seats,\n";
break;
case 'E':
cout << "row 5 and 6 are upper balcony seats." << endl;
break;
}// end switch
cout << "Enter the row number you want to sit: " << endl;
cin >> row;
cout << "Enter the seat number (from 1 to 10). " << endl;
cin >> column;
column = static_cast<char>(toupper(column));
}
void printForm(char form[][10], int row, char column)
{
int i, j;
if (form[row - 6][static_cast<int>(column + 1)] == 'X')
{
cout << "This seat already assigned. Choose another seat: " << endl;
cin >> column;
column = static_cast<char>(toupper(column));
}
form[row - 6][static_cast<int>(column + 1)] = 'X';
cout << "* indicates that the seat is available; " << endl;
cout << "X indicates that the seat is occupied. " << endl;
cout << setw(12) << "1" << setw(6) << "2" << setw(6) << "3"
<< setw(6) << "4" << setw(6) << "5" << setw(6) << "6"
<< setw(6) << "7" << setw(6) << "8" << setw(6) << "9" << setw(6) << "10" << endl;
for (i = 0; i < 6; i++)
{
cout << left << setw(3) << "Row " << setw(2) << i + 1;
for (j = 0; j < 10; j++)
{
cout << right << setw(6) << form[i][j];
}
cout << endl;
}
int floor = ? ? ? ;
int balcony = ? ? ? ;
int upper = ? ? ? ;
int floorprice = 30 * floor;
int balconyprice = 20 * balcony;
int upperprice = 10 * upper;
int total = floorprice + balconyprice + upperprice;
cout << "The number of tickets sold in each seating level: \n";
cout << "Floor: " << floor << " tickets sold." << endl;
cout << "Balcony: " << balcony << " tickets sold. " << endl;
cout << "Upper balcony: " << upper << " tickets sold." << endl;
cout << "The sales amount sold in each seating level: \n";
cout << "Floor: $" << floorprice << endl;
cout << "Balcony: $" << balconyprice << endl;
cout << "Upper balcony: $" << upperprice << endl;
cout << "The total sales amount for the entire auditorium is: $" << total << endl;
}
|