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

Write a C++ program that uses a function named countNum2s that takes as input an

ID: 3698077 • Letter: W

Question

Write a C++ program that uses a function named countNum2s that takes as input an array of integers and an integer that specifies how many entries are in the array. The function should return the number 2's in the array. The program also uses another function named countNum3s that takes as input an array of integers and an integer that specifies how many entries are in the array. The function should return the number 3's in the array. The maximum size of the array is 50. The program should also use a function to read data into the array and another function to print the content of the array. Your main program should call the functions in the following order: Read data Print array countNum2 countNum3

Explanation / Answer

#include<iostream>
using namespace std;
int countNum2s(int a[],int n){
int count =0;
for(int i=0;i<n;i++)
if(a[i]==2)
count++;
return count;
}
int countNum3s(int a[],int n){
int count =0;
for(int i=0;i<n;i++)
if(a[i]==3)
count++;
return count;
}
void readData(int a[],int n){
for(int i=0;i<n;i++)
cin>>a[i];
}
void printArray(int a[],int n){
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
}
int main(){
int a[50],n;
cout<<"Enter number of elements in the array";
cin>>n;
cout<<"Enter the array elements";
readData(a,n);
printArray(a,n);
cout<<" Number of 2's = "<<countNum2s(a,n);
cout<<" Number of 3's = "<<countNum3s(a,n);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote