Hi Guys i'm here to bother you guys again, I think i'm learning a lot thanks to you guys. My teacher assigned this theater reservation system project with the following guidelines.
In this assignment you will implement a seat reservation system for a theater. The seats in the theater will be represented with a two dimensional array. The closer the seats are to the stage, the more expensive the seats are. Moreover, within a row, the seats at the center shall be more expensive. For this assignment, we will use a simple algorithm to assign costs to seats. The seats in one row cost $10 more than the seats in the previous row. Within a row of n seats, the first and last n/4 seats should be $5 cheaper than the rest of the seats.
To do so, create a header file TheaterReservationSystem.h having the following:
· Two constants: ROWS and SEATS_PER_ROW.
· A function prototype int calculateCost(int row, int seat). This function will calculate the cost of the seat based on the row and seat number as described above.
· A function prototype bool reserveSeat(int cost). This function will reserve the first available seat of the specified cost if there is one. If the program finds a seat of the specified cost, the function shall return true. Otherwise, the function shall return false.
· A function prototype void displaySeatsCost(). This function will print to the standard output a matrix containing the cost of the seats.
· A function prototype void displaySeats(). This function will print to the standard output a matrix showing which seats are reserved and which seats are not available.
· Create a source file TheaterReservationSystem.cpp that implements the functions defined in the header file. In the source file, declare a global variable seats of type bool[][]. This will be the array that indicates whether a seat is sold or not.
Create a driver file TheaterReservationDriver.cpp. In this file display the following menu:
here is what I have so far and for some reason I cant get it to compile. If you guys could take a look and see what I am doing wrong id appreciate it a bunch
This is The header File
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#ifndef THEATERRESERVATIONSYSTEM_H
#define THEATERRESERVATIONSYSTEM_H
#define ROWS 4
#define SEATS_PER_ROW 6
#define MINSEATCOST 10
int calculateCost (int row, int seat);
bool reserveSeat (int cost);
bool reserveBestSeat (int lowestCost, int highestCost);
void displaySeatCost();
void displaySeats ();
int menu();
#endif
|
Here is My functions .cpp
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
|
#include <cstdlib>
#include <iostream>
#include "theaterReservationSystem.h"
using namespace std;
int costMatrix [ROWS][SEATS_PER_ROW];
bool available [ROWS][SEATS_PER_ROW];
int calculateCost(int row, int seat)
{
int howfar = (ROWS-1) - row;
return (costMatrix[ROWS-1][seat] + (howfar*10));
}
bool reserveSeat (int cost)
{
available = new bool*[ROWS];
for (int i=0; i<ROWS; i++)
available[i] = new bool[SEATS_PER_ROW];
for (int i=0; i<ROWS; i++)
for (int j=0; j<SEATS_PER_ROW; j++)
available[ROWS][SEATS_PER_ROW] = true;
costMatrix = new int*[ROWS];
for (int i=0; i<ROWS; i++)
costMatrix[i] = new int[SEATS_PER_ROW];
int spb4 = SEATS_PER_ROW/4;
for (int i=0; i<spb4; i++)
costMatrix[ROWS-1][i] = MINSEATCOST;
for (int i=spb4; i<(SEATS_PER_ROW-spb4); i++)
costMatrix[ROWS-1][i] = (MINSEATCOST+5);
for (int i=(SEATS_PER_ROW-spb4); i<SEATS_PER_ROW; i++)
costMatrix[ROWS-1][i] = MINSEATCOST;
for (int i=(ROWS-2); i>=0; i--)
for (int j=0; j<SEATS_PER_ROW; j++)
costMatrix[i][j] = costMatrix[i+1][j] + 10;
}
bool reserveBestSeat (int lowestCost, int highestCost)
{
int closerRow = (ROWS - (highestCost/MINSEATCOST));
int fartherRow = (ROWS - (lowestCost/MINSEATCOST));
for (int i=closerRow; i<=fartherRow; i++)
{
int bestSeat = -1;
for (int j=0; j<SEATS_PER_ROW; j++)
{
if ((costMatrix[i][j] <= highestCost && costMatrix[i][j] >= lowestCost) && available[i][j])
{
if (bestSeat == -1)
{
bestSeat = j;
}
else
{
if (costMatrix[i][j] > costMatrix[i][bestSeat])
{
bestSeat = j;
break;
}
}
}
}
if (bestSeat != -1)
{
available[i][bestSeat] = false;
return true;
}
}
return false;
}
void displaySeatCost()
{
for (int i=0; i<ROWS; i++)
{
for (int j=0; j<SEATS_PER_ROW; j++)
{
cout << costMatrix[ROWS][SEATS_PER_ROW] << "\t";
}
cout << endl;
}
}
void displaySeats ()
{
for (int i=0; i<ROWS; i++)
{
for (int j=0; j<SEATS_PER_ROW; j++)
{
if (available[ROWS][SEATS_PER_ROW])
{
cout << "A ";
}
else
{
cout << "R ";
}
}
cout << endl;
}
}
int menu()
{
int choice;
cout << "Enter 1 to reserve a seat" << endl;
cout << "Enter 2 to reserve the best seat available" << endl;
cout << "Enter 3 to display seats cost" << endl;
cout << "Enter 4 to display reservations" << endl;
cout << "Enter 5 to quit" << endl;
cout << "Choice? ";
cin >> choice;
return choice;
}
|
The Driver.cpp
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
|
#include <cstdlib>
#include <iostream>
#include "theaterReservationSystem.h"
using namespace std;
int main()
{
const int seats = 4, seatsPerRow = 4;
//theaterReservationSystem (seats, seatsPerRow);
int choice, cost, lowerCost, higherCost;
do
{
choice = menu();
switch (choice)
{
case 1:
cout << "Cost? ";
cin >> cost;
if (reserveSeat(cost))
{
cout << "Seat Reserved Successfully." << endl;
}
else
{
cout << "Sorry! no seat available with that cost." << endl;
}
break;
case 2:
cout << "Lower Cost in range? ";
cin >> lowerCost;
cout << "Higher Cost in range? ";
cin >> higherCost;
if (reserveBestSeat(lowerCost, higherCost))
{
cout << "Seat Reserved Successfully." << endl;
}
else
{
cout << "Sorry! no seat available within that cost range." << endl;
}
break;
case 3:
displaySeatCost();
break;
case 4:
displaySeats();
break;
}
}
while (choice != 5);
return 0;
}
|
Sorry for the super long post been pulling my hair out for days, I don't know what wrong I have tried everything from the files the teacher gave for "hints" to looking online.
Thanks a Bunch