The code is now written in C++ translate it over to C programming language using
ID: 3761474 • Letter: T
Question
The code is now written in C++ translate it over to C programming language using scanf and printf:
#include <iostream>
#include <iomanip>
using namespace std;
//Function Declarations
int Show_Menu (); //To show main menu
void Show_Chart (); //To show seating chart
const char FULL = '*'; //Seat taken
const char EMPTY = '#'; //Seat open
const int rows = 15; //Number of rows
const int columns = 30; //Number of seats per row
char map [rows][columns]; //Array to hold seating chart
double price;
int total = 0;
int seat = 450;
int seat2 = 0;
int Quit = 1;
int main ()
{
const int Num_Rows = 15;
int price [Num_Rows];
int row2, column2, cost;
int answer;
//Main Logo
cout << " *********************************************************" << endl;
cout << " * *" << endl;
cout << " * Welcome to The our small town Theater *" << endl;
cout << " * *" << endl;
cout << " *********************************************************" << endl;
cout << endl << endl;
//Sets the row prices.
for (int count = 0; count < rows; count++)
{
cout << "Please enter the price for row " << (count + 1) << ": ";
cin >> price [count];
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
map [i][j] = EMPTY;
}
int choice;
do
{
choice = Show_Menu(); // Shows the main menu function.
switch (choice)
{
case 1:
cout << "View Seat Prices ";
for (int count = 0; count < rows; count++)
{
cout << "The price for row " << (count + 1) << ": ";
cout << price [count] << endl;
}
break;
case 2:
cout << "Purchase a Ticket ";
do
{
cout << "Please select the row you would like to sit in: ";
cin >> row2;
cout << "Please select the seat you would like to sit in: ";
cin >> column2;
if (map [row2] [column2] == '*')
{
cout << "Sorry that seat is sold-out, Please select a new seat.";
cout << endl;
}
else
{
cost = price [row2] + 0;
total = total + cost;
cout << "That ticket costs: " << cost << endl;
cout << "Confirm Purchase? Enter (1 = YES / 2 = NO)";
cin >> answer;
seat = seat - answer;
seat2 += answer;
if (answer == 1)
{
cout << "Your ticket purchase has been confirmed." << endl;
map [row2][column2] = FULL;
}
else if (answer == 2)
{
cout << "Would you like to look at another seat? (1 = YES / 2 = NO)";
cout << endl;
cin >> Quit;
}
cout << "Would you like to look at another seat?(1 = YES / 2 = NO)";
cin >> Quit;
}
}
while (Quit == 1);
break;
case 3:
cout << "View Available Seats ";
Show_Chart ();
break;
case 4:
cout << "View Seat Sales ";
break;
case 5:
cout << "quit ";
break;
default : cout << "Error input ";
}
} while (choice != 5);
return 0;
}
//********************************************************************************
//********************************************************************************
//** **
//** Define Functions. **
//** **
//********************************************************************************
//********************************************************************************
// Show Menu Function...
int Show_Menu()
{
int MenuChoice;
cout << endl << endl;
cout << " MAIN MENU ";
cout << " 1. View Seat Prices. ";
cout << " 2. Purchase a Ticket. ";
cout << " 3. View Available Seats. ";
cout << " 4. View Ticket Sales. ";
cout << " 5. Quit the program. ";
cout << "_____________________ ";
cout << "Please enter your choice: ";
cin >> MenuChoice;
cout << endl << endl;
return MenuChoice;
}
//Show Seating Chart Function
void Show_Chart ()
{
cout << " Seats" << endl;
cout << " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ";
for (int count = 0; count < 15; count++)
{
cout << endl << "Row " << (count + 1);
for (int count2 = 0; count2 < 30; count2++)
{
cout << " " << map [count] [count2];
}
}
cout << endl;
}
Explanation / Answer
#include <stdio.h>
//Function Declarations
int Show_Menu (); //To show main menu
void Show_Chart (); //To show seating chart
const char FULL = '*'; //Seat taken
const char EMPTY = '#'; //Seat open
const int rows = 15; //Number of rows
const int columns = 30; //Number of seats per row
char map [rows][columns]; //Array to hold seating chart
double price;
int total = 0;
int seat = 450;
int seat2 = 0;
int Quit = 1;
int main ()
{
const int Num_Rows = 15;
int price [Num_Rows];
int row2, column2, cost;
int answer;
//Main Logo
printf( " *********************************************************" );
printf( " * *" );
printf( " * Welcome to The our small town Theater *" );
printf( " * *" );
printf( " *********************************************************" );
printf(“ ”);
//Sets the row prices.
int count,i;
for (count = 0; count < rows; count++)
{
printf( "Please enter the price for row " << (count + 1) << ": ";
scanf( price [count];
}
for (i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
map [i][j] = EMPTY;
}
int choice;
do
{
choice = Show_Menu(); // Shows the main menu function.
switch (choice)
{
case 1:
printf( "View Seat Prices ";
for (count = 0; count < rows; count++)
{
printf( "The price for row %d :”, (count + 1) );
printf( “%d”,price [count] );
}
break;
case 2:
printf( "Purchase a Ticket ”);
do
{
printf( "Please select the row you would like to sit in: “);
scanf( “%d”,&row2);
printf( "Please select the seat you would like to sit in: ";
scanf(“%d”,&column2);
if (map [row2] [column2] == '*')
{
printf( "Sorry that seat is sold-out, Please select a new seat.”);
}
else
{
cost = price [row2] + 0;
total = total + cost;
printf( "That ticket costs: %d “, cost );
printf( "Confirm Purchase? Enter (1 = YES / 2 = NO)”);
scanf(“%c”, answer);
seat = seat - answer;
seat2 += answer;
if (answer == 1)
{
printf( "Your ticket purchase has been confirmed." );
map [row2][column2] = FULL;
}
else if (answer == 2)
{
printf( "Would you like to look at another seat? (1 = YES / 2 = NO)";
scanf( “%c”,Quit);
}
printf( "Would you like to look at another seat?(1 = YES / 2 = NO)";
scanf( “%c”,Quit);
}
}
while (Quit == 1);
break;
case 3:
printf( "View Available Seats ";
Show_Chart ();
break;
case 4:
printf( "View Seat Sales ";
break;
case 5:
printf( "quit ";
break;
default : printf( "Error input ";
}
} while (choice != 5);
return 0;
}
//********************************************************************************
//********************************************************************************
//** **
//** Define Functions. **
//** **
//********************************************************************************
//********************************************************************************
// Show Menu Function...
int Show_Menu()
{
int MenuChoice;
printf( endl );
printf( " MAIN MENU ";
printf( " 1. View Seat Prices. ";
printf( " 2. Purchase a Ticket. ";
printf( " 3. View Available Seats. ";
printf( " 4. View Ticket Sales. ";
printf( " 5. Quit the program. ";
printf( "_____________________ ";
printf( "Please enter your choice: ";
scanf( MenuChoice;
printf( endl );
return MenuChoice;
}
//Show Seating Chart Function
void Show_Chart ()
{
printf( " Seats" );
printf( " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ";
for (int count = 0; count < 15; count++)
{
printf( endl << "Row " << (count + 1);
for (int count2 = 0; count2 < 30; count2++)
{
printf( " " << map [count] [count2];
}
}
printf( endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.