Write a program that asks the user to input 10 positive inte
Write a program that asks the user to input 10 positive integers and stores them in an array. Be sure to specify if they are to hit return or a space after each number. Count the number of even and odd numbers in the array. Since you must return two counts, place these counts into an array of length 2. Print out the original array of numbers, the count of even, and the count of odd numbers.
The class Numbers should at least include:
a constructor Numbers (construct default array for the numbers)
method inputArray (collects 10 numbers from user and places then into array)
method evenOdds (counts the number of evens and odds and places these counts into an array to be returned)
method printArray (prints out the array of 10 positive integers)
private instance field (only one – the array!)
The main class NumberRunner should:
constructs a Numbers object
Print the array by calling the appropriate method
Print the count of even and odd
For example, if you are given the numbers:
1, 4, 9, 16, 25, 36, 49, 64, 82, 100
The output would be:
The Array is: 1 4 9 16 25 36 49 64 82 100
The number of evens: 6
The number of odds: 4
Solution
#include<iostream.h>
class Numbers
{
int num[], result[];
Numbers()
{
num = new int[10];
result = {0,0};
}
void inputArray()
{
for (int i=0; i<10 ; i++)
{
cout << \"Enter the number\" << i <<\": (and press enter)\" ;
cin>> num[i];
}
}
void evenOdds()
{
for(int i=0; i<10 ; i++)
{
if( num[i] %2 == 0)
result[0]++;
else
result[1]++;
}
}
void printArray()
{
cout << \"The Array is: \" ;
for (int i =0; i<10;i++)
cout <<num[i] << \" \";
}
}
class NumberRunner
{
int main()
{
NumberRunner Numbers = new NumberRunner();
Numbers.inputArray();
Numbers.evenOdds();
Numbers.printArray();
cout << \"\ The number of evens:\" << Numbers.result[0]<<endl
cout;<< \"The number of odds:\" << Numbers.result[1]<<endl;
}
}



