C++
Write a function named timesOfLetter that reads an array and returns the number of times of each lowercase vowel and each uppercase vowel 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 the input is alphabetic or not during inputting.
• Write a function named isInt() that determines the input is a digit or not during inputting.
• Initialize the size of the arrays as 10.
#include <iostream>
using namespace std;
bool isChar (char c)
{
if ((c >= 65 && c <= 90) || (c >= 97 && c
<= 122)) // ASCII value range for capital alphabets is 65 – 90
and for small alphabets is 97 – 122
return true;
else
return false;
}
bool isInt (char c)
{
if (c >= 48 && c <= 57) // ASCII value range for
digits is 48 – 57
return true;
else
return false;
}
void timesOfLetter (char *array, int *l_vowel, int
*u_vowel)
{
char c;
for(int i=0; i<10 ; i++){ // reading 10 alphabets from
user
cin>>c;
if(isChar(c)){
array[i] = c; }
else
i--; // if alphabet is not entered then don't take the input so
decrement the index
}
for(int i=0; i<10 ; i++){
if (array[i]=='A' || array[i]=='E' || array[i]=='I' ||
array[i]=='O' || array[i]=='U') // checking uppercase vowels
(*u_vowel)++;
if (array[i]=='a' || array[i]=='e' || array[i]=='i' ||
array[i]=='o' || array[i]=='u') // checking lowercase vowels
(*l_vowel)++;
}
}
void timesOfNumber (char *array, int *o_num, int *e_num)
{
char c;
for(int i=0; i<10 ; i++){ // reading 10 numbers from
user
cin>>c;
if(isInt(c))
array[i] = c;
else
i--; // if number is not entered then don't take the input so
decrement the index
}
for(int i=0; i<10 ; i++){
if( array[i]%2 == 0 ) // checking for even number
(*e_num)++;
else // if not even then it is odd
(*o_num)++;
}
}
// Driver function
int main()
{
char array[10];
int l_vowel = 0, u_vowel = 0, o_num = 0, e_num = 0;
cout<<"Enter 10 Alphabets : "<<endl;
timesOfLetter (array, &l_vowel, &u_vowel);
cout<<"Number of Lowercase Vowels :
"<<l_vowel<<endl;
cout<<"Number of Uppercase Vowels :
"<<u_vowel<<endl;
cout<<endl<<"Enter 10 Digits : "<<endl;
timesOfNumber (array, &o_num, &e_num);
cout<<"Number of Even Digits :
"<<e_num<<endl;
cout<<"Number of Odd Digits : "<<o_num;
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.