Instructions
Requirements and Specifications
- Develop and implement algorithms through the process of top-down, stepwise refinement.
- Design and develop programs that use functions to input data from the standard input stream and output data to the standard output stream.
- Implement programming solutions which use selection, repetition, and sequential control structures where appropriate.
- Demonstrate through program development the use of the various arithmetic, assignment and logical operators.
- Construct modular programs using functions that pass arguments both by value and by reference
- Write programs demonstrating the use of one-and two-dimensional arrays and strings.
- Pre-conditions and post-conditions clearly stated for all functions.
- Thorough inline documentation for all code.
- No Global variables except for constants.
- Function prototypes for all programmer defined functions.
- Function main() will drive the application and will:
- Declare all necessary variables, including arrays
- Initialize the state of the Theater (all seats will initially be available)
- Allow the user to Select the performance number to determine which prices file to use for pricing. (Note that seat prices will vary depending on the performance selected)
- Invoke user defined functions as necessary. Some functions may be void, some may return values. Functions will have parameters. Some will be value parameters some may be reference parameters.
- Execute until the user decides to exit the program.
- You must have individual functions for the following
- A function that populates an array with the prices read from the prices file specified by the user
- Displaying the Menu (see the test run). This function will display a menu from which the user can make selections.
- A function that gets the users choice of menu option and returns that choice as an int. The user will be prompted to enter a selection.
- A function that displays the current state of all of the seats in the theater (available or sold) (see the test run)
- A function that displays the prices of the seats in the theater. (see the test run)
- A function that displays the total sales of all tickets sold (see the test run)
- A function that handles ticket purchases and displays a summary of a purchase by a particular patron (See the test run)
- You should create stubs for any functions not completed or not working properly.
- Document any enhancements you might make beyond the basic requirements.
- Input validation – validate data as specified above
- Your functions must be cohesive. They should focus on doing a single thing. Most functions that you create should be between 5 and 15 lines. Anything longer probably needs to be decomposed into additional functions.
- At a minimum, you must test your program using the below Test Run. You should also test for valid user input.
Academic Honesty: (Details regarding Academic Honesty Guidelines can be found in the College Catalog on page 49)
The College Catalog states: One of the missions of Camden County College is: "… preparing students to be continuous learners who succeed upon transfer, work effectively in the contemporary workplace and function as citizens and leaders in their community." The goal of course assignments is to ensure that students master the course material. Dishonesty in fulfilling any assignment undermines the learning process and the integrity of the college degree. All students are expected to do their own work. All forms of academic dishonesty are absolutely forbidden. Engaging in dishonest or unethical behavior may result in disciplinary action taken by the instructor, or other appropriate College official.
Lifting code from online sources is dishonest and a violation of the Academic Honesty Policy.
Among the consequences for violating the Academic Honesty Policy are failing the course and expulsion.
Students who violate the College’s Academic Honesty policy for Project # 2 will receive a grade of 0 for the project and be subject to failing the course.
Project Submission:
- Name your source file “yourlastnamefirstnameProject2.cpp”.
- You will need to submit along with your .cpp file a Word document describing any aspects of the project that were not completed or are not working properly. List any functions that have been implemented as stubs. Also include in the document any enhancements that you made beyond the basic requirements. Name this file “yourlastnamefirstnamedescription”.
- Submit your project via the Project # 2 submission link in Canvas.
- Any of the requirements listed in the project requirements document that are missing or incomplete will result in a deduction to your grade. So make sure you read these requirements carefully. If you have questions about the requirements, make sure you contact me.
- The projects will be due at on 5/11/2021. Make note of the fact that the link for the project will close on 5/11. No submissions will be accepted after 11:59 pm on 5/11. Projects not submitted by the deadline will receive a grade of 0. Incomplete projects will receive consideration for partial credit, so make sure you submit whatever you have completed before the deadline.
In light of these facts, I strongly recommend that you complete the project and submit it before the due date. I will not be answering questions related to the project on 5/11, so get moving on this project asap.
Test Run
Select your performance (1, 2, or 3): 4
Invalid entry - Select your performance (1, 2, or 3): 3
Loading Prices for performance
Ticket Prices By Row
Row Price
--- -----
- 40.00
- 40.00
- 40.00
- 40.00
- 40.00
- 30.00
- 30.00
- 30.00
- 30.00
- 30.00
- 20.00
- 20.00
- 20.00
- 20.00
- 20.00
Press c to continue and then press return: c
CSC121 Theatre
- View Available Seats
- View Seating Prices
- View Ticket Sales
- Purchase a Ticket
- Exit the Program
Enter your choice(1-5): 1
Seats
12345678910
Row 1 AAAAAAAAAA
Row 2 AAAAAAAAAA
Row 3 AAAAAAAAAA
Row 4 AAAAAAAAAA
Row 5 AAAAAAAAAA
Row 6 AAAAAAAAAA
Row 7 AAAAAAAAAA
Row 8 AAAAAAAAAA
Row 9 AAAAAAAAAA
Row 10 AAAAAAAAAA
Row 11 AAAAAAAAAA
Row 12 AAAAAAAAAA
Row 13 AAAAAAAAAA
Row 14 AAAAAAAAAA
Row 15 AAAAAAAAAA
Legend: S = Sold
A = Available
Press c to continue and then press return: c
CSC121 Theatre
- View Available Seats
- View Seating Prices
- View Ticket Sales
- Purchase a Ticket
- Exit the Program
Enter your choice(1-5): 4
C++ Theatre
Ticket Purchase Opportunity
Do you wish to view the chart of available seats
before making your selections (y/n)? n
Please enter desired row number (1-15): 1
Please enter desired seat number (1-10): 1
Purchase confirmed
Would you like to purchase another seat (y/n)? y
Please enter desired row number (1-15): 1
Please enter desired seat number (1-10): 2
Purchase confirmed
Would you like to purchase another seat (y/n)? Y
Please enter desired row number (1-15): 12
Please enter desired seat number (1-10): 10
Purchase confirmed
Please enter desired row number (1-15): 1
Please enter desired seat number (1-10): 2
Sorry. That seat has been sold.
Would you like to purchase another seat (y/n)? Y
Please enter desired row number (1-15): 12
Please enter desired seat number (1-10): 9
Purchase confirmed
Would you like to purchase another seat (y/n)? n
You have purchased a total of 4 tickets for a total price of $120.00
CSC121 Theatre
- View Available Seats
- View Seating Prices
- View Ticket Sales
- Purchase a Ticket
- Exit the Program
Enter your choice(1-5): 1
Seats
12345678910
Row 1 SSAAAAAAAA
Row 2 AAAAAAAAAA
Row 3 AAAAAAAAAA
Row 4 AAAAAAAAAA
Row 5 AAAAAAAAAA
Row 6 AAAAAAAAAA
Row 7 AAAAAAAAAA
Row 8 AAAAAAAAAA
Row 9 AAAAAAAAAA
Row 10 AAAAAAAAAA
Row 11 AAAAAAAAAA
Row 12 AAAAAAAASS
Row 13 AAAAAAAAAA
Row 14 AAAAAAAAAA
Row 15 AAAAAAAAAA
Legend: S = Sold
A = Available
Press c to continue and then press return: c
CSC121 Theatre
- View Available Seats
- View Seating Prices
- View Ticket Sales
- Purchase a Ticket
- Exit the Program
Enter your choice(1-5): 4
C++ Theatre
Ticket Purchase Opportunity
Do you wish to view the chart of available seats
before making your selections (y/n)? n
Please enter desired row number (1-15): 10
Please enter desired seat number (1-10): 4
Purchase confirmed
Would you like to purchase another seat (y/n)? y
Please enter desired row number (1-15): 10
Please enter desired seat number (1-10): 5
Purchase confirmed
Would you like to purchase another seat (y/n)? n
You have purchased a total of 2 tickets for a total price of $60.00
CSC121 Theatre
- View Available Seats
- View Seating Prices
- View Ticket Sales
- Purchase a Ticket
- Exit the Program
Enter your choice(1-5): 1
Seats
12345678910
Row 1 SSAAAAAAAA
Row 2 AAAAAAAAAA
Row 3 AAAAAAAAAA
Row 4 AAAAAAAAAA
Row 5 AAAAAAAAAA
Row 6 AAAAAAAAAA
Row 7 AAAAAAAAAA
Row 8 AAAAAAAAAA
Row 9 AAAAAAAAAA
Row 10 AAASSAAAAA
Row 11 AAAAAAAAAA
Row 12 AAAAAAAASS
Row 13 AAAAAAAAAA
Row 14 AAAAAAAAAA
Row 15 AAAAAAAAAA
Legend: S = Sold
A = Available
Press c to continue and then press return: c
CSC121 Theatre
- View Available Seats
- View Seating Prices
- View Ticket Sales
- Purchase a Ticket
- Exit the Program
Enter your choice(1-5): 3
Total Sales to Date: $180.00
CSC121 Theatre
- View Available Seats
- View Seating Prices
- View Ticket Sales
- Purchase a Ticket
- Exit the Program
Enter your choice(1-5): 7
Choice must be between 1 and 5. Please re-enter: 5
C:\#Bill\MyVSProjects\CSC121Project2Spring2021\Debug\CSC121Project2Spring2021.exe (process 344) exited with code 0.
Press any key to close this window . . .
Source Code
#include
#include
#include
#include
#include
using namespace std;
const int MAX_ROWS = 15;
const int MAX_COLS = 10;
const char AVAILABLE = 'A';
const char SOLD = 'S';
// Let the user enter a key then presses enter
void pause()
{
cout << "Press c to continue and then press return: ";
char c;
cin >> c;
cout << endl;
}
// Load the prices from a file
void loadSeatingPrices(double seatingPrices[MAX_ROWS])
{
// Get a valid performance number
cout << "Select your performance (1, 2, or 3): ";
int performance;
cin >> performance;
while (performance < 1 || performance > 3)
{
cout << "Invalid entry - Select your performance (1, 2, or 3): ";
cin >> performance;
}
// Load the prices from file
stringstream ss;
ss << "prices" << performance << ".txt";
string filename = ss.str();
// Open the file
ifstream inFile(filename.c_str());
if (!inFile.is_open())
{
cout << "Error: failed to open " << filename << endl;
exit(0);
}
cout << endl;
cout << "Loading Prices for performance" << endl;
cout << endl;
// Put the prices into the array
int rowNumber;
double price;
while (inFile >> rowNumber >> price)
seatingPrices[rowNumber - 1] = price;
inFile.close();
}
// Print the table of prices
void viewSeatingPrices(const double rowPrices[MAX_ROWS])
{
cout << "Ticket Prices By Row" << endl;
cout << setw(10) << right << "Row" << setw(10) << right << "Price" << endl;
cout << setw(10) << right << "---" << setw(10) << right << "-----" << endl;
for (int row = 0; row < MAX_ROWS; row++)
cout << setw(10) << right << (row + 1) << setw(10) << right << fixed << setprecision(2) << rowPrices[row] << endl;
pause();
}
// Make all seats empty
void initializeSeats(char seats[MAX_ROWS][MAX_COLS])
{
for (int row = 0; row < MAX_ROWS; row++)
for (int col = 0; col < MAX_COLS; col++)
seats[row][col] = AVAILABLE;
}
// Print out all the seats
void viewSeats(const char seats[MAX_ROWS][MAX_COLS])
{
cout << setw(15) << right << "Seats" << endl;
// Print column labels
cout << setw(8) << "";
for (int col = 0; col < MAX_COLS; col++)
cout << (col + 1);
cout << endl;
// Print each row
for (int row = 0; row < MAX_ROWS; row++)
{
cout << "Row" << setw(3) << right << (row + 1) << " ";
for (int col = 0; col < MAX_COLS; col++)
cout << seats[row][col];
cout << endl;
}
cout << endl;
cout << setw(8) << "" << "Legend: S = Sold" << endl;
cout << setw(8) << "" << " A = Available" << endl;
pause();
}
// Purchase a ticket
double purchaseTicket(const double seatingPrices[MAX_ROWS], char seats[MAX_ROWS][MAX_COLS])
{
// Print out the seats if the user wishes to
cout << " C++ Theatre" << endl;
cout << " Ticket Purchase Opportunity" << endl;
cout << "Do you wish to view the chart of available seats before making your selections (y/n)? ";
char response;
cin >> response;
if (response == 'y' || response == 'Y')
viewSeats(seats);
// Ask for the desired seat to purchase
char again = 'Y';
int numTickets = 0;
double totalCost = 0;
while (again == 'Y' || again == 'y')
{
cout << "Please enter desired row number (1-15): ";
int row;
cin >> row;
cout << "Please enter desired seat number (1-10): ";
int col;
cin >> col;
row--;
col--;
// Check if within range
if (row < 0 || row >= MAX_ROWS || col < 0 || col >= MAX_COLS)
{
cout << "Error: Invalid seat location." << endl;
}
else if (seats[row][col] == SOLD)
{
// Check that it is available
cout << "Sorry. That seat has been sold." << endl;
}
else
{
// Purchase if available
seats[row][col] = SOLD;
cout << "Purchase confirmed" << endl;
numTickets++;
totalCost += seatingPrices[row];
}
// Ask if interested for another purchase
cout << "Would you like to purchase another seat (y/n)? ";
cin >> again;
}
cout << endl;
cout << "You have purchased a total of " << numTickets << " for a total price of $" << fixed << setprecision(2) << totalCost << endl;
return totalCost;
}
// Entry point of the program
int main()
{
// Start by loading the prices from file
double seatingPrices[MAX_ROWS];
loadSeatingPrices(seatingPrices);
viewSeatingPrices(seatingPrices);
// Initialize the empty seats
char seats[MAX_ROWS][MAX_COLS];
initializeSeats(seats);
double totalSales = 0;
bool quit = false;
while (!quit)
{
// Ask the user what to do
cout << " CSC121 Theatre" << endl;
cout << "1. View Available Seats" << endl;
cout << "2. View Seating Prices" << endl;
cout << "3. View Ticket Sales" << endl;
cout << "4. Purchase a Ticket" << endl;
cout << "5. Exit the Program" << endl;
cout << "Enter your choice (1-5): ";
int choice;
cin >> choice;
cout << endl;
// Execute user's choice
switch (choice)
{
case 1:
viewSeats(seats);
break;
case 2:
viewSeatingPrices(seatingPrices);
break;
case 3:
cout << "Total Sales to Date: $" << fixed << setprecision(2) << totalSales << endl;
break;
case 4:
totalSales += purchaseTicket(seatingPrices, seats);
reak;
case 5:
quit = true;
break;
default:
cout << "Choice must be between 1 and 5." << endl;
}
cout << endl;
}
return 0;
}