In: Computer Science
Write a function named timesOfLetter that reads an array and returns the number of times of each lowercase letter and each uppercase letter appear in it, using reference parameter. • Write a function named timesOfNumber that reads an array and returns the number of times of each odd number, and each even number appear in it, using reference parameter. • Write a function named isChar() that determines if the input is alphabetic or not during inputting. • Write a function named isInt() that determines if the input is a digit or not during inputting. • Initialize the size of the arrays as 10.
Hints: • Firstly, determine whether the element is a letter or a number, which should not be any other characters. • By passing by reference, the values can be modified without returning them. • You may call a function inside another function.
//function named determines if the input is alphabetic or
not
bool isChar(char c)
{
if((c>='a' && c<='z') || (c>='A'
&& c<='Z'))
return true;
return false;
}
//function that determines if the input is a digit or not
bool isInt(int n)
{
if(n>='0' && n<='9')
return true;
return false;
}
/* function that reads an array and returns the number of times
of each
lowercase letter and each uppercase letter appear in it, using
reference
parameter.
nl = number of lowercase, nu = number of uppercase
*/
void timesOfLetter(int &nl, int &nu)
{
char s[10], ch;
int n = 10;
for(int i=0; i<n; i++)
{
cin>>ch;
if(isChar(i)==false)
{
cout<<"Not
a letter!";
i--;
continue;
}
s[i] = ch;
}
nl = nu = 0;
for(int i=0; i<n; i++)
{
if(s[i]>='a' &&
s[i]<='z') nl++;
else if(s[i]>='A' &&
s[i]<='Z') nu++;
}
}
/* function that reads an array and returns the number of times
of each odd
number, and each even number appear in it, using reference
parameter.
ne = number of even, no = number of odd
*/
void timesOfNumber(int &ne, int &no)
{
int s[10], a;
int n = 10;
for(int i=0; i<n; i++)
{
cin>>a;
if(isInt(i)==false)
{
cout<<"Not
a digit!";
i--;
continue;
}
s[i] = a;
}
ne = no = 0;
for(int i=0; i<n; i++)
{
if(s[i]%2==0) ne++;
else no++;
}
}