#include <iostream>
#include <iomanip>
#include <fstream>
#include "groupProj.h"
using namespace std;
const char Avail = '#';
const char Taken = '*';
const int r = 15;
const int c = 30;
char SEATS[r][c];
int main()
{
// Declarations for main
ifstream inputPrices;
double seatPrices[15];
int row;
int column;
double cost;
double totalSales = 0.0;
int answer;
int confirm;
int choice;
int seat1 = 450;
int seat2 = 0;
//**********************************************
// Open the file
inputPrices.open("SeatPrices.txt");
if (!inputPrices)
{
cout << "Error opening the file!\n";
return 1;
}
// Input the prices from file into an array
for (int h = 0; h < 15; h++)
{
inputPrices >> seatPrices[h];
}
//**********************************************
cout << " Welcome to Rachel's Theater!\n\n\n";
for (int i = 0; i < 15; i++)
{
for (int j = 0; j < 30; j++)
{
SEATS[i][j] = Avail;
}
}
do
{
displayMenu();
cin >> choice;
cout << "\n";
switch (choice)
{
case 1: cout << " You have chosen to view the seat prices.\n\n";
for (int k = 0; k < 15; k++)
{
inputPrices >> seatPrices[k];
cout << " The price for row " << (k + 1)
<< " is: $" << seatPrices[k] << endl;
cout << "\n";
}
break;
case 2: cout << " You have chosen to purchase a ticket.\n\n";
do
{
cout << " *Be sure to pick a valid row, 1-15 and seat, 1-30* \n\n";
cout << " Please select the row you'd like to sit in: ";
cin >> row;
cout << " Please select the seat you'd like to sit in: ";
cin >> column;
if (SEATS[row-1][column-1] == '*')
{
cout << "\n";
cout << " Sorry, that seat is taken, please select another.\n\n";
break;
}
if (SEATS[row-1][column-1] != '*')
{
cost = seatPrices[row-1] + 0; // To get the correct price
cout << " That ticket costs: " << cost << endl;
cout << " Confirm Purchase? Enter (1 = YES / 2 = NO): ";
cin >> answer;
if (answer == 1)
{
seat1 = seat1 - answer;
seat2 += answer;
}
if (answer == 1)
{
totalSales += seatPrices[row-1];
cout << "\n";
cout << " Your ticket purchase has been confirmed.\n\n";
SEATS[row-1][column-1] = Taken;
break;
}
else if (answer == 2)
{
cout << "\n";
cout << " Would you like to purchase a different seat? (1 = YES / 2 = NO): ";
cin >> confirm;
cout << "\n";
}
}
} while (confirm == 1);
break;
case 3: cout << " You have chosen to view the available seats.\n\n";
displaySeats();
cout << "\n";
break;
case 4: cout << " You have chosen to view the ticket sales.\n\n";
cout << " Total of sales so far: $" << totalSales << endl;
cout << "\n";
break;
case 5: cout << " You have chosen to view the number of seats.\n\n";
cout << " The number of seats available: " << seat1 << endl;
cout << " The number of seats sold: " << seat2 << endl;
cout << "\n";
break;
case 6: cout << " Ending the Program.\n\n";
break;
default : cout << " Please enter a choice in the range of 1-5.\n\n";
}
} while (choice != 6);
return 0;
}
//********************Function mains************************
void displayMenu()
{
cout << " Menu Selection\n\n";
cout << " 1. View Seat Prices\n";
cout << " 2. Purchase a Ticket\n";
cout << " 3. View Available Seats\n";
cout << " 4. View Ticket Sales\n";
cout << " 5. View Number of Seats\n";
cout << " 6. Exit\n\n";
cout << " Enter a choice from the Menu Selection: ";
}
void displaySeats()
{
cout << "\n";
cout << " Seats\n\n";
cout << " 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0\n";
for (int count1 = 0; count1 < 15; count1++)
{
cout << endl << "Row " << (count1 + 1);
for (int count2 = 0; count2 < 30; count2++)
{
cout << " " << SEATS[count1][count2];
}
}
cout << "\n";
}
Rachel Ard 0 Newbie Poster
Rachel Ard 0 Newbie Poster
vmanes 1,165 Posting Virtuoso
Rachel Ard 0 Newbie Poster
vmanes 1,165 Posting Virtuoso
Rachel Ard 0 Newbie Poster
Rachel Ard 0 Newbie Poster
vmanes 1,165 Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.