0% found this document useful (0 votes)
16 views10 pages

Cinema Seat Reservation System Code

Uploaded by

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

Cinema Seat Reservation System Code

Uploaded by

arsalan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lab Task 1: Cinema Seat Booking System

Scenario:

You are tasked with creating a system to manage seat bookings in a cinema hall using a 2D
array. The seats are represented in rows and columns where 1 represents a booked seat and 0 an
available seat.

Steps:

1. Understand the Array Representation:


o Rows represent seat rows in the cinema.
o Columns represent individual seats in each row.
o Example: For a cinema with 5 rows and 10 seats in each row, declare a 2D array
as int seats[5][10];.
2. Initialize the Seats:
o Use a nested loop to initialize the array with default values. Initially, all seats can
be 0 (available), but you can also pre-book some seats for testing.
o Example: Set seats[0][4] = 1; to indicate seat 4 in row 0 is booked.
3. Display Seat Arrangement:
o Write a function that uses a loop to display the seating arrangement in a human-
readable format.
o Step: Loop through the array, and for each row, print all seats (0 for available, 1
for booked).
4. Book a Seat:
o Take input from the user for row and seat number they wish to book.
o Check if the seat is available by accessing seats[row][seat].
o If 0, mark it as 1 (booked). If already 1, display a message that the seat is booked.
5. Cancel a Booking:
o Similar to booking, take input from the user to cancel a booking.
o Check if seats[row][seat] == 1. If yes, mark it as 0 (available).
6. Loop Until User Exits:
o Create a menu-driven system to allow continuous booking, cancellation, or
viewing until the user decides to exit.

Key Learning Objectives:

 Understand array indexing for real-world scenarios.


 Learn how to manipulate arrays using loops.
 Practice taking and validating user input.

Lab Task 2: School Attendance Tracker

Scenario:
A teacher wants to track student attendance for a week. Store attendance using a 2D array where
each row represents a student and each column represents a day. 1 means present, 0 means
absent.

Steps:

1. Declare the 2D Array:


o Represent attendance for 10 students over 5 days. Declare a 2D array as int
attendance[10][5]; where rows represent students and columns represent days.
2. Initialize with Data:
o Initially, set all entries to 0 (absent). Allow the teacher to enter attendance daily,
updating the array.
3. Input Attendance:
o Prompt the teacher for daily attendance. Use nested loops to update the attendance
of all students for each day.
o Example: Use a loop that iterates over each student (for (int i = 0; i < 10;
i++)), then ask the teacher if the student was present (1) or absent (0).
4. Display Attendance for All Students:
o Write a function to print the attendance matrix where rows represent students and
columns represent days.
o Example: Print each row followed by the attendance for each day.
5. Calculate and Display Total Present Days for a Student:
o Prompt the user for a specific student’s ID and calculate the total number of
present days by summing up the values of the respective row.
6. Loop for Daily Updates:
o Allow the system to take attendance day by day and update the array accordingly.

Key Learning Objectives:

 Use 2D arrays to store multiple related data (students' attendance across multiple days).
 Practice array traversal and summation.
 Develop skills in building a user-interactive system for real-time data entry.

Lab Task 3: Tic-Tac-Toe Game

Scenario:

Build a simple Tic-Tac-Toe game where two players take turns marking X or O on a 3x3 grid.
The game ends when one player wins or all cells are filled.

Steps:

1. Array Declaration:
o Declare a 3x3 char array to store the board state.
o Initialize the array with spaces (' '), representing empty cells.
2. Display the Board:
o Write a function to display the current state of the board.
o Loop through the 2D array and print the value of each cell (X, O, or space).
3. Input Player Move:
o Alternately prompt players for row and column input to place their move (X or O).
o Validate the input to ensure the selected cell is empty.
4. Check for Win:
o Write a function to check if there is a winning condition: three matching Xs or Os
in a row, column, or diagonal.
o Use loops to check each row, each column, and the two diagonals.
5. Detect Draw:
o After each move, check if the board is completely filled and no player has won.
6. Loop Until Game Ends:
o Create a loop that alternates between Player 1 and Player 2. Exit the loop if a
player wins or if there is a draw.

Key Learning Objectives:

 Use 2D arrays to simulate a game board.


 Learn about turn-based systems and input validation.
 Develop skills in game logic and condition checking with arrays.

Lab Task 4: Image Representation in Grayscale

Scenario:

An image in grayscale can be represented by a 2D array where each element is a pixel intensity
between 0 and 255. Implement a basic image manipulation system that allows adjusting the
brightness.

Steps:

1. Declare a 2D Array for Image Pixels:


o Represent the image as a 10x10 2D array where each element is an integer
between 0 and 255.
o Example: int image[10][10];
2. Initialize the Image:
o Initialize the array with random values between 0 and 255 to simulate pixel
intensities.
3. Display the Image:
o Write a function to display the array, printing each pixel value in rows and
columns, just like an image grid.
4. Adjust Brightness:
Create a function that increases or decreases brightness by adding or subtracting a
o
value from each pixel.
o Ensure the pixel values stay within the range 0-255 (use if statements or the
min/max functions).
5. Update and Display the New Image:
o After adjusting brightness, display the updated image.
6. Loop for Multiple Adjustments:
o Allow the user to repeatedly adjust brightness until they decide to exit.

Key Learning Objectives:

 Simulate a real-world image processing task using arrays.


 Practice bounds checking (ensuring values remain within a certain range).
 Work with nested loops to manipulate large sets of data.

Lab Task 5: Student Grades Record

Scenario:

A teacher wants to store and analyze student grades. You will use a 2D array where each row
represents a student and each column represents a subject.

Steps:

1. Declare the 2D Array:


o Declare an array int grades[5][4]; for 5 students and 4 subjects.
2. Input Grades:
o Use a nested loop to input grades for each student and subject.
o Example: Loop through each student and ask for grades in 4 subjects.
3. Display Grades:
o Write a function to print the grades in a table format, where each row represents a
student and each column represents a subject.
4. Calculate Average for Each Student:
o Write a function to calculate and display the average grade for each student.
o Sum the values in each row and divide by the number of subjects.
5. Identify the Highest Scorer:
o Write a function to find and display the student with the highest average.
6. Provide Feedback:
o For students with an average below 50, display a message encouraging them to
improve.

Key Learning Objectives:

 Learn how to use 2D arrays to store structured data (grades per student).
 Practice calculating sums and averages from 2D array data.
 Explore real-world educational applications of arrays.

Lab Task 6: Weather Data Logger

Scenario:

Log temperatures for 7 days across 5 cities.

Steps:

1. Declare the Array:


o temperature[5][7] for 5 cities over 7 days.
2. Input Data:
o Fill in the array with daily temperatures for each city.
3. Display Data:
o Print out a daily log for each city.
4. Calculate Average Temp for Each City:
o Write a function to compute the average temperature for each city.

Lab Task 7: Library Book Availability Tracker

Scenario:

Track book availability in 3 library branches for 10 books.

Steps:

1. Declare Array:
o books[10][3] where rows represent books and columns represent branches.
2. Input Availability:
o Use 1 for available, 0 for unavailable.
3. Display Book Status:
o Print which branches have the books.

Lab Task 8: Sales Tracking System


Scenario:

Track daily sales for 5 products over 7 days.

Steps:

1. Declare Array:
o sales[5][7] where products are rows and days are columns.
2. Input Daily Sales:
o Input sales data for each product.
3. Total Sales Calculation:
o Write a function to calculate total sales for each product.

Lab Task 9: Hospital Patient Monitoring

Scenario:

Record vital signs for 6 patients every hour for 12 hours.

Steps:

1. Declare Array:
o vitals[6][12] for 6 patients and 12 readings.
2. Input Data:
o Input vitals (heart rate, temperature, etc.).
3. Average Calculation:
o Calculate the average vital signs for each patient.

Lab Task 10: School Exam Scores

Scenario:

Track scores for 5 students across 6 subjects.

Steps:

1. Declare Array:
o scores[5][6] where rows are students and columns are subjects.
2. Input Scores:
o Input exam scores for each subject.
3. Display Scores:
o Print the score table.
Lab Task 11: Chess Board Representation

Scenario:

Simulate a chess board using a 2D array.

Steps:

1. Declare Array:
o board[8][8] where each position is either W for white piece, B for black, or E for
empty.
2. Initialize Board:
o Set initial chess positions.

Lab Task 12: Daily Attendance Tracking System

Scenario:

Track attendance for 15 employees for 30 days.

Steps:

1. Declare Array:
o attendance[15][30].
2. Input Data:
o Record 1 for present, 0 for absent each day.

Lab Task 13: Hospital Bed Availability

Scenario:

Track bed availability in 5 wards for 7 days.

Steps:

1. Declare Array:
o beds[5][7] where rows represent wards and columns represent days.
2. Input Data:
o Record bed availability (1 for available, 0 for unavailable).
Lab Task 14: Monthly Rainfall Data

Scenario:

Track rainfall for 4 cities over 30 days.

Steps:

1. Declare Array:
o rainfall[4][30].
2. Input Data:
o Record daily rainfall amounts.

Lab Task 15: School Grades Record System

Scenario:

Track marks for 10 students across 5 subjects.

Steps:

1. Declare Array:
o marks[10][5].
2. Input Marks:
o Record marks for each subject.

Lab Task 16: Flight Seat Booking System

Scenario:

Track seat bookings in a flight for 6 rows and 4 columns.

Steps:

1. Declare Array:
o seats[6][4].
2. Input Booking Data:
o Record 1 for booked, 0 for available.

Lab Task 17: Tracking Exam Results


Scenario:

Track results for students in 3 subjects.

Steps:

1. Declare Array:
o results[20][3] where rows represent students and columns represent subjects.

Lab Task 18: Stock Inventory Management

Scenario:

Track stock levels for 10 products across 3 warehouses.

Steps:

1. Declare Array:
o stock[10][3].

Lab Task 19: Game Scoreboard System

Scenario:

Track player scores in 5 rounds for 6 players.

Steps:

1. Declare Array:
o scores[6][5].

Lab Task 20: Student Attendance in Classrooms

Scenario:

Track attendance of 25 students over 10 days.

Steps:

1. Declare Array:
o attendance[25][10].

Common questions

Powered by AI

2D arrays allow structured storage of attendance data, where rows correspond to students and columns to days. This organization facilitates easy access and manipulation of daily attendance records. The system operates by initializing the arrays with zeroes (absent), updating data daily by querying for each student’s presence, and displaying the records in matrix form for easy visualization. This method reduces complexity in tracking attendance trends and calculating present days per student .

Hospitals can monitor patient vital signs using a 2D array where rows represent patients and columns represent time intervals. By inputting data at regular intervals (e.g., hourly), they can continuously track changes. To process data efficiently, calculate average values over the period for each patient, assisting in gauging health trends. This system demands systematic data entry, validation to avoid anomalies, and array traversal for analytics .

Develop the Tic-Tac-Toe game by declaring a 3x3 char array initialized with spaces (' ') for empty cells. Players alternately input their moves as 'X' or 'O' with checks for valid empty cells. The win condition checks use loops to verify if any row, column, or diagonal contains three identical marks. If a win occurs or all cells are occupied with no winner, the game concludes as a win or a draw. This requires careful input validation and continual game state updates .

In a game scoreboard system, input validation ensures the accuracy of score data stored in a 2D array where rows and columns represent players and rounds. Proper validation involves checking input ranges, ensuring numerical data integrity, and preventing logical errors such as overflow or inconsistent scoring. Validation mitigates the risk of erroneous data compromising scoreboard integrity and ensures that calculations, like total scores, are accurate and meaningful .

Design a flight seat booking system with a 2D array where each position represents a seat's status (1 for booked, 0 for available). Key processes involve allowing bookings (changing 0 to 1) and ensuring invalid or redundant bookings are handled. Key challenges include preventing duplicate bookings and handling cancellation processes, which require accurate tracking of array state updates and consistent interface synchronization to reflect changes in seat availability .

A library can track book availability using a 2D array, with rows representing books and columns representing branches. An entry is 1 if a book is available, and 0 if not. This requires an initial setup to input statuses for each book-branch pair. Displaying the array helps visualize availability, making inventory management straightforward by quickly identifying which branches hold specific books .

Hospitals use 2D arrays to track bed availability, where each element represents a bed's status over time and wards. Processes include daily updates reflecting occupancy changes; using 1 for available and 0 for unavailable beds ensures quick availability checks for each period. To maintain accuracy, rigorous daily data entry and verification procedures are crucial, ensuring the system reflects reality and supports operational decisions effectively .

To adjust image brightness, represent the image as a 10x10 2D array of pixel values ranging from 0 to 255. To manipulate brightness, apply a uniform adjustment (addition or subtraction) to each pixel. Critical steps include looping through each pixel, adjusting the value, and ensuring it remains within the 0-255 range by employing bounds checks or min/max functions. Display the adjusted image to reflect changes, emphasizing the importance of maintaining valid pixel intensities throughout .

Management of student grades through a 2D array involves structuring data such that rows represent students and columns represent subjects. Input each student's grades, then calculate their average by summing the row entries and dividing by the number of subjects. To identify the highest scorer, compare these averages, keeping track of the highest found. This structured approach allows seamless updates, retrieval, and analysis of grade data .

To simulate a cinema seat booking system using a 2D array, represent the seats as a grid where rows and columns correspond to seat positions. Initialize all seats as available (0). To book a seat, take the user's input for row and seat number, checking if the seat is unbooked (0) before marking it as booked (1). This requires implementing a looped menu for continuous interaction, validating array indices, and displaying the grid state after changes .

You might also like