Question

Take the following C++ code and add to it the following: Write a program that reads...

Take the following C++ code and add to it the following:

Write a program that reads a string and outputs the number of times each lowercase vowel appears in it. Your program must contain a function with one of its parameters as a char variable, and if the character is a vowel, it increments that vowel's count.

#include<iostream>

#include<string>

using namespace std;

int countVowel(char, char);

int main(void)
{
string str1;
int countA = 0;
int countE = 0;
int countI = 0;
int countO = 0;
int countU = 0;
  
cout<<"ENter a word to count vowels: ";
cin>>str1;
  
for(int i = 0; i<str1.length (); i++)
{
countA = countA + countVowel (str1.at (i), 'a');
countE = countE + countVowel (str1.at(i), 'e');
countI = countI + countVowel (str1.at (i), 'i');
countO = countO + countVowel (str1.at (i), 'o');
countU = countU + countVowel (str1.at (i), 'u');
}
cout<<"The vowel A appears: ";
<<countA<<end1;
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>

using namespace std;

int countVowel(char, char);

int main(void)
{
    string str1;
    int countA = 0;
    int countE = 0;
    int countI = 0;
    int countO = 0;
    int countU = 0;

    cout << "ENter a word to count vowels: ";
    cin >> str1;

    for (unsigned int i = 0; i < str1.length(); i++) {
        countA = countA + countVowel(str1.at(i), 'a');
        countE = countE + countVowel(str1.at(i), 'e');
        countI = countI + countVowel(str1.at(i), 'i');
        countO = countO + countVowel(str1.at(i), 'o');
        countU = countU + countVowel(str1.at(i), 'u');
    }
    cout << "The vowel a appears: " << countA << endl;
    cout << "The vowel e appears: " << countE << endl;
    cout << "The vowel i appears: " << countI << endl;
    cout << "The vowel o appears: " << countO << endl;
    cout << "The vowel u appears: " << countU << endl;
}

int countVowel(char c1, char c2) {
    return c1 == c2;
}

gcc version 4.6.3 2 ENter a word to count vowels: hello_how_are you? The vowel a appears: 1 The vowel e appears: 2 The vowel i appears: 0 The vowel o appears: 3 The vowel u appears: 1

\color{red}Please\;let\;me\;know\;if\;you\;need\;me\;to\;make\;any\;changes..

> can u make it appear the total of all vowels.

BASIC BASIC Sat, Nov 13, 2021 4:10 AM

> using int count_vowels(string str)

BASIC BASIC Sat, Nov 13, 2021 4:10 AM

Add a comment
Answer #2

Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str = "There", then after removing all the vowels, str = "Thr". After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel


source: cengage
answered by: TJ Jacobs
Add a comment
Know the answer?
Add Answer to:
Take the following C++ code and add to it the following: Write a program that reads...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • // Write a program that determines how many of each type of vowel are in an...

    // Write a program that determines how many of each type of vowel are in an entered string of 50 characters or less. // The program should prompt the user for a string. // The program should then sequence through the string character by character (till it gets to the NULL character) and count how many of each type of vowel are in the string. // Vowels: a, e, i, o, u. // Output the entered string, how many of...

  • Write a program that prompts the user to input a string. The program then uses the...

    Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. #include <iostream> #include <string> using namespace std; void removeVowels(string& str); bool isVowel(char ch);...

  • Here is my code to put a quote down, flip it, and reverse it. I do...

    Here is my code to put a quote down, flip it, and reverse it. I do not have much knowledge on coding. Does my code only use Variables, Console I/O, Java Program Design, Intro to IDEs, If Statements, Selection and Conditional Logic, Strings, Loops, Nesting, and Iteration? If not, could it be fixed to only use them? These are the offical steps of the assignment: - Ask a user to enter a quote - whether it's several sentences or a...

  • C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure...

    C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure you test your code. Supplied code #include <stdio.h> int main(void) { char ch; int countA = 0; int countE = 0; int countI = 0; printf("Enter in a letter A, E, or I.\n"); scanf(" %c", &ch); //Replace the following block with your switch if(ch == 'E' || ch == 'e') countE++; else if(ch == 'A' || ch == 'a') countA++; else if(ch == 'I'...

  • I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly...

    I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...

  • Using C++ Use the below program. Fill in the code for the 2 functions. The expected...

    Using C++ Use the below program. Fill in the code for the 2 functions. The expected output should be: The:fox:jumps:over:the:fence.: The:fox:jumps:over:the:fence.: The:fox:jumps:over:the:fence.: The:fox:jumps:over:the:fence.: #include #include #include using namespace std; //Assume a line is less than 256 //Prints the characters in the string str1 from beginIndex //and inclusing endIndex void printSubString( const char* str1 , int beginIndex, int endIndex ) { } void printWordsInAString( const char* str1 ) { } int main() { char str1[] = "The fox jumps over the...

  • I need to add a for or a while loop to the following code. please help...

    I need to add a for or a while loop to the following code. please help needs to be in c++. #include <iostream> #include <string.h> using namespace std; int main() {    char input[100]; cout << "Please enter a character string: "; cin >> input; char *head = &input[0], *tail = &input[strlen(input) - 1]; char temp = *head; *head = *tail; *tail = temp; tail--; head++; cout << "CString = " << input << "\n"; }

  • In C++ Please The given program reads a list of single-word first names and ages (ending...

    In C++ Please The given program reads a list of single-word first names and ages (ending with -1), and outputs that list with the age incremented. The program fails and throws an exception if the second input on a line is a string rather than an int. At FIXME in the code, add a try/catch statement to catch ios_base:: failure, and output o for the age. Ex: If the input is: Lee 18 Lua 21 Mary Beth 19 Stu 33...

  • I'm having trouble getting my program to output this statement Enter a sentence: Test! There are...

    I'm having trouble getting my program to output this statement Enter a sentence: Test! There are 5 total characters. There are 1 vowel. There are 1 UPPERCASE letters. There are 3 lowercase letters. There are 1 other characters. Here's my code: #include<string.h> #include<stdio.h> #include<stdbool.h> int main() { char str[100]; int i; int vowels=0; int UC; int LC; int Others; int c; printf("Enter a sentence: \n"); gets(s); LC=countLC(&s); UC=countUC(&s); Others=countOthers(&s); printf("There are %d total characters.\n", ; for(i=0; i<strlen(str); i++){ if(isVowel(str[i])) vowels++;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT