2D Array Lab Tasks
2D Array Lab Tasks
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:
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:
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.
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.
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:
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:
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.
Scenario:
Steps:
Scenario:
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.
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.
Scenario:
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.
Scenario:
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:
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.
Scenario:
Steps:
1. Declare Array:
o attendance[15][30].
2. Input Data:
o Record 1 for present, 0 for absent each day.
Scenario:
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:
Steps:
1. Declare Array:
o rainfall[4][30].
2. Input Data:
o Record daily rainfall amounts.
Scenario:
Steps:
1. Declare Array:
o marks[10][5].
2. Input Marks:
o Record marks for each subject.
Scenario:
Steps:
1. Declare Array:
o seats[6][4].
2. Input Booking Data:
o Record 1 for booked, 0 for available.
Steps:
1. Declare Array:
o results[20][3] where rows represent students and columns represent subjects.
Scenario:
Steps:
1. Declare Array:
o stock[10][3].
Scenario:
Steps:
1. Declare Array:
o scores[6][5].
Scenario:
Steps:
1. Declare Array:
o attendance[25][10].