V.Vidhya Logo

V.Vidhya

Multi-Dimensional Arrays


Q1.

What will be the output of the following programs?

You have to predict the output yourself without running/executing the code.


Q2.

A group of friends is playing a classic Tic-Tac-Toe game. The game is played on a 3x3 grid, where each cell can either be empty (.), filled with X or O.

As the game progresses, they need a way to store the current state of the game board and update it after each move.

At this moment, the game board looks like this:

X  O  X  
.  .  O  
X  .  . 

// grid cell numbers
// 1 2 3
// 4 5 6
// 7 8 9

Now, it’s player O’s turn, and they want to place their mark in the middle row, first position i.e. cell number 4.


Q3.

An air-quality station in your city measures the fine particulate concentration (PM2.5 in µg/m³) at four different times of the day: morning, noon, evening and night. The station collects this data every day for a full week.

Write a program that:

Expected Output
Enter PM2.5 readings for each day and time:
-------------------------------------------------

Day 1:
--------
Morning: 22
Noon:    24
Evening: 23
Night:   21

Day 2:
--------
Morning: 24
Noon:    26
Evening: 25
Night:   24

Day 3:
--------
Morning: 23
Noon:    27
Evening: 26
Night:   25

Day 4:
--------
Morning: 26
Noon:    29
Evening: 28
Night:   25

Day 5:
--------
Morning: 29
Noon:    33
Evening: 30
Night:   28

Day 6:
--------
Morning: 30
Noon:    33
Evening: 32
Night:   31

Day 7:
--------
Morning: 26
Noon:    27
Evening: 25
Night:   23

-------------------------------------------------

Enter the day number (1-7) to get the average PM2.5 concentration: 4  
Average PM2.5 on Day 4: 27 µg/m³

-------------------------------------------------

Highest PM2.5 of the week: 33 µg/m³ on Day 5 (Noon)  
Lowest  PM2.5 of the week: 21 µg/m³ on Day 1 (Night)

Q4. (Adv.)

A small cinema hall has a fixed seating arrangement with multiple rows (5) and columns (6). Some seats are already booked, while others are available.

Develop a seat booking system where:

Expected Output
# Options:
1. Display Seating Chart
2. Check Seat Availability
3. Book a Seat
4. Exit
----------------
Enter your choice: 1

Current Seating Chart:

     1 2 3 4 5 6 
    -------------
1  | O O O O O O 
2  | O O O O O O 
3  | O O O O O O 
4  | O O O O O O 
5  | O O O O O O 

----------------
# Options:
1. Display Seating Chart
2. Check Seat Availability
3. Book a Seat
4. Exit
----------------
Enter your choice: 2

Enter row (1-5) and column (1-6) to check availability: 3 4
Seat is available.

----------------
# Options:
1. Display Seating Chart
2. Check Seat Availability
3. Book a Seat
4. Exit
----------------
Enter your choice: 3

Enter row (1-5) and column (1-6) to book: 5 3
Seat booked successfully!

Current Seating Chart:

     1 2 3 4 5 6 
    -------------
1  | O O O O O O 
2  | O O O O O O 
3  | O O O O O O 
4  | O O O O O O 
5  | O O X O O O 

----------------
# Options:
1. Display Seating Chart
2. Check Seat Availability
3. Book a Seat
4. Exit
----------------
Enter your choice: 2

Enter row (1-5) and column (1-6) to check availability: 5 3
Seat is already occupied.

----------------
# Options:
1. Display Seating Chart
2. Check Seat Availability
3. Book a Seat
4. Exit
----------------
Enter your choice: 3

Enter row (1-5) and column (1-6) to book: 5 3
Seat is already occupied. Please choose another seat.

Current Seating Chart:

     1 2 3 4 5 6 
    -------------
1  | O O O O O O 
2  | O O O O O O 
3  | O O O O O O 
4  | O O O O O O 
5  | O O X O O O 

----------------
# Options:
1. Display Seating Chart
2. Check Seat Availability
3. Book a Seat
4. Exit
----------------
Enter your choice: 4

Exiting the system.

Q5. (Adv.)

A hospital consists of multiple floors (3), each with a certain number of rooms (2), and each room has a fixed number of beds (4). Due to rising patient intake, the hospital administration wants to efficiently manage the availability of beds across all floors.

Your task is to develop a program that:

The hospital needs a solution to avoid overbooking beds and improve efficiency.

Expected Output
----------------
# Options:

1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 1

Current Bed Status:
Floor 1:
  Room 1: O O O O 
  Room 2: O O O O 
Floor 2:
  Room 1: O O O O
  Room 2: O O O O 
Floor 3:
  Room 1: O O O O 
  Room 2: O O O O 

----------------
# Options:

1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 2

Enter floor (1-3) and room (1-2) to check availability: 2 1

Bed availability in Floor 2, Room 1:
Bed 1 is available.
Bed 2 is available.
Bed 3 is available.
Bed 4 is available.

----------------
# Options:

1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 3

Enter floor (1-3), room (1-2), and bed (1-4) to book: 2 1 3

Bed booked successfully!

----------------
# Options:

1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 1

Current Bed Status:
Floor 1:
  Room 1: O O O O 
  Room 2: O O O O 
Floor 2:
  Room 1: O O X O 
  Room 2: O O O O 
Floor 3:
  Room 1: O O O O 
  Room 2: O O O O 

----------------
# Options:

1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 4

Total vacant beds in the hospital: 23

----------------
# Options:

1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 3

Enter floor (1-3), room (1-2), and bed (1-4) to book: 2 1 3

Bed is already occupied. Please choose another bed.

----------------
# Options:

1. Display Bed Status
2. Check Bed Availability
3. Book a Bed
4. Display Total Vacant Beds
5. Exit
----------------
Enter your choice: 5

Exiting the system.

Prev Post
Arrays
Next Post
Vector