const int Rows = 15; const int Cols = 30; void displayMenu(); int getChoice(); v
ID: 3536450 • Letter: C
Question
const int Rows = 15;
const int Cols = 30;
void displayMenu();
int getChoice();
void displaySeats (const char[][Cols]);
void displayPrices(const double[]);
void displaySales(double, const char[][Cols]);
void purchaseTicket(char[][Cols],const double[],double &);
void displayMenu()
{
cout<<endl
<<" C++ Theatre "
<<"1. View Available Seats "
<<"2. View Seating Prices "
<<"3. View Ticket Sales "
<<"4. Purchase a Ticket "
<<"5. Exit the program "
<<" Enter your choice(1-5): ";
}
int getChoice()
{
int ch;
cin>>ch;
cout<<endl;
if(ch<1 || ch>5)
cout<<"Invalid Selection ";
else
return ch;
}
void displaySeats(const char asientos[][Cols])
{
cout<<"Seats "
<<" ";
for(int i=0;i<Rows;i++)
{
cout<<" Row "<< i+1<<" ";
for(int j=0;j<Cols;j++)
cout<<asientos[i][j]<<" ";
}
cout<<endl;
system ("pause");
}
void displayPrices(const double rowCost[])
{
cout<<"Seating Prices: ";
for(int i=0;i<Rows;i++)
cout<<"Ticket Price for row "<<i+1<<" is: $"<<rowCost[i]<<endl;
system ("pause");
cout<<" ";
}
void displaySales(double tSales,const char asientos[][Cols])
{
int totalTickets=0;
for(int i=0;i<Rows;i++) //control fila
for(int j=0;j<Cols;j++) //control columna
if(asientos[i][j]=='*')
totalTickets++;
cout<<" Tickets Sales Information "
<<" Total numbers of tickets sold: "<<totalTickets<<endl
<<"Total amount of money earned $"<<tSales<<endl;
system ("pause");
}
void purchaseTicket(char asientos[][Cols],const double rowCost[], double & tSales)
{
char select;
int fila, columna,boleto=0;
double TOTAL=0;
cout<<" C++ Theatre "
<<" Ticket Purchase Opportunity ";
do{
cout<<" Do you want to see a chart of available seats before your selection? (y/n)";
cin>> select;
if (select=='y')
displaySeats(asientos);
//Validacion de fila
if (fila>1 || fila<15)
cout<<"Please enter desired row number(1-15): ";
cin>>fila;
{
while(fila<1 || fila>15){
cout<<"Invalid Input!! Please enter desired row number(1-15): ";
cin>>fila;
}
}
//validacion asientos
if (columna>1 || columna<30)
cout<<"Please enter desired seat number(1-30): ";
cin>>columna;
{
while(columna<1 || columna>30){
cout<<"Invalid Input!! Please enter desired seat number(1-30): ";
cin>>columna;
}
}
if(asientos[fila-1][columna-1]=='*')
{
cout<<" No Available Seat"
<<" Do you want to buy another ticket? (y/n)";
cin>>select;
}
else
{
asientos[fila-1][columna-1]='*';
cout<<" Purchase Confirmed "
<<"Would you like to purchase another ticket? (y/n)";
cin>>select;
TOTAL+=rowCost[fila-1];
boleto = boleto +1;
}
}while(select=='y');
if (boleto>0)
cout<<" You have purchased a total of "<<boleto<<" ticket for a total price of "<<TOTAL<<endl;
tSales+=TOTAL;
system ("pause");
}
//Funcion Main
int main()
{
int ch;
double cost, tSales=0;
double rowCost[Rows];
char asientos[Rows][Cols];
for(int i=0;i<Rows;i++)
for(int j=0;j<Cols;j++)
asientos[i][j]= '#';
for(int i=0;i<Rows;i++)
{
cout<<"Please enter ticket price for Row "<<i+1<<": ";
cin>> cost;
rowCost[i]=cost;
cout<<endl;
}
cout <<"Thank You! ";
system("pause");
system ("cls");
do{
displayMenu();
ch=getChoice();
switch(ch){
case 1:
displaySeats(asientos);
break;
case 2:
displayPrices(rowCost);
break;
case 3:
displaySales(tSales,asientos);
break;
case 4:
purchaseTicket(asientos,rowCost,tSales);
break;
case 5:
return 0;
} // fin del switch
}while(ch!=5);
return 0;
}
Explanation / Answer
Here is my code, please rate it.
Imports Microsoft.VisualBasic
Imports System
Public Class GlobalMembersCPlusPlus
Public Const Rows As Integer = 15
Public Const Cols As Integer = 30
Public Shared Sub displayMenu()
Console.Write(ControlChars.Lf)
Console.Write(" C++ Theatre" & vbLf & vbLf)
Console.Write("1. View Available Seats" & vbLf & vbLf)
Console.Write("2. View Seating Prices" & vbLf & vbLf)
Console.Write("3. View Ticket Sales" & vbLf & vbLf)
Console.Write("4. Purchase a Ticket" & vbLf & vbLf)
Console.Write("5. Exit the program " & vbLf & vbLf)
Console.Write(vbTab & "Enter your choice(1-5): ")
End Sub
Public Shared Function getChoice() As Integer
Dim ch As Integer
cin>>ch
Console.Write(ControlChars.Lf)
If ch<1 OrElse ch>5 Then
Console.Write("Invalid Selection" & vbLf & vbLf)
Else
Return ch
End If
End Function
Public Shared Sub displaySeats(ByRef asientos() As String)
Console.Write("Seats" & vbLf)
Console.Write(" ")
For i As Integer = 0 To Rows - 1
Console.Write(vbLf & "Row ")
Console.Write(i+1)
Console.Write(vbTab)
For j As Integer = 0 To Cols - 1
Console.Write(asientos(i).Chars(j))
Console.Write(" ")
Next j
Next i
Console.Write(ControlChars.Lf)
system("pause")
End Sub
Public Shared Sub displayPrices(ByVal rowCost() As Double)
Console.Write("Seating Prices:" & vbLf & vbLf)
For i As Integer = 0 To Rows - 1
Console.Write("Ticket Price for row ")
Console.Write(i+1)
Console.Write(" is: $")
Console.Write(rowCost(i))
Console.Write(ControlChars.Lf)
Next i
system("pause")
Console.Write(vbLf & vbLf)
End Sub
'Sub displaySales(ByVal UnnamedParameter1 As Double, ByRef UnnamedParameter2[] As String)
Public Shared Sub purchaseTicket(ByRef asientos() As String, ByVal rowCost() As Double, ByRef tSales As Double)
Dim [select] As SByte
Dim fila As Integer
Dim columna As Integer
Dim boleto As Integer = 0
Dim TOTAL As Double = 0
Console.Write(vbTab & vbTab & vbTab & "C++ Theatre" & vbLf)
Console.Write(vbTab & vbTab & vbTab & "Ticket Purchase Opportunity" & vbLf)
Do
Console.Write(vbLf & "Do you want to see a chart of available seats before your selection? (y/n)")
cin>> [select]
If [select] = AscW("y"c) Then
GlobalMembersCPlusPlus.displaySeats(asientos)
End If
'Validacion de fila
If fila>1 OrElse fila<15 Then
Console.Write("Please enter desired row number(1-15): ")
End If
cin>>fila
Do While fila<1 OrElse fila>15
Console.Write("Invalid Input!! Please enter desired row number(1-15): ")
cin>>fila
Loop
'validacion asientos
If columna>1 OrElse columna<30 Then
Console.Write("Please enter desired seat number(1-30): ")
End If
cin>>columna
Do While columna<1 OrElse columna>30
Console.Write("Invalid Input!! Please enter desired seat number(1-30): ")
cin>>columna
Loop
If asientos(fila-1).Chars(columna-1)="*"c Then
Console.Write(vbLf & "No Available Seat")
Console.Write(vbLf & vbLf & "Do you want to buy another ticket? (y/n)")
cin>>[select]
Else
asientos(fila-1).Chars(columna-1)="*"c
Console.Write(vbLf & "Purchase Confirmed" & vbLf & vbLf)
Console.Write("Would you like to purchase another ticket? (y/n)")
cin>>[select]
TOTAL+=rowCost(fila-1)
boleto = boleto +1
End If
Loop While [select] = AscW("y"c)
If boleto>0 Then
Console.Write(vbLf & "You have purchased a total of ")
Console.Write(boleto)
Console.Write(" ticket for a total price of ")
Console.Write(TOTAL)
Console.Write(ControlChars.Lf)
End If
tSales+=TOTAL
system("pause")
End Sub
Public Shared Sub displaySales(ByVal tSales As Double, ByRef asientos() As String)
Dim totalTickets As Integer = 0
For i As Integer = 0 To Rows - 1 'control fila
For j As Integer = 0 To Cols - 1 'control columna
If asientos(i).Chars(j)="*"c Then
totalTickets += 1
End If
Next j
Next i
Console.Write(" Tickets Sales Information" & vbLf & vbLf)
Console.Write(vbLf & "Total numbers of tickets sold: ")
Console.Write(totalTickets)
Console.Write(ControlChars.Lf)
Console.Write("Total amount of money earned $")
Console.Write(tSales)
Console.Write(ControlChars.Lf)
system("pause")
End Sub
'Funcion Main
Shared Function Main() As Integer
Dim ch As Integer
Dim cost As Double
Dim tSales As Double = 0
Dim rowCost(Rows - 1) As Double
Dim asientos(Rows - 1, Cols - 1) As SByte
For i As Integer = 0 To Rows - 1
For j As Integer = 0 To Cols - 1
asientos(i, j) = AscW("#"c)
Next j
Next i
For i As Integer = 0 To Rows - 1
Console.Write("Please enter ticket price for Row ")
Console.Write(i+1)
Console.Write(": ")
cin>> cost
rowCost(i)=cost
Console.Write(ControlChars.Lf)
Next i
Console.Write("Thank You!" & vbLf & vbLf)
system("pause")
system("cls")
Do
GlobalMembersCPlusPlus.displayMenu()
ch = GlobalMembersCPlusPlus.getChoice()
Select Case ch
Case 1
GlobalMembersCPlusPlus.displaySeats(asientos)
Case 2
GlobalMembersCPlusPlus.displayPrices(rowCost)
Case 3
GlobalMembersCPlusPlus.displaySales(tSales, asientos)
Case 4
GlobalMembersCPlusPlus.purchaseTicket(asientos, rowCost, tSales)
Case 5
Return 0
End Select ' fin del switch
Loop While ch<>5
Return 0
End Function
End Class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.