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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
//7.17
#include <iostream>
#include <iomanip>
#include <conio.h>
using namespace std;
const int Row = 15;
const int Col = 30;
int numSold(char[Row][Col]);
void showChart(char [Row][Col]);
void viewticketAmount(int);
void updateChart(const char [][30], int, int);
void avaliableRow(char [Row][Col]);
void avaliableAuditorium(char[Row][Col]);
int main()
{
char Again;
int Seatssold, Seatotal, Showchart1;
int i, j, k, totalamt = 0, choice, totaltickets = 0, viewticket, viewseats, Numsold, Avaliableseats;
int Rowava, Ticketsales, Aud;
double Price[15];
int R, C;
char Show[Row][Col] = {{ '#', '#', '#', '#', '#', '*', '*', '*', '#', '#', '#', '#', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '#', '*', '*', '*', '*', '*'},
{'*', '#', '#', '#', '*', '*', '*', '#', '#', '*', '*', '*', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '#', '*'},
{ '*', '#', '#', '*', '*', '*', '*', '#', '#', '*', '*', '*', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '#', '*'},
{ '*', '*', '#', '*', '*', '*', '*', '#', '#', '*', '*', '*', '#', '#', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '#', '*'},
{ '*', '*', '#', '*', '*', '*', '*', '#', '#', '*', '*', '*', '#', '*', '#', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'},
{ '*', '*', '#', '*', '*', '*', '*', '#', '#', '*', '*', '*', '#', '*', '*', '#', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'},
{ '*', '*', '#', '#', '*', '*', '*', '#', '#', '*', '*', '*', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'},
{ '*', '*', '*', '#', '*', '*', '*', '#', '#', '*', '*', '*', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'},
{ '*', '*', '*', '#', '*', '*', '*', '*', '*', '*', '*', '*', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'},
{ '*', '*', '*', '#', '#', '#', '*', '*', '*', '*', '*', '#', '#', '*', '*', '*', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'},
{ '#', '*', '*', '*', '*', '#', '*', '*', '*', '*', '*', '#', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'},
{ '#', '*', '*', '*', '*', '#', '*', '*', '*', '*', '*', '#', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'},
{ '#', '*', '*', '*', '*', '#', '*', '*', '*', '*', '*', '#', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'},
{ '#', '#', '#', '#', '#', '#', '*', '*', '*', '*', '*', '#', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*'},
{ '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '*', '*', '#', '*', '#', '#', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '#'},
};
showChart(Show);
do
{
cout << "Hit any key to continue\n";
getch();
system("cls");
for (int i = 0; i < 15; i++)
{
cout << "\nEnter the price for row\t" << (i + 1) << ".\n";
cin >> Price[i];
totalamt += Price[i];
}
cout << "Enter the number of tickets you wish to purchase\n";
cin >> choice;
for (int k = 1 ; k <= choice;k++)
{
totaltickets++;
cout << "\nEnter the row:\t";
cin >> R;
if (R < 0 || R > 15)
{
cout << "\nEnter the row,it cant be greater than 15 or less than 0:\t";
cin >> R;
}
cout << "\nEnter the column:\t";
cin >> C;
if ( C < 0 || C > 30)
{
cout << "\nEnter the column:\t";
cin >> C;
}
updateChart(Show, R, C);
cout << "\nThe price for all the tickets purchased are " << totalamt << ".";
}
cout << "\nEnter 1 to view how many Tickets were sold.\n";
cin >> Ticketsales;
if (Ticketsales == 1)
{
viewticketAmount(totaltickets);
}
cout << "\nHit any key to proceed with the program\n";
getch();
cout << "\nEnter 1 to see the total amount of seats sold.\n";
cin >> Seatssold;
if (Seatssold == 1)
{
Seatotal = numSold(Show);
cout << "\nThe number of seats sold are " << Seatotal << ".\n";
}
cout << "\nEnter 1 to view seats avaliable in each row.\n";
cin >> Rowava;
if (Rowava == 1)
{
avaliableRow(Show);
}
cout << "\nEnter 1 to view how many seats are avaliable throughout the entire auditorium.\n";
cin >> Aud;
if ( Aud == 1)
{
avaliableAuditorium(Show);
}
cout << "\nEnter 1 to view chart again\n";
cin >> Showchart1;
if (Showchart1 == 1)
{
showChart(Show);
}
cout << "\nEnter Y to purchase another set\n";
cin >> Again;
}
while (Again == 'Y');
return 0;
}
void showChart(char Show[Row][Col])
{
int i, j;
int cols = 0;
for (int i = 0; i < Row;i++)
{
for (int j = 0; j < Col;j++)
{
cols++;//will match max row value which is 15 and then print a NEWLINE
cout << setw(1) << Show[i][j] << " ";
if ( cols % Col == 0)
cout << endl;
}
}
}
void updateChart(const char Show[][30], int R, int C)
{
if (Show[R][C] == '*')
{
cout << "Sorry, that seat is taken.\n";
}
else
Show[R][C] = '*';
cout << "That seat has been reserved.\n";
}
void viewticketAmount(int totalTickets)
{
cout << "\nThe total amount of tickets sold in this transaction is\t" << totalTickets << "\n";
}
int numSold(char Show[Row][Col])
{
int i, j;
int Totalsold = 0;
for (int i = 0; i < Row;i++)
{
for (int j = 0; j < Col;j++)
{
if (Show[i][j] == '*')
{
Totalsold++;
}
}
}
return Totalsold;
}
void avaliableRow(char Show[Row][Col])
{
int i, j;
int Totalrow;
for (int i = 0; i < Row;i++)
{
Totalrow = 0;
for (int j = 0; j < Col;j++)
{
if ( Show[i][j] == '#')
{
Totalrow++;
cout << "\nRow " << (i + 1) << " has " << Totalrow << "avaliable seats.\n";
}
}
}
}
void avaliableAuditorium(char Show[Row][Col])
{
int i, j;
int Avaliable = 0;
for (int i = 0; i < Row;i++)
{
for (int j = 0; j < Col;j++)
{
if ( Show[i][j] == '#')
{
Avaliable++;
}
}
}
cout << "\nThe amount of avaliable seats in the auditorium is " << Avaliable << "\n";
}
|