1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
shepuryov [24]
3 years ago
15

Given that arrayIntValues [MAX_ROWS][MAX_COLUMNS] is a 2 dimensional array of positive integers, write a C++ function Even to fi

nd the total number of even elements in the array.
It should have input parameter array arrayIntValues.
A[length][width]
Length
Width

The function should return an integer. Also create a C++ subroutine called printArray with the input parameter array.

Computers and Technology
1 answer:
bixtya [17]3 years ago
3 0

Answer:

Here is the C++ program:

#include <iostream>  //to use input output functions

using namespace std;   // to identify objects like cin cout

const int MAX_ROWS=3;  //sets the maximum number of rows to 3

const int MAX_COLUMNS=2;  //sets the maximum number of columns to 2

//function prototypes

void printArray(const int array[MAX_ROWS][MAX_COLUMNS]);  

void Even(const int arrayIntValues[MAX_ROWS][MAX_COLUMNS]);

int main(){  //start of main method

    int arrayIntValues[MAX_ROWS][MAX_COLUMNS];   //declares a 2D array of integers

    cout<<"Enter elements of 2D array: ";  //prompts user to enter integers in a 2D array

    for(int i=0;i<MAX_ROWS;i++)  {  //outer loop to iterate through rows

               for(int j=0;j<MAX_COLUMNS;j++) //inner loop to iterate through columns

               cin>>arrayIntValues[i][j];  }   //reads and stores integers in 2D array

Even(arrayIntValues);  //calls Even method by passing arrayIntValues

printArray(arrayIntValues); }   //calls printArray method by passing arrayIntValues

void Even(const int arrayIntValues[MAX_ROWS][MAX_COLUMNS]){  //method that takes an array as parameter and finds the total number of even elements in the array

    int count = 0;  //counts the number of even numbers in array

       for(int row=0;row<MAX_ROWS;row++){  //outer loop iterates through rows of the array

               for(int col=0;col<MAX_COLUMNS;col++){  //inner loop iterates through columns of the array

               if(arrayIntValues[row][col]%2==0 && arrayIntValues[row][col]>=0)  //if the element at specified index of 2D array is an even number i.e. completely divisible by 2 and that element is positive

                               count++;   }        }  //adds 1 to the count variable each time an even positive integer appears in the array

       cout<<"total number of even elements in the array: "<<count<<endl; }   //displays the number of even element in arrayIntValues

void printArray(const int array[MAX_ROWS][MAX_COLUMNS]){  //method that takes an array as parameter and displays the even numbers in that array

       for(int row=0;row<MAX_ROWS;row++){  //outer loop iterates through rows of the array

               for(int col=0;col<MAX_COLUMNS;col++){  //inner loop iterates through columns of the array

                       if(array[row][col]%2==0 && array[row][col]>=0)  //if the element at specified index of 2D array is an even number i.e. completely divisible by 2 and that element is positive

                               cout<<array[row][col]<<endl;  //displays the even element of the array

                        else  //if element is not even

                        continue;                 }         }       }  //continues the loop to look for even elements

Explanation:

The program first prompts the user to enter elements in 2D array. It then calls Even method which iterates through the rows and columns of the array to look for the positive even numbers (elements) in array . Whenever a positive even number is encountered in the array, the count variable is incremented to 1. At the end the method returns an integer which is the total number of even elements in the array. Then the program calls printArray method which iterates through the rows and columns of the array to look for the positive even numbers (elements) in array . Whenever a positive even number is encountered in the array, that element is displayed on the output screen. The screenshot of the output is attached.    

You might be interested in
Using the world_x database you installed in Module 1, list the countries and the capitals of each country. Modify your query to
Rainbow [258]

Answer:

SELECT country.Name, city.Name

FROM country

JOIN countrylanguage ON country.Code = countrylanguage.CountryCode

JOIN city ON country.Capital = city.ID

WHERE countrylanguage.Language = 'English'

AND countrylanguage.Percentage < 30;

Explanation:

SELECT is used to query the database and get back the specified fields.

City.Name is an attribute of city table.

country.Name is an attribute of country table.

FROM is used to query the database and get back the preferred information by specifying the table name.

country , countrylanguage and city are the table names.

country and countrylanguage are joined based ON country.Code = countrylanguage.CountryCode

countrylanguage and city are joined based ON country.Capital = city.ID

WHERE is used to specify a condition based on which the data is to be retrieved. The conditions are as follows:

countrylanguage.Language = 'English'

countrylanguage.Percentage < 30;

5 0
3 years ago
What does this say in morse code?
Furkat [3]

Answer:

That it is time for lunch?

Explanation:

4 0
3 years ago
Read 2 more answers
Which statement about dialogues is NOT correct? Select one: A. Users should be able to control the direction of speed of dialogu
Gennadij [26K]

Answer:

Option B is not correct

Explanation:

Dialogues become problematic when they appear automatically because of high level incompatibility

3 0
2 years ago
Digital Subscriber Line (DSL) is a way for traditional telephone companies to provide Internet access a way for traditional cabl
zvonat [6]

Answer:

Option A is correct

Digital Subscriber line is a way where telephone companies provide internet access for connection.

It is a communication medium used to transfer digital signals. DSL is one of the most popular broadband internet access.

Explanation:

DSL stands for Digital Subscriber Line. DSL works with high-speed bandwidth that connects from a phone jack to a telephone network. DSL works within frequencies. You can use the DSL while making phone calls.

6 0
2 years ago
Read 2 more answers
After earning a learners license what test must be successfully passed to earn an operators license in Florida
Monica [59]
After earning a learners license , the <span>test that must be successfully passed to earn an operators license in Florida is: the driving skill test
The diriving skill test is a set of procedure that all learners must follow in order to determine the learners' ability in driving motor vehicle and test learner's understanding about traffic rules.</span>
5 0
3 years ago
Other questions:
  • One random part of Chess is whether the white side or the black side moves first? A. True B. False
    10·2 answers
  • In order to make burger a chef needs the following ingredients one piece of chicken meat 3 lettuce leaves 6 tomato slices Write
    8·1 answer
  • Vlad is the leader of a group; he receives most of the messages from the group members, and he provides most of the information
    6·1 answer
  • Match the limits of the user with an appropriate design response. 1. severe arthritis, unable to type or use a mouse on a reliab
    11·1 answer
  • Is it safe to tape down cords such as internet cables to the floor?
    14·1 answer
  • What does the third argument (3) refer to in the following formula: VLOOKUP(10005, A1:C6, 3, FALSE)
    6·1 answer
  • Network address 192.10.10.0<br>​
    12·1 answer
  • B. List any four major drawbacks of the first generation computer​
    10·1 answer
  • If im downloading a game at 4mb/s how many minutes would it take to download 25 GB
    14·2 answers
  • Tại sao xe chỉ sản xuất ra 1996cc mà không phải là 2000cc?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!