0
0
C++programming~30 mins

Multi-dimensional arrays in C++ - Mini Project: Build & Apply

Choose your learning style9 modes available
Working with Multi-dimensional Arrays in C++
📖 Scenario: You are organizing seating for a small movie theater. The theater has 3 rows and 4 seats in each row. You want to keep track of how many people are sitting in each seat.
🎯 Goal: Create a 2D array to represent the seats, fill it with some numbers, then calculate the total number of people seated in the theater.
📋 What You'll Learn
Create a 2D array called seats with 3 rows and 4 columns
Initialize the array with exact values for each seat
Create an integer variable called totalPeople to hold the sum
Use nested for loops with variables row and col to iterate over seats
Add the number of people in each seat to totalPeople
Print the total number of people using std::cout
💡 Why This Matters
🌍 Real World
Multi-dimensional arrays are used to represent grids, tables, or matrices such as seating charts, game boards, or pixel data in images.
💼 Career
Understanding multi-dimensional arrays is essential for software developers working with data structures, graphics, simulations, and many other fields.
Progress0 / 4 steps
1
Create the 2D array seats
Create a 2D array called seats with 3 rows and 4 columns. Initialize it with these exact values: first row {1, 0, 2, 1}, second row {0, 3, 1, 0}, third row {2, 1, 0, 1}.
C++
Need a hint?

Use int seats[3][4] = { ... }; to create and initialize the array.

2
Create the variable totalPeople
Create an integer variable called totalPeople and set it to 0. This will hold the total number of people seated.
C++
Need a hint?

Use int totalPeople = 0; to create and initialize the variable.

3
Sum all people using nested for loops
Use nested for loops with variables row and col to iterate over the seats array. Add each seat's value to totalPeople.
C++
Need a hint?

Use two for loops: outer loop for rows, inner loop for columns. Add each seat value to totalPeople.

4
Print the total number of people
Use std::cout to print the text Total people seated: followed by the value of totalPeople.
C++
Need a hint?

Use std::cout << "Total people seated: " << totalPeople << std::endl; to print the result.