Related questions
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 nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- in C program pleasearrow_forwardDo asap please.arrow_forwardWrite a function count_evens() that has four integer parameters, and returns the count of parameters where the value is an even number (i.e. evenly divisible by 2). Ex: If the four parameters are: 1 22 11 40 then the returned count will be: 2 Hint: Use the modulo operator % to determine if each number is even or odd. Your program must define the function:count_evens(num1, num2, num3, num4) python # Define your function here if __name__ == '__main__': num1 = int(input()) num2 = int(input()) num3 = int(input()) num4 = int(input()) result = count_evens(num1, num2, num3, num4) print('Total evens:', result)arrow_forward
- Thanks for the help, but I'm not finished yet. Here are my instructions for my C++ program: Write a program that uses the function isPalindrome given in Example 6-6 (Palindrome). Test your program on the following strings:madam, abba, 22, 67876, 444244, trymeuemyrt Modify the function isPalindrome of Example 6-6 so that when determining whether a string is a palindrome, cases are ignored, that is, uppercase and lowercase letters are considered the same. The isPalindrome function from Example 6-6 has been included below for your convenience. bool isPalindrome(string str) {int length = str.length(); for (int i = 0; i < length / 2; i++) {if (str[i] != str[length – 1 – i]) {return false;} // if } // for loopreturn true;}// isPalindrome Your program should print a message indicating if a string is a palindrome: madam is a palindrome Here's what I have so far: //Include the neccessary header files.#include <iostream>#include <string.h>#include <algorithm> //Declare the...arrow_forwardGiven a string which is basically a sentence without spaces between words. However, the first letter of every word is in uppercase. You need to print this sentence after the following amendments: (i) Put a single space between these words (ii) Convert the uppercase letters to lowercase. Note: The first character of the string can be both uppercase/lowercase. Write a C++ function that takes a string and then performs the mentioned amendments and returns a string.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education