const int Rows = 15; const int Cols = 30; void displayMenu(); int getChoice(); v
ID: 3536451 • 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
http://blogs.msdn.com/b/csharpfaq/archive/2010/09/28/converting-a-vba-macro-to-c-4-0.aspx
visit this site it help you
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.