Question

Write a program in C to assign seats of a movie theater (capacity: 200 seats). Your...

Write a program in C to assign seats of a movie theater (capacity: 200 seats). Your program should display the following menu of alternatives:

Please type 1 for "section A, $50/ticket" type 2 for "section B, $70/ticket", and type 3 for "section C, $80/ticket".  If the user types 1, then your program should assign a seat in the A section (seats 1–50). If the user types 2, then your program should assign a seat in the B section (seats 51–100). If the user types 3, then your program should assign a seat in the C section (seats 101–200). Your program should then ask for the number of tickets. Finally the program prints ticket/tickets individually indicating the seat number and the section of each ticket  and then prints the receipt indicating the total cost. Use a single-subscripted array to represent the seating chart of the theater. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding element of the array to 1 to indicate that the seat is no longer available. Your program should, of course, never assign a seat that has already been assigned. When a section is full, your program should ask the user if it is acceptable to be placed in other sections. If yes, then make the appropriate seat assignment. If no, then print the message "We are booked."

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int seats[201];

int checkAvailability(int section, int tickets) {

int start, end, counter = 0;

if(section == 1) {

start = 1;

end = 50;

} else if( section == 2) {

start = 51;

end = 100;

} else {

start = 101;

end = 200;

}

//Find total available

for(int i = start; i <= end; i++) {

if(seats[i] == 0) {

counter++;

}

}

//return true if available >= required

if(counter >= tickets) {

return 1;

} else {

return 0;

}

}

void assignSeats(int section, int tickets) {

int start, end, cost = 0, counter = 0;;

if(section == 1) {

start = 1;

end = 50;

cost = 50;

} else if( section == 2) {

start = 51;

end = 100;

cost = 70;

} else {

start = 101;

end = 200;

cost = 80;

}

printf("Assigned seats are :: ");

//Assign seats

for(int i = start; i <= end; i++) {

if(seats[i] == 0) {

printf("%d ", i);

seats[i] = 1;

counter++;

}

if(counter == tickets) {

break;

}

}

printf("\n PLease pay $%d \n", (tickets * cost));

printf("thank you\n");

}

int main() {

while(1) {

printf("%s\n", "Please type 1 for section A, $50/ticket type 2 for section B, $70/ticket, and type 3 for section C, $80/ticket");

int choice, tickets;

scanf("%d", &choice);

printf("%s\n", "Number of tickets :: ");

scanf("%d", &tickets);

int available = checkAvailability(choice, tickets);

if(available == 1) {

assignSeats(choice, tickets);

} else {

printf("Do you want seat in other sections as we are unable to book in the choosen section (type 1 for yes else type 0) :: ");

int c;

scanf("%d", &c);

if(c == 1) {

printf("Choose Another section please :: ");

} else {

printf("We are booked\n");

}

}

}

}

Please type 1 for section A, $50/ticket type 2 for section B, $70/ticket, and ty pe 3 for section C, S80/ticket umber of tickets Assigned seats are 181 102 103 104 105 PLease pay $400 thank you lease type 1 for section A, S50/ticket type 2 for section B, $70/ticket, and ty pe 3 for section C, $80/ticket

please comment for further assistance

Add a comment
Know the answer?
Add Answer to:
Write a program in C to assign seats of a movie theater (capacity: 200 seats). Your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have to write a C program to assign seats on each flight of the airline’s...

    I have to write a C program to assign seats on each flight of the airline’s only plane (capacity: 40 seats, in 10 rows). For the sake of simplicity, assume that each row has 4 seats labeled A, B, C, D. Your program should display the following menu of alternatives: Please type 1 for "first class" Please type 2 for "business class" Please type 3 for “economy class”. If the person types 1, then your program should assign a seat...

  • (Airline Reservations System) A small airline has just purchased a computer for its new automated reservations system

    (Airline Reservations System) A small airline has just purchased a computer for its new automated reservations system. The president has asked you to program the new system. You'll write a program to assign seats on each flight of the airline's only plane (capacity: 10 scats).Your program should display the following menu of alternatives:Please type 1 for "first class"please type 2 for "economy"If the person types 1 , then your program should assign a seat in the first class section (seats...

  • C# WINDOWS FORMS APPLICATION (not CONSOLE APPLICATION ) (Please screenshot window form of this program and...

    C# WINDOWS FORMS APPLICATION (not CONSOLE APPLICATION ) (Please screenshot window form of this program and write code on computer. Thank you very much !) For this week's assignment , create and complete a Windows application for the following question. Airline Reservation System: An airline has just bought a computer for its new reservation system. Develop a new system to assign seats on the new airplane( capacity: 10 seats) Display the following alternatives: "Please type 1 for first class, and...

  • In C++. Write a program that can be used to assign seats for a commercial airplane...

    In C++. Write a program that can be used to assign seats for a commercial airplane and print out the ticket total. The airplane has 13 rows, with row 7 being the Emergency Exit row. Each row has 7 seats, there are two seats on each side of the plane and three seats in the middle with aisles on both sides. Rows 1 and 2 are considered first class with tickets for this specific  flight being $872.00 round trip. Rows 3...

  • C# Question. Please do a lot of documenting of what your code did and thorough explaining...

    C# Question. Please do a lot of documenting of what your code did and thorough explaining in your // comments. A small airline has just purchased a computer for its new automated reservations system. You have been asked to develop the new system. You’re to write an app to assign seats on each flight of the airline’s only plane (capacity: 10 seats). Display the following alternatives: Please enter 1 for First Class or 2 for Economy. If the user types...

  • Programming language C++. (Airline Reservations System) A small airline has just purchased a computer for its...

    Programming language C++. (Airline Reservations System) A small airline has just purchased a computer for its new au- tomated reservations system. You have been asked to develop the new system. You’re to write an app to assign seats on each flight of the airline’s only plane (capacity: 10 seats). Display the following alternatives: Please type 1 for First Class and Please type 2 for Economy. If the user types 1, your app should assign a seat in the first-class section...

  • I could really use some help with this question! Thanks!! Must use C# and it must...

    I could really use some help with this question! Thanks!! Must use C# and it must be a console application ------------------------------------------------------------------------------------------------------------------------------ You start working on this w/o arrays just with seats: bool f1, f2,..., e1, e2,.... You can use Console application for now. A small airline has just purchased a computer for its new automated reservations system. You have been asked to develop the new system. You’re to write an app to assign seats on each flight of the airline’s...

  • For c++ Write a program that can be used to assign seats for a commercial airplane....

    For c++ Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with six seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business class, and rows 8 rows through 13 are economy class. Your program must prompt the user to enter the following information: Ticket type (first class, business class, or economy class) Desired seat a. b. Output the seating plan in the...

  • For this week's assignment , create and complete a Windows application for the following question. Airline...

    For this week's assignment , create and complete a Windows application for the following question. Airline Reservation System: An airline has just bought a computer for its new reservation system. Develop a new system to assign seats on the new airplane( capacity: 10 seats) Display the following alternatives: "Please type 1 for first class, and please type 2 for Economy". If the user enters 1, your application should assign a seat in the first class( seats 1-5). If the user...

  • Theater Seating Revenue with Input Validation

    A dramatic theater has three seating sections, and it charges the following prices for tickets in each section:Section A seats cost $20 each, section B seatscost $15 each, and section C seats cost $10 each.The theater has 300 seats in section A, 500 seats in section B, and 200 seats in section C.Design aprogram that asks for the number of tickets sold in each section and then displays the amount of income generated from ticket sales.The program should validatethe numbers...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT