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
Lotus 1-2-3 allows the user to record, compare, and organize data. It is often used for creating budgets, tracking sales, and ma
Anvisha [2.4K]
It is a spreadsheet document or software
5 0
3 years ago
Today's consoles and games have audio features that rival cinematic audio.<br> True or False?
Angelina_Jolie [31]

Answer:

true

Explanation:

4 0
2 years ago
Read 2 more answers
Define a pointer variable named daco that can be used for objects of the class Banana.
ozzi

Answer:

c)Banana * daco;

Explanation:

To declare an variable pointer we use * symbol after writing it's type.For example int *.Then we write the name of the variable since the name of the variable is daco.The class is a user defined data type so instead of writing any data type we will write class name then the * then name of the variable.

Banana * daco; which matches the option c Banana* daco;

4 0
3 years ago
Read 2 more answers
Andy wants to add a script on his website that will automatically update the current date when the script loads in the browser.
FrozenT [24]
The script that Andy would want to use is Javascript, here is the source code: document.getElementById("para1").innerHTML = formatAMPM();
function formatAMPM() {var d = new Date(),    minutes = d.getMinutes().toString().length == 1 ? '0'+d.getMinutes() : d.getMinutes(),    hours = d.getHours().toString().length == 1 ? '0'+d.getHours() : d.getHours(),    ampm = d.getHours() >= 12 ? 'pm' : 'am',    months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],    days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];return days[d.getDay()]+' '+months[d.getMonth()]+' '+d.getDate()+' '+d.getFullYear()+' '+hours+':'+minutes+ampm;<span>}

The HTML code needed to call this Javascript on his website is this: </span><span><div id="para1"></div>
</span>
You could call the Javascript up using PHP.

Hope this helps! Good luck! :) 
8 0
3 years ago
What programs and outher things could i use to start a youtube gameing chanel
Julli [10]
Try icthio.com I use that and its free.Good luck,!
4 0
3 years ago
Other questions:
  • PLEASE HELP 15 POINTS Emma plans on building a dog house using an algorithm. What will be the final step of the process? a) crea
    6·1 answer
  • is this website just for a bunch of lazy kids bumming off answers? Because if that were the case I'd be one of them.
    9·1 answer
  • Which term describes the process by which light passes through an object or a medium.
    7·2 answers
  • What piece of equipment is NOT a tool that would be considered appropriate equipment for on-site visits? a. multimeter b. flashl
    14·1 answer
  • A cathedral hull allows the boat to do what
    7·1 answer
  • What kinds of dogs are there
    9·2 answers
  • Isa wants to find out if his co-worker Alexis is available for an event on Wednesday, February 10th. Which calendar
    12·1 answer
  • Who Has any idea How to code?
    7·2 answers
  • 1.-  POR QUE LOS HUMANOS NOS INTERESAMOS EN ROBOTS CONASPECTO HUMANO?
    8·1 answer
  • PLS HELP WITH MY PYTHON HW ILL GIVE YOU BRAINLIEST
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!