Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN C+ LANGUAGE AND THE EXPLANTION PLEASE!!! Using_beginthread spawn subprocesses

ID: 3801677 • Letter: I

Question

IN C+ LANGUAGE

AND THE EXPLANTION PLEASE!!!

Using_beginthread spawn subprocesses that sell pretend tickets to a show. The tickets correspond to slots in an array call it tickets. If ticket[i] == 1 it means that the ticket is available. If you sell that ticket change the value of ticket[i] to 0. To do this create a function called sell tickets that takes as input an array of tickets and returns a 0 if it sold a ticket or a 1 if there are no tickets left. Just before the return print that the handle sold a ticket. Since the array is a location in memory to be shared by the spawned processes you need to use the wait and signal functions to control access to the array. Read about them and then deploy them in your program.

Explanation / Answer

#include <string.h>
#include<conio.h>
#include<dirh.h>
#include <iomanip.h>
#include <iostream.h>
#include <fstream.h>
#include <array.h>

using namespace std;
void get_menu_choice(char tickets[][8][24]);
bool sell_seat(char tickets[][8][24]);
void print_day_list(char tickets[][8][24]);
void print_floor_list(char tickets[][8][24]);
void print_chart();
const char FULL ='*';
const char EMPTY = '-';
const int rows = 8;
const int seats = 24;
const int days = 8;
char map [days][rows][seats];

int main()
{
char tickets[8][8][24];
bool done = false;
while (!done)
{
done = sell_seat(tickets);
}
print_day_list(tickets);
print_floor_list(tickets);
get_menu_choice(tickets);

int choice;

do
{

switch(choice)
{
case '1':
cout << "1 - Sell a Ticket.";
sell_seat(tickets);
break;
case '2':
cout << "2 - Display Seating Chart.";
print_chart();
break;
case '3':
cout << "3 - Display Sales Summary - Day Listing";
print_day_list(tickets);
break;
case '4':
cout << "4 - Display Sale Summary - Floor Listing";
print_floor_list(tickets);
break;
case '5':
cout << "Quit";
break;
default:
cout << "Invalid Try again!" << endl;
break;
}
}while(choice != 'Q');

return 0;
}
void get_menu_choice(char tickets[][8][24])
{
int MenuChoice;

cout << " *** Main Menu *** " << endl;
cout << "1 - Sell a Ticket." << endl;
cout << "2 - Display Seating Chart." << endl;
cout << "3 - Display Sales Summary - Day Listing" << endl;
cout << "4 - Display Sale Summary - Floor Listing" << endl;
cout << "5 - Quit" << endl;
cout << "Your Choice: ";
cin >> MenuChoice;
cout << endl;

}
bool sell_seat(char tickets[][8][24])
{
char choice, level;
int day, location;

cout << "Enter seat request by day (T)hursday, (F)riday, (S)aturday"
<< " followed by Section (F)loor, (B)alcony, (U)pper Balcony "
<< " followed by seat number (1-20).";

cin >> choice;

choice = toupper(choice);

if (choice == 'T')
day = 0;
else if (choice == 'F')
day = 1;
else if (choice == 'S')
day = 2;
else
{
cout << "Invalid day entered, try again ";
return false;
}
cin >> level;
level = toupper(level);
if (level == 'F' )
location = 0;
else if (level == 'B')
location = 1;
else if (level == 'U')
location = 2;
else
{
cout << "Invalid location entered, try again ";
return false;
}
for (int count = 0; count < 24; count++)
{
if (tickets[day][location][count] == '*')
{
tickets[day][location][count] = 'S';
return false;
}
}
cout << "All seats filled for " << choice << " at location " << level
<< " try again" << endl;
return false;
}
void print_chart()
{
string dayTitles[8] = {"Thursday ", "Friday ", "Saturday "};
string locationTitles[8] = {"Floor ", " Balcony ", " Upper Balcony "};

for (int k = 0; k< 8; k ++)
{
cout << dayTitles[i];
for(int m = 0; m< 8; m++)
{
cout << locationTitles[m];
cout << " " << map[k][m] << endl;
}
}
}
void print_day_list(char tickets[][8][24])
{
string dayTitles[8] = {"Thursday ", "Friday ", "Saturday "};
string locationTitles[3] = {"Floor ", " Balcony ", " Upper Balcony "};
int totalSold = 0, dayTotal[8] = {0}, locationTotal[3] = {0}, sold, dayAmount[3] = {0};
int amount[8] = {0};
int price[8] = {50, 30, 20};
for (int day = 0; day < 8; day ++)
{
cout << dayTitles[day] << endl;
for (int location = 0; location < 3; location++)
{
if(location !=0)
cout << ' ';

cout << locationTitles[location];
sold = 0;
for (int seats = 0; seats < 24; seats++)
{
if(tickets[day][location][seats] == 'S')
{
sold++;
totalSold++;
dayTotal[day]++;
locationTotal[location]++;
dayAmount[day] += price[location];
}
}
cout << ' ' <<"Tickets sold " << sold << " $" << sold * price[location] << endl;
amount[location] += sold * price[location];
}
}
cout << " Total tickets sold for all concerts " << totalSold
<< " $ " << amount[0] + amount[1] + amount[2] << endl << endl;
}
void print_floor_list(char tickets[][8][24])
{
string locationTitles[3] = {"Floor ", "Balcony ", "Upper Balcony "};
string dayTitles[3] = {"Thursday ", " Friday ", " Saturday "};
int totalSold = 0, locationTotal[3] = {0}, dayTotal[3] = {0}, sold, locationAmount[3] = {0};
int amount[8] = {0};
int price[8] = {50, 30, 20};
for (int location = 0; location < 8; location++)
{
cout << locationTitles[location] << endl;
for (int day = 0; day < 8; day++)
{
if(day !=0)
cout << ' ';

cout << dayTitles[day];
sold = 0;
for (int seats = 0; seats < 24; seats++)
{
if(tickets[location][day][seats] == 'S')
{
sold++;
totalSold++;
locationTotal[location]++;
dayTotal[day]++;
locationAmount[location] += price[day];
}
}
cout << ' ' <<"Tickets sold " << sold << " $" << sold * price[day] << endl;
amount[day] += sold * price[day];
}
}
cout << " Total ticket sales for all shows: " << totalSold
<< " $ " << amount[0] + amount[1] + amount[8] << endl << endl;
}