Write a program which Asks the user to enter any sequence of

Write a program which:

Asks the user to enter any sequence of characters

The program should display all the lower-case vowels that are present and the number of times each vowel occurs

The program should display all the upper-case vowels that are present and the number of times each vowel occurs

The program should display the upper-case vowel which appears most frequently in the user input AND the number of times it appeared.

The program should display the lower-case vowel which appears most frequently in the user input AND the number of times it appeared.

The user must be asked if he/she wants to continue entering values or quit.

You must demonstrate effective use of the new and delete operators.

Remember to comment your code

Use meaningful or memonic variable names

You must use a pointer to a variable of type char to store the user input, and you MUST allocate the EXACT amount of memory to store all the characters entered by the user. For example:

If the user types Awq, then you need to use the new operator to allocate dynamic memory for a pointer to a char of size 3: UserInputCharArray = new char[3];

If the user types 300 letters, then you need to use the new operator to allocate memory for a pointer to a char of size 300: UserInputCharArray = new char[300];

In order to accomplish this, you must capture the user input one char at a time using a loop. As you are capturing the chars you need to be clever enough to count the chars as you are removing them from the input stream AND somehow use new and delete operators to create and destroy pointers (plural) to store the chars as you are removing them from the input stream. Remember that the new and delete operators work at RUN TIME NOT COMPILE time! So use them to allocate JUST THE EXACT AMOUNT OF MEMORY FOR THE ENTRY.

Below is an example of WHAT NOT TO DO!!!

const in ARRAY_SIZE =100;//bad idea

char *UserInputCharArray = nullptr;//this is correct

//allocate memory to the pointer

UserInputCharArray = new char[ARRAY_SIZE]; //you are allocating at compile time the size of the array; another VERY BAD idea!

This code above is NOT allowed because you are assuming the user will enter a string of exactly 100 chars. Unless you have a crystal ball and can guess that every user will enter a string of 100 chars every single time, DON”T do this. Others reasons why this is not allowed are:

If the user enters a four char entry like “gaga”, then you are wasting memory, by allocating memory for an array of 100 chars

If the user enters a four hundred char entry by typing “gaga” 100 times; then you are not allocatingenough memory, to capture the entire entry!

HINT

char aChar;//declare a variable of type char

// Get a string. Prompt user

cout << \"Enter a string: \";

//capture userInput, one char at a time

aChar = cin.get();

while (aChar != 10)

{

//your code

}

This is the book we are currently using.. \"Starting Out With Cpp From Control Structures Through Objects 8th Edition\" Chapter 10.

Solution

#include<iostream>
#include<string.h>
using namespace std;
/* Returns the lower case vowel character according to position of vowFer array index position
which is passed to this function as parameter */
char LowerChar(int n)
{
switch(n)
{
case 0:
return \'a\';
break;
case 1:
return \'e\';
break;
case 2:
return \'i\';
break;
case 3:
return \'o\';
break;
case 4:
return \'u\';
break;
}//End of switch
}//End of function

/* Returns the upper case vowel character according to position of vowFer array index position
which is passed to this function as parameter */
char UpperChar(int n)
{
switch(n)
{
case 0:
return \'A\';
break;
case 1:
return \'E\';
break;
case 2:
return \'I\';
break;
case 3:
return \'O\';
break;
case 4:
return \'U\';
break;
}//End of switch
}//End of function

//Initializes the VowFre array. Because it is used for both lower case and upper case frequency
void init(int arr[])
{
for(int x = 0; x < 5; x++)
arr[x] = 0;
}//End of function

//Main function
int main()
{
//Declare a variable of type char
char aChar;
//Allocation of memory to a character pointer as per the size of entered data
char *charPointer = new char;
//Array to store the frequency of vowels both lower and upper case
int VowFer[5];
//c counter and max to store the maximum frequency
int c = 0, max;
// Get a string. Prompt user
cout << \"Enter a string: \";
//Capture userInput, one char at a time
aChar = cin.get();
while(aChar != \'\ \')
{
c++;
//If Enter key is pressed stop entering data
if(aChar == \'\ \')
break;
//Stores the accepted character in the pointer
*(charPointer + c) = aChar;
//Increase the counter
aChar = cin.get();
}
cout<<\"\ Length = \"<<c;
//Displays the entered data
cout<<\"\ Entered Data: \";
for(int x = 0; x < c; x++)
cout<<*(charPointer + x);
//Initializes the VowFer array
init(VowFer);
//Loops till end of the entered data
for(int x = 0; x < c; x++)
{
//Checks the lower case vowel character and increase the respective position counter
if(*(charPointer + x) == \'a\')
VowFer[0]++;
else if(*(charPointer + x) == \'e\')
VowFer[1]++;
else if(*(charPointer + x) == \'i\')
VowFer[2]++;
else if(*(charPointer + x) == \'o\')
VowFer[3]++;
else if(*(charPointer + x) == \'u\')
VowFer[4]++;
}//End of for
cout<<\"\ \ Lower case Vowels and its Frequency \ \";
//Loops till end
for(int x = 0; x < 5; x++)
{
//Find the maximum frequency
max = VowFer[x];
if(VowFer[x] > max)
max = x;
//If frequency value is not zero then display
if(VowFer[x] != 0)
{
cout<<\"\ Vowel \" <<LowerChar(x)<<\" occurred \"<<VowFer[x]<<\" times\";
}//End of if
}//End of for loop
cout<<\"\ \ Lower - case vowel \"<<LowerChar(max)<<\" which appears most frequently = \"<<VowFer[max];
//Initializes the VowFer array
init(VowFer);
//Loops till end of the entered data
for(int x = 0; x < c; x++)
{
//Checks the lower case vowel character and increase the respective position counter
if(*(charPointer + x) == \'A\')
VowFer[0]++;
else if(*(charPointer + x) == \'E\')
VowFer[1]++;
else if(*(charPointer + x) == \'I\')
VowFer[2]++;
else if(*(charPointer + x) == \'O\')
VowFer[3]++;
else if(*(charPointer + x) == \'U\')
VowFer[4]++;
}//End of for

cout<<\"\ \ Upper case Vowels and its Frequency \ \";
//Loops till end
for(int x = 0; x < 5; x++)
{
//Find the maximum frequency
max = VowFer[x];
if(VowFer[x] > max)
max = x;
//If frequency value is not zero then display
if(VowFer[x] != 0)
{
cout<<\"\ Vowel \" <<UpperChar(x)<<\" occurred \"<<VowFer[x]<<\" times\";
}//End of if
}//End of for loop
cout<<\"\ \ Upper - case vowel \"<<UpperChar(max)<<\" which appears most frequently = \"<<VowFer[max];
}//End of main

Output:

Enter a string: A mAn in the cAge for yOu and mE.

Length = 33
Entered Data: A mAn in the cAge for yOu and mE

Lower case Vowels and its Frequency

Vowel a occurred 1 times
Vowel e occurred 2 times
Vowel i occurred 1 times
Vowel o occurred 1 times
Vowel u occurred 1 times

Lower - case vowel e which appears most frequently = 2

Upper case Vowels and its Frequency

Vowel A occurred 3 times
Vowel E occurred 1 times
Vowel O occurred 1 times

Upper - case vowel A which appears most frequently = 3

Write a program which: Asks the user to enter any sequence of characters The program should display all the lower-case vowels that are present and the number of
Write a program which: Asks the user to enter any sequence of characters The program should display all the lower-case vowels that are present and the number of
Write a program which: Asks the user to enter any sequence of characters The program should display all the lower-case vowels that are present and the number of
Write a program which: Asks the user to enter any sequence of characters The program should display all the lower-case vowels that are present and the number of
Write a program which: Asks the user to enter any sequence of characters The program should display all the lower-case vowels that are present and the number of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site