Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a function called ev5 that takes as input an integer array a1 and its l

ID: 3600372 • Letter: 1

Question

1. Write a function called ev5 that takes as input an integer array a1 and its length l1, and returns true if the number of even elements in the array is more than 5. Test your code in a main function [1 point].

2. Write a class called Array that has the input arguments of the above function as the private members, and a new version of the above function as a public method. The new version of the ev5 function should have only 1 input argument [1 point]. Add any more accessor and mutators methods if needed, and test your class in a main func4on [1 point].

Explanation / Answer

Question 1

Answer:

#include <iostream>

using namespace std;
bool ev5(int a1[], int l1) {
int evenCount = 0;
for(int i=0;i<l1;i++) {
if(a1[i] % 2 == 0) {
evenCount++;
}
}
return evenCount > 5;
}
int main()
{
int a1[10] = {2,3,4,5,6,7,8,9,10,12};
cout<<"Result: "<<ev5(a1, 10)<<endl;

return 0;
}

Output:

Question 2

#include <iostream>

using namespace std;
class Array {
private:
int n;
public:
Array(int a){
n=a;
}
bool ev5(int a1[]) {
int evenCount = 0;
for(int i=0;i<n;i++) {
if(a1[i] % 2 == 0) {
evenCount++;
}
}
return evenCount > 5;
}

};
int main()
{
Array a(10);
int a1[10] = {2,3,4,5,6,7,8,9,10,12};
cout<<"Result: "<<a.ev5(a1)<<endl;


return 0;
}

Output: