C++ Need help with the functions While testing I am not getting the count for the vowles and consontants. Please jelp and test each option. Write a function that accepts a C-string as its argument. The function should count the number of vowels appearing in the string and return that number. Write another function that accepts a C-string as its argument. This function should count the number of consonants appearing in the string and return that number. Demonstrate the two functions in a program that performs the following steps: 1. The user is asked to enter a string. 2. The program displays the following menu: A) Count the number of vowels in the string B) Count the number of consonants in the string C) Count both the vowels and consonants in the string D) Enter another string E) Exit the program 3. The program performs the operation selected by the user and repeats until the user selects E, to exit the program. // Sharissa Sullivan //Febuary 2 2023 // Chapter 10 Vowels and Consonants #include // headers for defining a string and c string functions strlen #include #include #include #include // to convert lower case letter to upper case using namespace std; //Protype functions int countVowles(const char *); int countConst(const char *); int main() { //create the variables char stringInput[100]; char outPut; //Prompt the user to enter their name and display on screen cout << " Enter your name with a max of 100 characters:\n "; // Use a varaible to store the user input //in >> stringInput; // Use getline function to store the user input cin.getline(stringInput, 101); // use do-while loop and print the following statments : use \n at the end of each sentence to go to the next line do { cout << "\nEnter your choice \n"; cout << " A) Count the number of vowels in the string \n"; cout << " B) Count the number of consonants in the string \n"; cout << " C) Count both the vowels and consonants in the string\n"; cout << " D) Enter another string \n"; cout << " E) Exit the program\n"; cout << " Please enter your choice\n"; cin >> (outPut); // output is not equal to A,B,C,D,E && = And != not equal to while (outPut != 'A' && outPut != 'B' && outPut != 'C' && outPut != 'D' && outPut != 'E'); { cout << "Please enter a valid choice (A, B, C, D or E)!\n"; cin >> outPut; } switch (outPut) { case 'A': cout << "There are" << countVowles(stringInput); cout << "vowles in the string.\n"; break; case 'B': cout << "There are" << countConst(stringInput); cout << " consonants in the string.\n"; break; case 'C': // use strlen to return to the numbers of vowles and constants cout << "There are " << strlen(stringInput); cout << " vowels and constants in the string.\n"; break; case 'D': cout << "Enter your mother's name:"; cin.ignore(); cin.getline(stringInput, 101); break; case 'E': break; } } while (outPut != 'E'); return 0; } // Create count vowels function and return the number int countVowles(const char *pointer ) { //create variable int vowels = 0; //Use a while condition while (*pointer != '\0') { // toupper retuns an upper case letter if (toupper(*pointer) == 'A' || toupper(*pointer) == 'E' || toupper(*pointer) == 'I' || toupper(*pointer) == 'O' || toupper(*pointer) == 'U' || toupper(*pointer) == 'Y') vowels++; pointer++; } return vowels++; } int countConst (const char *pointer) { //create a variable int cCounter = 0; while (*pointer != '\0') { if (toupper(*pointer) != 'A' || toupper(*pointer) != 'E' || toupper(*pointer) != 'I' || toupper(*pointer) != 'O' || toupper(*pointer) != 'U' || toupper(*pointer) != 'Y' && isalpha(*pointer) ) cCounter++; pointer++; } return cCounter; }
C++ Need help with the functions
While testing I am not getting the count for the vowles and consontants.
Please jelp and test each option.
Write a function that accepts a C-string as its argument. The function should count the number of vowels appearing in the string and return that number.
Write another function that accepts a C-string as its argument. This function should count the number of consonants appearing in the string and return that number.
Demonstrate the two functions in a program that performs the following steps:
1. The user is asked to enter a string.
2. The program displays the following menu:
A) Count the number of vowels in the string
B) Count the number of consonants in the string
C) Count both the vowels and consonants in the string
D) Enter another string
E) Exit the program
3. The program performs the operation selected by the user and repeats until the user selects E, to exit the program.
// Sharissa Sullivan
//Febuary 2 2023
// Chapter 10 Vowels and Consonants
#include <iostream>
// headers for defining a string and c string functions strlen
#include <iostream>
#include <string>
#include <cstring>
#include <cctype> // to convert lower case letter to upper case
using namespace std;
//Protype functions
int countVowles(const char *);
int countConst(const char *);
int main() {
//create the variables
char stringInput[100];
char outPut;
//Prompt the user to enter their name and display on screen
cout << " Enter your name with a max of 100 characters:\n ";
// Use a varaible to store the user input
//in >> stringInput;
// Use getline function to store the user input
cin.getline(stringInput, 101);
// use do-while loop and print the following statments : use \n at the end of each sentence to go to the next line
do
{
cout << "\nEnter your choice \n";
cout << " A) Count the number of vowels in the string \n";
cout << " B) Count the number of consonants in the string \n";
cout << " C) Count both the vowels and consonants in the string\n";
cout << " D) Enter another string \n";
cout << " E) Exit the program\n";
cout << " Please enter your choice\n";
cin >> (outPut);
// output is not equal to A,B,C,D,E && = And != not equal to
while (outPut != 'A' && outPut != 'B' && outPut != 'C' &&
outPut != 'D' && outPut != 'E');
{
cout << "Please enter a valid choice (A, B, C, D or E)!\n";
cin >> outPut;
}
switch (outPut)
{
case 'A':
cout << "There are" << countVowles(stringInput);
cout << "vowles in the string.\n";
break;
case 'B':
cout << "There are" << countConst(stringInput);
cout << " consonants in the string.\n";
break;
case 'C': // use strlen to return to the numbers of vowles and constants
cout << "There are " << strlen(stringInput);
cout << " vowels and constants in the string.\n";
break;
case 'D':
cout << "Enter your mother's name:";
cin.ignore();
cin.getline(stringInput, 101);
break;
case 'E':
break;
}
} while (outPut != 'E');
return 0;
}
// Create count vowels function and return the number
int countVowles(const char *pointer ) {
//create variable
int vowels = 0;
//Use a while condition
while (*pointer != '\0') {
// toupper retuns an upper case letter
if (toupper(*pointer) == 'A' || toupper(*pointer) == 'E' ||
toupper(*pointer) == 'I' || toupper(*pointer) == 'O' ||
toupper(*pointer) == 'U' || toupper(*pointer) == 'Y')
vowels++;
pointer++;
}
return vowels++;
}
int countConst (const char *pointer) {
//create a variable
int cCounter = 0;
while (*pointer != '\0') {
if (toupper(*pointer) != 'A' || toupper(*pointer) != 'E' ||
toupper(*pointer) != 'I' || toupper(*pointer) != 'O' ||
toupper(*pointer) != 'U' || toupper(*pointer) != 'Y' &&
isalpha(*pointer)
)
cCounter++;
pointer++;
}
return cCounter;
}
Please refer to the following steps for the complete solution to the problem above.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images