Theater Ticket Sales Project

When i run the program it runs into an error when displaying. mostly in the seatarrArrangment fuction and it displays odd characters other than the ones in the file this is the output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Row 1 @ºΘ@Cw( 0<ⁿ▐ P< ñ( ╥ iyIL
Row 2  : Φ≡ î °S╠╔ ÿ ?îº
Row 3 Θ╪CwWy ╚° î mCwm2╨000 áp
á
Row 4 P ─ A á°Rp9$pºΘxCwW!¿▄┤ ⁿ
Row 5 ! mdß ─ │░ ╖W @t ╪6° °°
Row 6 NΣ¼╠ $,4<DLT\DLT|RRñ¼┤╝─
Row 7 ╠╘▄─╠╘▄╠ $,4<DLT\dlt|RSñ¼
Row 8 ┤╝─╠╘▄Σ∞⌠ⁿ║¼Σ╚ ( äü
Row 9 é╘ \╘Xîd ⁿ ╘& s 
Row 10 $╨OXÇεX xk xφh╨ñ └ê╨ 8rΓ0╚
 └pX< ╨ T aä@∞=┐ ╨ß|XX
Row 12 `@ ⌠⌠ <òh áH╝ É ░░>Ec
Row 13 el  ≡┴  
Row 14   w  d ?┴Æ α p$ α É?
Row 15 ╠Φ!@Çh  ■K $P P$Θσαá

i cant figure out how to fix it please help!

#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct Seat
{
double cost;
char valid;
};

ifstream fileprices("SeatPrices.dat");
ifstream fileseats("SeatsAvailability.dat");
ofstream fileresults("SeatsResults.dat");

class TicketManager
{
private:
Seat aud[15][30];
int seat;
double price;
public:
void update(int number, int row, int colum);
void priceList();
void order(int , int , int , char& );
void seatarrAngement();
void print();
TicketManager();
~TicketManager();
};

//constructor
TicketManager::TicketManager()
{
//declare variables
seat = 0; price = 0;
double price;
//use a for loop to read prices from the file
for(int row = 0; row < 15; row++)
{
fileprices >> price;
for(int col = 0; col < 30; col++)
{
aud[row][col].cost = price;
fileseats >> aud[row][col].valid;
}
}
}

//destructor
TicketManager::~TicketManager()
{
for(int row = 0; row < 15; row++)
{
fileresults << "Row" << left << setw(8) << row + 1;
for(int col = 0; col < 30; col++)
{
fileresults << aud[row][col].valid;
}
fileresults << endl;
}
fileresults << "Seats Sold:" << seat << endl;
fileresults << "Seats Available:" << (15 * 30) - seat << endl;
fileresults << "Amount: $" << price << endl;
fileresults.close();
}

//priceList member function
void TicketManager::priceList()
{
for(int row = 0; row < 15; row++)
{
for(int col = 0; col < 30; col++)
{

cout << aud[row][col].cost << " ";
}
cout << endl;
}
}

//seatarrAngement membe function
void TicketManager::seatarrAngement()
{

cout << "Legend : * = Sold " << endl;
cout << " # = Available" << endl;
cout << endl;
cout << " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 " << endl;
string line;

for(int row = 0; row < 15; row++)
{
cout << "Row " << left << setw(8) << (row + 1);
for(int col = 0; col < 30; col++)
{
cout << aud[row][col].valid;
}

cout << endl;
}
}

//order member function
void TicketManager::order(int number, int rowNum, int startNum, char& purchase)
{
bool order = true;
for(int x =0; x < number; x++)
{
if(aud[rowNum][startNum + x].valid == '*')
{
cout << "Seats are not available" << endl;
order = false;
purchase = 'N';
break;
}
}

if(order)
{
cout << "The number of seats are " << number << endl;
cout << "The price for each seat: $" << aud[rowNum][0].cost << endl;
cout << "The total cost is: $" << aud[rowNum][0].cost * number << endl;
cout << endl;
cout << "Do you want to purchase these seats? (Y/N) ";
cin >> purchase;
}

}


//update seats member function
void TicketManager::update(int number, int row, int colum)
{
for(int x = 0; x < number; x++)
{
aud[row][colum + x].valid = '*';
}
}

//print member function
void TicketManager::print()
{
for(int row = 0; row < 15; row++)
{
for(int col = 0; col < 30; col++)
{

if(aud[row][col].valid== '*')
{
seat++;
price += aud[row][col].cost;
}
}
}

cout << "Seats Sold: " << seat << endl;
cout << "Seats Available: " << (15 * 30) - seat << endl;
cout << "Money Collected: $" << price << endl;
}



//driver main
int main()
{
//declare variables
string i;
int op, row, amount, seat1;
char purchase;
TicketManager aud;
cout << fixed << setprecision(2);
do
{
cout << " Menu " << endl;
cout << " 1.Seating Chart " << endl;
cout << " 2.Request Tickets " << endl;
cout << " 3.Print Sales " << endl;
cout << " 4.Exit " << endl;
cin >> op;

while (op < 1 || op > 4)
{
cout << "Enter Your Choice Again!" << endl;
cin >> op;
}

switch (op)
{
case 1:
cout << endl;
cout << "Display the Seating Chart" << endl;
aud.seatarrAngement();
break;

case 2:
cout << "Enter the No. of seats requesting: ";
cin >> amount;
cout << "Enter the row number: ";
cin >> row;
cout << "Enter the column number: ";
cin >> seat1;
aud.order(amount,row,seat1,purchase);

if(toupper(purchase) == 'Y')
{
cout << "The Seats have been purchased" << endl;
aud.update(amount,row,seat1);
}
else
{
cout << "The Seats are availiable" << endl;
}
break;
case 3:
cout << endl << "print" << endl;
aud.print();
break;
case 4:
break;
}
cout << endl;
}

while(op != 4);
fileprices.close();
fileseats.close();
system("pause");
return 0;
}
closed account (SECMoG1T)
whenever you open a file it is your obligation to check if that file opened successfully, otherwise you might be using an invalid filestream.

1
2
3
4
5
6
7
8
9
10
11

std::ifstream fileprices("SeatPrices.dat");///this stream might  fail if the file isn't in the working dir

if(fileprices)
{
  ///use fileprices
}

else
  ///handle stream errors
Topic archived. No new replies allowed.