Question

C++ Write a function named timesOfLetter that reads an array and returns the number of times...

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.

Homework Answers

Answer #1

#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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a function that accepts an int array and the array’s size as arguments. The function...
Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N...
COMPLETE IN C++ Declare and initialize a global constant named SIZE with the value 50. Write...
COMPLETE IN C++ Declare and initialize a global constant named SIZE with the value 50. Write a void function called count that accepts two parameters-- a C-string called str representing a C-string passed to the function and an array of integers called alphabets to store the count of the letters of the C-string. Note that the alphabets array stores 26 counters – one for each letter of the alphabet. Use the same counter for lowercase and uppercase characters. The first...
PLEASE DO IT IN C++ ONLY. THE MIN-MAX DIGIT PROBLEM Write a function named minMaxDigit() that...
PLEASE DO IT IN C++ ONLY. THE MIN-MAX DIGIT PROBLEM Write a function named minMaxDigit() that accepts an integer as an input parameter and returns the largest and smallest digits using the two output parameters min and max. For example, the call minMaxDigit(68437, min, max) would set min to 3 and max to 8. If there is only one digit, then both min and max are set to the same value. The function has no return statement.
1) Write a function in C that takes in a single integer parameter and returns an...
1) Write a function in C that takes in a single integer parameter and returns an array of factors. The function signature should be : int* get_factors(int number) To make things a little easier, assume that the input (number) will never have more than 100 factors. The returned array should be null-terminated. 2) Write a main() function that asks a user for a number, calls the function above, then prints the results.
Write a function that accepts an int array and the array’s size as arguments. The function...
Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named data into an...
Write a function that returns the largest element of an array? Your function should accept a...
Write a function that returns the largest element of an array? Your function should accept a 1-D array as an input and return the largest number. You may assume all numbers are integers. CODE IN C++ PLEASE
Please write a program that reads the file you specify and calculates how many times each...
Please write a program that reads the file you specify and calculates how many times each word stored in the file appears. However, ignore non-alphabetic words and convert uppercase letters to lowercase letters. For example, all's, Alls, alls are considered to be the same words. What is the output of the Python program when the input file is specified as "proverbs.txt"? That is, in your answer, include the source codes of your word counter program and its output. <proverbs.txt> All's...
1. Write a function named "countPositiveNegative" that accepts an array of integers, its size and return...
1. Write a function named "countPositiveNegative" that accepts an array of integers, its size and return the number of positive and negative in the array through the use of parameters. In addition, it also returns the number of 0s in the array as the return value. For example, array of {10, 20, -30, -40, 50, 0, 60} will return 4 for positives, 2 for negatives and 1 for 0's as the return value. 2. Write a function named "rotateRight" that...
(C++) 5.15 LAB: Two smallest numbers with arrays Write a program that reads a list of...
(C++) 5.15 LAB: Two smallest numbers with arrays Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending order. The input begins with an integer indicating the number of integers that follow. Ex: If the input is: 5 10 5 3 21 2 the output is: 2 3 You can assume that the list of integers will have at least 2 values. To achieve the above, first read the integers...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT