0% found this document useful (0 votes)
9 views3 pages

PF Open Ended

Open ended lab

Uploaded by

anasjaveed739
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

PF Open Ended

Open ended lab

Uploaded by

anasjaveed739
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

EE-133L Programming Fundamentals

Spring 2025

Registration number 2024-EE-403, 2024-EE-409, 2024-EE-415, 2024-EE-


423
Name Ahmad Arslan, Hammad Latif, Imran Ahmad, Atif
Bhatti

Open Ended Lab


Objective:
1. To reinforce fundamental concepts of C programming.
2. To develop a deeper understanding of programming constructs through hands-on practice.

Task 1:
Create a simplified cinema ticket booking system using the C programming language.
The system should allow users to book seats for a cinema show by providing the row and column
of the seat they want to book.
The booking system will display the status of seats (booked or available) after each booking and
calculate the total cost based on the number of tickets booked.
Requirements:
● There should be a fixed number of rows and columns (e.g., 3 rows and 4 columns).
● All seats should initially be available (indicated by 0).
● Users will book one seat at a time by specifying the row and column numbers.
Booking Process:
● The system will prompt the user to enter a row and column number.
● If the seat is available, it will be marked as booked (1).
● If the seat is already booked, the user will be notified.
● After each booking, the seat arrangement will be displayed.
● The total cost will be calculated based on the number of seats booked. Assume each seat
costs Rs. 300.
Exiting the Program:
● After each booking, the user will be asked if they want to book another seat.
● If the user enters 1, they can book another seat.

Instructor: Miss Rimsha Chauhdary


EE-133L Programming Fundamentals
Spring 2025

● If the user enters 0, the program will display the


total number of seats booked and the total cost,
then exit.
● The program must handle invalid seat entries
(e.g., out-of-bound row/column) gracefully and
notify the user.

Code:
#include <stdio.h>
int main() {
int seats[3][4] = {0};
int row, col;
int totalBooked = 0;
int choice = 1;
int price = 300;
while (choice == 1) {
printf("\nSeat Arrangement (0 = Available, 1 =
Booked):\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
printf("%d ", seats[i][j]);
}
printf("\n");
}

printf("\nEnter row (0-3): ");


scanf("%d", &row);
printf("Enter column (0-4): ");
scanf("%d", &col);

if (row < 0 || row > 2 || col < 0 || col > 3) {


printf("Invalid seat! Please try again.\n");
} else if (seats[row][col] == 1) {
printf("Seat already booked!\n");
} else {
seats[row][col] = 1;
totalBooked++;
printf("Seat booked successfully!\n");
}
printf("\nDo you want to book another seat? (1 = Yes, 0 = No): ");
scanf("%d", &choice);
}
printf("\nTotal seats booked: %d\n", totalBooked);
printf("Total cost: Rs. %d\n", totalBooked * price);
printf("Thank you for booking!\n");

Instructor: Miss Rimsha Chauhdary


EE-133L Programming Fundamentals
Spring 2025

return 0;
}
Output:

a) Booking by client.
b) A number of seats that are taken and available.
c) The client wants to book more seats.
d) Total seats booked and total cost.

Explanation:
Explain the answers using the piece of code you write for that portion.
Can you explain how users book tickets in the program? What steps do they need to
follow?
For this purpose, User don’t have to cross the limits.User have to enter the input for booking
the seats. For this user must enter the number of row and column and these doesn’t exceed
the limits.
How does the program determine if a seat is available for booking?
If the seats are available initially represented by ‘0’ when user booked it, then it represented
as 1. User choose the row and column for the seat and pay (300Rs) for it.
Explain how the program decides when to stop booking tickets.
At the end when user want to stop to booking seats the program asked user “Do you want to
book another seat”. User have to enter 0 here and program will ended.
What does the program do if the user enters an invalid row or column number?
If the user do this, Program tell you the “Invalid seat”. And after it program will ended.
How does the program ensure a smooth exit when the booking process is complete?
When the user complete the booking of the seats then the user enter the ‘0’ and the program
will ended.

Instructor: Miss Rimsha Chauhdary

You might also like