problem with code

wat im trying to do is to allow the user to select a show and than select by row and by column where they would like to sit and than append this value to a file using the value X so that this seat can not be chosen again if another user enters the same row number and column number.

i have a function which checks this but i am unsure on how to use a two dimensional array to read in the file and than append a value to the file in a specific spot that has been selected by row and by column.

this is the code i have come up with so far...

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
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <iomanip>
using std::ifstream;
using std::ofstream;
using std::endl;
using std::cout;
using std::ios;
using namespace std;

class ticketSelling
{
      private:
              string show;
              string day;
              string classType;
              int row;
              int column;
              char bookKeeper[14][30];
              void checkAvailability();
      public:
             void setPerformance(string, string);
             void sellTicket(string, string, string);
             };
                 
void ticketSelling::checkAvailability(){
     
    ifstream infile;
    infile.open("seatsConfig.txt", ios::app);
    
    if (infile.fail())
    {
       cout <<"file does not exist"<<endl;
       }
    else{
		cout<<"Checking availabilities..."<<endl<<endl;
		for (int i = 0; i < row; ++i) 
			for (int j = 0; j < column; ++j) 

				infile >> bookKeeper[i][j];     
	}
    infile.close();
    
};
     
     
void ticketSelling::setPerformance(string selection, string cT)
{
     int row, column;
     
     cout<<"Please choose from the list below which show you would like to see:"<<endl; 
     cout<<"(Enter either selection1, selection2 or selection3)"<<endl;
     cout<<"1. Guys and dolls"<<endl;
     cout<<"2. Mamma mia"<<endl;
     cout<<"3. The phantom of the opera"<<endl<<endl;
     cin>>selection;
     
     if (selection == "selection1")
     {
                   show= "Guys and dolls";
                   day= "Thursday Night Premiere";
                   cout<<show<<endl<<day<<endl;
                   }
                   
     else if (selection == "selection2")
     {
          show= "Mamma mia";
          day= "Saturday night premiere";
          cout<<show<<endl<<day<<endl;
          }
          
     else if (selection == "selection3")
     {
          show= "The phantom of the opera";
          day= "Sunday Night Premiere";
          cout<<show<<endl<<day<<endl;
          }
          
     else 
     {
          cout<<"You have not selected a show please enter either 1, 2 or 3 for a show you would like to see."<<endl<<endl;
          }
          
     cout<<endl;
     cout<<"Which class would you like to be seated in classA, classB, classC or classD? "<<endl;
     cin>>classType;
     
     if (classType == "classA")
     {
                   
                   classType= "$120";
                   cout<<classType<<endl;
                   }
                   
     else if (classType == "classB")
     {
          classType= "$90";
          cout<<classType<<endl;
          }
          
     else if (classType == "classC")
     {
          classType= "$60";
          cout<<classType<<endl;
          }
          
     else if (classType == "classD")
     {
          classType= "$30";
          cout<<classType<<endl;
          }
          
     else
     {
         cout<<"You have not entered a valid class type"<<endl;
         
         }
         
     cout<<"please enter the row in which you would like to be seated in (1-14)?"<<endl;
     cin>>row;
     cout<<"please select which column you would like to be seated in (1-30)?"<<endl;
     cin>>column;
     checkAvailability();
         
         
     
};
     
void ticketSelling::sellTicket(string s, string d, string cT)
{
     string ticketSell;
     cout<<"Would you like to purchase this ticket"<<endl;
     cout<<"Please enter yes or no:"<<endl;
     cin>>ticketSell;
     
      
     if (ticketSell == "yes")
     {
                    ofstream ticket;

                    s=show;
                    d=day;
                    cT=classType;
                                      
                    
                    ticket.open("ticket.txt");
                    
                    if (ticket.fail())
                    {
                       cout<<"Opening of file has failed"<<endl;
                       }
                cout<<"your ticket is now being printed..."<<endl;       
              ticket << "The Natasha Theatre"<<endl;
              ticket << "Tonight you will be viewing "<<show<<endl;
              ticket << "You will be seated in "<<row<<"_"<<column<<endl;
              ticket << "At a cost of: "<<classType<<endl;
              
             ticket << day << endl;
              
              }
              
              else
              {
                  cout<<"Thank you for your time please press enter to exit this screen. Thank you."<<endl;
                  }
     
     };


could you please tell me if im going down the right track and if not could you please show me how to implement this properley...

Thanks in advance
Last edited on
hmmm... dont want to discourage but it looks you are not going in correct direction.

ticket << "The Natasha Theatre"<<endl;
ticket << "Tonight you will be viewing "<<show<<endl;
ticket << "You will be seated in "<<row<<"_"<<column<<endl;
ticket << "At a cost of: "<<classType<<endl;

why are you putting all this in your data file..
"like you will be seated in"
, where will you search for your real data.. for each booking all this will be saved in the file. from where row and column is coming??

the first step should be to design your data file and your class, what all things should be in the data file. like row/column, day, time, show type.. etc etc.. then implement it.

its hard work but if you correct the mistakes early it will save lot of your time.
does all this makes any sense??


oh no i created a seperate file called ticket so it prints out wat the user has chosen from the prompted output.

This is what i have altered i have decided not to append the file and just use the array to iterate through each value to add an "x" to show that this "seat" is no longer available.

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
185
186
187
188
189
190
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <iomanip>
using std::ifstream;
using std::ofstream;
using std::endl;
using std::cout;
using std::ios;
using namespace std;

class ticketSelling
{
      private:
              string show;
              string day;
              string classType;
              int row;
              int column;
              char bookKeeper[14][30];
              char checkAvailability();
              char loadSeating();
      public:
             void setPerformance(string, string);
             void sellTicket(string, string, string);
             };
                 
char ticketSelling::loadSeating(){
     
    ifstream infile;
    infile.open("seatsConfig.txt");
    
    if (infile.fail())
    {
       cout <<"file does not exist"<<endl;
       }
    else{
		cout<<"Checking availabilities..."<<endl<<endl;
		for (int i = 0; i < 14; ++i) 
			for (int j = 0; j < 30; ++j) 

				infile >> bookKeeper[i][j];     
	}
    infile.close();
    
};

char checkAvailability(){
     if ( bookKeeper [row][column] == "x")
     {
           cout<<"Sorry this seat has already been booked. Please make another selection"<<endl;
            }
     else
     {
         bookKeeper[row][column] = "x";
         }
};
     
     
void ticketSelling::setPerformance(string selection, string cT)
{
     
     cout<<"Please choose from the list below which show you would like to see:"<<endl; 
     cout<<"(Enter either selection1, selection2 or selection3)"<<endl;
     cout<<"1. Guys and dolls"<<endl;
     cout<<"2. Mamma mia"<<endl;
     cout<<"3. The phantom of the opera"<<endl<<endl;
     cin>>selection;
     
     if (selection == "selection1")
     {
                   show= "Guys and dolls";
                   day= "Thursday Night Premiere";
                   cout<<show<<endl<<day<<endl;
                   }
                   
     else if (selection == "selection2")
     {
          show= "Mamma mia";
          day= "Saturday night premiere";
          cout<<show<<endl<<day<<endl;
          }
          
     else if (selection == "selection3")
     {
          show= "The phantom of the opera";
          day= "Sunday Night Premiere";
          cout<<show<<endl<<day<<endl;
          }
          
     else 
     {
          cout<<"You have not selected a show please enter either 1, 2 or 3 for a show you would like to see."<<endl<<endl;
          }
          
     cout<<endl;
     cout<<"Which class would you like to be seated in classA, classB, classC or classD? "<<endl;
     cin>>classType;
     
     if (classType == "classA")
     {
                   
                   classType= "$120";
                   cout<<classType<<endl;
                   }
                   
     else if (classType == "classB")
     {
          classType= "$90";
          cout<<classType<<endl;
          }
          
     else if (classType == "classC")
     {
          classType= "$60";
          cout<<classType<<endl;
          }
          
     else if (classType == "classD")
     {
          classType= "$30";
          cout<<classType<<endl;
          }
          
     else
     {
         cout<<"You have not entered a valid class type"<<endl;
         
         }
         
       loadSeating();   
     cout<<"Below is the formation of the auditorium below: "<<endl<<endl;    
     for (int index1=0; index1<14; index1++) {
                for (int index2=0; index2<30; index2++)
                        cout << bookKeeper[index1][index2];
		cout << endl<<endl;
	}
     
     cout<<"please enter the row in which you would like to be seated in (1-14)?"<<endl;
     cin>>row;
     cout<<"please select which column you would like to be seated in (1-30)?"<<endl;
     cin>>column;
     
     checkAvailability();
    
         
         
     
};
     
void ticketSelling::sellTicket(string s, string d, string cT)
{
     string ticketSell;
     cout<<"Would you like to purchase this ticket"<<endl;
     cout<<"Please enter yes or no:"<<endl;
     cin>>ticketSell;
     
      
     if (ticketSell == "yes")
     {
                    ofstream ticket;

                    s=show;
                    d=day;
                    cT=classType;
                                      
                    
                    ticket.open("ticket.txt");
                    
                    if (ticket.fail())
                    {
                       cout<<"Opening of file has failed"<<endl;
                       }
                cout<<"your ticket is now being printed..."<<endl;       
              ticket << "      The Natasha Theatre"<<endl<<endl;;
              ticket << "Tonight you will be viewing "<<show<<endl;
              ticket << "You will be seated in "<<row<<"_"<<column<<endl;
              ticket << "At a cost of: "<<classType<<endl;
              
             ticket << day << endl;
              
              }
              
              else
              {
                  cout<<"Thank you for your time please press enter to exit this screen. Thank you."<<endl;
                  }
     
     };


The only problem i have with this code at the moment is that its saying that my bookkeeper variable and row and column variable is undeclared so im unsure as to why this has happened.
Topic archived. No new replies allowed.