Hello again, I'm having trouble with a program that I have to write involving classes and arrays. Essentially i have to create a class Theater, which I am not sure how to do. The theater has 15 rows with 30 seats per row, and each row is assigned a price for each seat, inputted from a text file. I cannot seem to get the 2d array to work properly. The user should be able to purchase a specific seat using the inputted prices, which keeps a running total of seats purchased. The output should show each row and seat and put a * if the seat is purchased and a # if the seat is available.

This is what I have so far, please let me know if it is to sloppy and I will do my best to make it cleaner, sorry.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib> 
using namespace std;

void menu();
void purchase();
void total_value();
void total_number();
void seats_row();
void seats_all();
void seating_chart();

void get_price()
{
    int i;
    ifstream fin;
    fin.open("seats.txt");
    int price[15];
    for(i=1; i<16; i++)
    {
        fin >> price[i];
        cout << "Row " << i << " is $" << price[i] << endl;
    }
}

void purchase()
{
    int seat;
    int row;
    int total;
    do
    {
        do
        {
            cout << "-------- Purchase Seats --------" << endl
                 << "Enter the row and seat number desired." << endl
                 << "There are 15 rows and 30 seats per row." << endl
                 << "Enter -1 for the Row Number When You are Done." << endl;
            cout << "Row Number: ";
            cin >> row;
            if(row == -1)
            {
                cin.sync();
                menu();
            }
            cout << "Seat Number: ";
            cin >> seat;
            cout << endl;
        }while(row > 0);
        if(row < 1 || row > 15 || seat < 1 || seat > 30)
            cout << "You must enter an appropriate value.\n\n";
    }while(row < 1 || row > 15 || seat < 1 || seat > 30);
}

void total_value()
{
    get_price();
}

void total_number()
{
}

void seats_row()
{
}

void seats_all()
{
}

void seating_chart()
{
    int i,j;
    double theater[15][30];
    for(i=0; i<15; i++)
    {
        for(j=0; j<30; j++)
        {
            cin >> theater[i][j];
            cout << theater[i][j];
        }
    }
    
}

// MENU

void menu()
{
    int choice;
    do
    {
        cout << "Choose One of the Following." << endl
             << "(1) Purchase Tickets." << endl
             << "(2) Display Total Dollar Value of All Tickets Sold." << endl
             << "(3) Display Total Number of Tickets Sold." << endl
             << "(4) Display the Number of Seats Available in Each Row." << endl
             << "(5) Display the Number of Seats Available in the Entire Auditorium." << endl
             << "(6) Display the Current Seating Chart." << endl
             << "(7) Exit the System." << endl
             << "Choice: ";
        cin >> choice;
        if(choice < 1 || choice > 7)
            cout << "You must enter a number 1 through 7." << endl;;
        cout << endl;
    }while(choice < 1 || choice > 7);

    if(choice == 1)
        purchase();
    if(choice == 2)
        total_value();
    if(choice == 3)
        total_number();
    if(choice == 4)
        seats_row();
    if(choice == 5)
        seats_all();
    if(choice == 6)
        seating_chart();
    if(choice == 7)
        exit(1);

}

// MAIN FUNCTION

int main()
{
    menu();
    return 0;
}

Recommended Answers

All 5 Replies

I have helped you out by writing what I think you want and put it into a "cleaner" format (could be more clean) and divided it into seperate files for structure. (file allinone.cpp is the whole thing in one file if this is for school and they want it in one)

I did my best to comment lines to show you what is going on.

I attached all the files.

wow thanks a lot, im fairly sure i can work through it now, much appreciated.

I see you just took the allinone.cpp if you actually want to learn some form of structure for coding bigger projects I suggest you look at the divided files and then look at the single. I find looking at something with 500+ lines a little overwhelming when you are just starting out.

Yeah that may help, I'm just using them as guidelines and re-writing what i originally had. Thanks

Got it. Thanks for the help, much appreciated.

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.