Here is my codes and below the codes the errors
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
|
// Chapter 7, Programming Challenge 20: Theater Seating
#include<iostream>
#include<iomanip>
using namespace std;
const int ROWS = 15;
const int COLS = 30;
const char TAKEN = '*';
const char EMPTY = '#';
void displayMenu();
int getChoice();
void displaySeats(const char Seats[][COLS]);
void displayPrices(const double price[]);
void displaySales(double totalSales);
void purchaseTicket(char seats[][COLS], const double ticketPrice[], double& grandTotal);
int main(){
int choice = 0;
double totalSold = 0;
const char map[ROWS][COLS];
double tickets[ROWS];
for(int r = 0; r < ROWS ; r++){
for (int c = 0; c < COLS; c++){
map[r][c] = EMPTY;
}
}
for (int row = 0; row < ROWS; row++){
cout << "Please enter ticket price for Row " << setw(2) << row+1;
cin >> tickets[row];
}
cout << fixed << showpoint << setprecision(2);
do{
displayMenu();
choice = getChoice();
if (choice == 1){
displaySeats(map);
}
else if (choice == 2){
displayPrices(tickets);
}
else if (choice == 3)
displaySales(totalSold);
else if (choice == 4){
purchaseTicket(map,tickets, totalSold); // <--------------------------------?
}
}while(choice != 5);
return 0;
}
void displayMenu(){
cout << "\n\n\n\t\tC++ Theatre" << endl << endl;
cout << "\n\t1. View Available Seats";
cout << "\n\t2. View Seating Prices";
cout << "\n\t3. View Ticket Sales";
cout << "\n\t4. Purchase a Ticket";
cout << "\n\t5. Exit the Program\n\n";
cout << "\n\tEnter your choice(1-5): ";
}
int getChoice(){
int choice = 0;
while(choice == 0 ){
cin >> choice;
if (choice <= 0 || choice > 5){
cout << "Choice must be between 1 and 5. Please re-enter: ";
choice = 0;
}
}
return choice;
}
void displaySeats(const char seats[][COL]){
const char seats[ROWS][COLS];
cout << "\n\t\tSeats";
cout << "\n 123456789012345678901234567890" << endl;
for(int r = 0; r < ROWS ; r++){
cout << "row " << setw(2) << r+1 << " ";
for(int c = 0; c < COLS; c++){
cout << seats[r][c];
}
}
cout << "\n\n\n\tLegend:\t* = Sold";
cout << "\n\t\t# = Available";
//
cout << "\n\n\nPress the Enter key to continue.";
cin.ignore();
cin.get();
}
void displayPrices(const double price[]){
const double price[ROWS];
cout << "\nTicket Prices By Row " << endl << endl;
cout << " Row Price" << endl;
cout << " --- -----" << endl;
//suggestion use a for loop
for(int row = 0; row < ROWS; row++)
cout << setw(8) << row+1 << setw(10) << price[row] << endl;
cout << "\n\n\nPress the Enter key to continue.";
cin.ignore();
cin.get();
}
void purchaseTicket(char seats[][COLS], const double ticketPrice[], double& grandTotal){
char choice = 'n';
char choice2 = 'n';
int numTickets = 0;
int totalTickets = 0;
int r = 0;
int c = 0;
double totPrice = 0;
double grandTotal = 0;
const double ticketPrice[ROWS];
cout << "\n\t\t C++ Theatre" << endl;
cout << "\t\tTicket Purchase Opportunity" << endl << endl;
//
cout << "Do you wish to view the chart of available seats \n"
<< "before making your selections (y/n)? ";
cin >> choice;
displaySeats();
do{
while(totalTickets < 450){
cout << "\nPlease enter desired row number (1-" << ROWS << "): ";
cin >> r;
if(r <= 0 || r > ROWS){
cout << "Row must be between 1 and "
<< ROWS << ". Please re-enter: ";
continue;
}
cout << "\nPlease enter desired seat number (1-" << COLS << "): ";
cin >> c;
if(c <= 0 || c > COLS){
cout << "Seat must be between 1 and " << COLS << ". Please re-enter: ";
continue;
}
// if the seat is available
else if(seats[r-1][c-1] == TAKEN){
cout << "\nSorry. That seat has been sold.\n";//**********************
continue;
}
else{ // and if it is - sell the ticket
seats[r-1][c-1] = TAKEN;
totPrice += ticketPrice[r-1];
cout << "\nPurchase confirmed\n";
numTickets++;
totalTickets++;
}
}
cout << "\nWould you like to purchase another seat (y/n)? ";
cin >> choice2;
if(totalTickets == 450){
cout << "Sorry, we're sold out!" << endl;
break;
}
else
continue;
}while(choice2 == 'y' || choice2 == 'Y');
cout << "\n\nYou have purchased a total of " << numTickets << " tickets " << "for a total price of $" << totPrice;
grandTotal += totPrice;
}
void displaySales(double totalSales){
cout << "\n\nTotal Sales to Date: $" << totalSales << "\n\n";
}
|
In function 'int main()':
19:13: error: uninitialized const 'map' [-fpermissive]
23:23: error: assignment of read-only location 'map[r][c]'
49:41: error: invalid conversion from 'const char (*)[30]' to 'char (*)[30]' [-fpermissive]
14:6: note: initializing argument 1 of 'void purchaseTicket(char (*)[30], const double*, double&)'
At global scope:
79:38: error: 'COL' was not declared in this scope
In function 'void displaySeats(...)':
81:13: error: uninitialized const 'seats' [-fpermissive]
In function 'void displayPrices(const double*)':
103:25: error: declaration of 'const double price [15]' shadows a parameter
103:15: error: uninitialized const 'price' [-fpermissive]
In function 'void purchaseTicket(char (*)[30], const double*, double&)':
128:9: error: declaration of 'double grandTotal' shadows a parameter
129:31: error: declaration of 'const double ticketPrice [15]' shadows a parameter
129:15: error: uninitialized const 'ticketPrice' [-fpermissive]