Professional Documents
Culture Documents
Lab Grading
Below is the grading table for this lab:
Task # Points
Task 1 30
Task 2 40 + 20
Task 3 30
Total 100
1. Populating and Printing a 4x4 Integer Array:
Write a C++ program that prompts the user to enter values to populate a 4x4 integer array. After
populating the array, display its contents.
Requirements:
● Use a loop to take user input for each element of the 4x4 array.
● Display the populated array using nested loops.
Row Sum Function:
Implement a C++ function named calculateRowSum that takes the 2D array and a row index as
parameters and returns the sum of all elements in that row.
Requirements:
● The function should be declared and defined separately from the main program.
● Use proper function prototypes and parameters.
● Test the function by calling it from the main program with different row indices.
EXAMPLE OUTPUT:
Original array:
1 2
3 4
3. Task: Write a C++ program that takes user input to populate a 4x4 integer matrix. Implement
a sorting function that sorts each row of the matrix independently in ascending order.
Requirements:
● Use a loop to take user input for each element of the 4x4 matrix.
● Implement a sorting function named sortRows that sorts each row independently.
● The sorting function should not sort the entire matrix but should sort each row
separately (if you can sort the whole matrix, you are a wizard! 👏)
● Display the original matrix and the matrix after sorting each row in ascending order.
Enter values to populate the 4x4 matrix:
4 3 2 1
8 7 6 5
12 11 10 9
16 15 14 13
Original matrix:
4 3 2 1
8 7 6 5
12 11 10 9
16 15 14 13