Question: #include using namespace std; const int ARRAY _ SIZE = 5 ; int rand _ number ( ) { return rand ( ) % 4

#include
using namespace std;
const int ARRAY_SIZE =5;
int rand_number(){
return rand()%41-20;
}
void populate_rand_numbers(int matrix[][ARRAY_SIZE]){
for (int i =0; i < ARRAY_SIZE; ++i){
for (int j =0; j < ARRAY_SIZE; ++j){
matrix[i][j]= rand_number();
}
}
}
void print_rand_numbers(int matrix[][ARRAY_SIZE]){
for (int i =0; i < ARRAY_SIZE; ++i){
for (int j =0; j < ARRAY_SIZE; ++j){
cout << matrix[i][j]<<"";
}
cout << endl;
}
}
int sum_odd_row(int row[]){
int sum =0;
for (int i =0; i < ARRAY_SIZE; ++i){
if (row[i]%2!=0){
sum += row[i];
}
}
return sum;
}
void prompt_sum_odd_row(int matrix[][ARRAY_SIZE]){
for (int i =0; i < ARRAY_SIZE; ++i){
cout << "Sum all odd numbers in row "<< i +1<<"="<< sum_odd_row(matrix[i])<< endl;
}
}
int main(){
srand(time(0));
int matrix[ARRAY_SIZE][ARRAY_SIZE];
populate_rand_numbers(matrix);
cout << "Random Numbers in the 5-by-5 Array:" << endl;
print_rand_numbers(matrix);
cout << endl;
prompt_sum_odd_row(matrix);
return 0;
}
Learning outcome: assess students ability to:
Create a 2D array in a program.
Access data in a 2D array.
Define functions with the application of 2D array.
Generate and use random numbers.
Activity description: sum of all ODD numbers of the value in each ROW of a 5-by-5 matrix (2D array).
Create a program that will sum all ODD numbers in each ROW of a 2-dimension array. The program will:
Set the size of an array as a global constant variable with value of 5.
define function rand_number(). Function rand_number() is used to randomly generate a value between -20 and 20 and return the value as an integer.
Define function populate_rand_numbers(). Function populate_rand_numbers() is used to populate the 5-by-5 matrix. It means that each cell of the 5 rows and 5 columns will be populated with one random number. This random number is obtained by using function rand_number().
define function print_rand_number(). Function print_rand_number() is used to print the value in each cell of the 5-by-5 array.
define function sum_odd_row(). Function sum_odd_row() is used to sum all ODD numbers of the values in each ROW of a 5-by-5 array.
Define function prompt_sum_odd_row(). The function is used to print the result of the sums as:
Sum all odd numbers in row 1=____
Sum all odd numbers in row 2=____
Sum all odd numbers in row 3=____ solve thius c++ programthis

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!