Fix The Code Below
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
#define ROWS 25
#define SEATS 6
void int_seats(char array[][SEATS], int elements);
void seat_map(char seats[ROWS][SEATS]);
unsigned int count_seats(char seats[ROWS][SEATS]);
int main(void)
{
char section[ROWS][SEATS] = {0};
unsigned int i = 0, j = 0, row = 0, seat = 0,
seats_available = 0, elements=0;
string answer;
//Initialize seats with random value of 'x' or '0'
int_seats(section, ROWS);
//Print a map of the section
seat_map(section);
//Determine the number of seats available
seats_available = count_seats(section);
//Sell a seat to customer
cout<<endl<<" Do you want to buy a
ticket? Y/N "<<endl;
getline(cin, answer);
if(seats_available == 0)
{
cout<<"Sorry, This flight is
full."<<endl;
system("pause");
return 0;
}
while (answer.at(0)== 'Y')
{
cout<<"There
are"<<seats_available<<"seats
available."<<endl;
cout<<"SELECT YOUR
SEAT"<<endl<<endl;
seat_map(section);
cout<<"Enter the row and seat
number:"<<endl;
cin>>row>>seat;
cin.ignore(100, '\n');
if (section[row - 1][seat - 1] == '0');
{
section[row -1][seat - 1] = 'x'; //mark
seat as sold
seats_available;
cout<<"You just purchased
seat"<<seat<<" in row "<<row<<endl
<< "Thank you for
your order."<<endl<<endl;
}
{
cout<<"Sorry, The seat is taken,
Pick a different seat."<<endl;
}
cout<<endl<<"Do you want to buy another
ticket? Y/N"<<endl;
getline(cin, answer);
}
cout<<endl<<"Do you want to return a ticket?
Y/N"<<endl;
getline(cin, answer);
while (answer.at(0)== 'Y')
{
cout<<"Enter the row and seat
number for the retured ticket."<<endl;
cin>>row>>seat;
cin.ignore(100, '\n');
cout<<"You just retured a
ticket in
row"<<row<<"seat"<<seat<<endl;
cout<<"MARK SEAT as
AVAILABLE"<<endl<<endl;
section[row - 1][seat - 1] = '0';
seats_available++;
seat_map(section);
cout<<endl<<" Do you want
to return another ticket? Y/N"<<endl;
}
cout<<endl<<endl<<endl;
system("pause");
void int_seats(char array[][SEATS], int elements)
{
int i,j;
for (i=0; i<elements;i++)
{
for (j=0; j<SEATS; j++)
{
if (rand() % 2 ==
0)
array[j]
= '0'; // Vacant seats
else
array[j]
= 'x'; // Seat is not available
}
}
return 0;
}
void seat_map(char seats[ROWS][SEATS])
{
unsigned int i, j;
cout<<" SEAT MAP "<<endl<<endl;
cout<<"Seat";
for (j=0; j<SEATS; j++)
{
if (j== 3)
cout<<" "; //Print 2
spaces for the aisle
cout<<setw(2)<<j+1;
}
cout<<endl<<endl;
for (i=0; i<ROWS; i++)
cout<<" Row ";I
cout<< setw(2)<< i+1;
for (i = 0; j<SEATS; j++)
{
if (j==3)
cout<<" ";
cout<<setw(2)<<seats[j];
}
cout<<endl;
return;
unsigned int count_seats(char seats[ROWS][SEATS])
{
unsigned int seat_count = 0, i, j;
for (i = 0; i<ROWS; i++)
{
for (j = 0; j< SEATS; j++)
{
if (seats[j]=='0')
{
seat_count++;
}
}
}
return seat_count;
}
Fix The Code Below #include #include #include #include using namespace std; #def
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am