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);...

  • The statement in the following program is in the incorrect order. Rearrange the statements so that...

    The statement in the following program is in the incorrect order. Rearrange the statements so that they prompt the user to input the shape type (rectangle, circle, or cylinder) and the appropriate dimension of the shape. The program then outputs the following information about the shape: For a rectangle, it outputs the area and perimeter, for a circle, it outputs the area and circumference; and for a cylinder, it output the volume and surface area. After rearranging the statements, your...

  • 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'...

  • Complete the following program to count all vowels in a word. #include #include using namespace std;...

    Complete the following program to count all vowels in a word. #include #include using namespace std; int main() { string word; cin >> word; ... for (...) { string ch = word.substr(i, 1); if (ch == "a" || ch == "e" || ch == "i" || ch == "o" || ch == "u") ... } cout << "Vowels: " << count << endl; return 0; }

  • 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...

  • C++ Debug nextVowel.cpp #include <iostream> using namespace std; // Recursion on a single value // return...

    C++ Debug nextVowel.cpp #include <iostream> using namespace std; // Recursion on a single value // return next character (in ASCII order) // which is a vowel, starting with parameter // If there are no more vowels, return null character ('\0') char nextVowel(char start) { // recursive call return nextVowel(start + 1); // base case if (start > 'z') return '\0'; // incorrect base case if ('a' == start || 'i' == start || 'o' == start || 'u' == start)...

  • 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...

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