Question

In: Computer Science

Program Zeus:    Complete the Count Vowels program (Count Vowels.cpp template provided at the end) to include two...

Program Zeus:    Complete the Count Vowels program (Count Vowels.cpp template provided at the end) to include two user defined functions (which you will write!). Code lenguage is C++

bool isVowel (char c)       // returns true if c is a vowel and false otherwise

int countVowels (string s) // returns the number of vowels in s.

You can access each character of s by using s.at(i) where i ranges from 0 to s.length()-1.

countVowels () should call isVowel (s.at(i)) to check if character i is a vowel.

Run the program once with the following inputs. For full credit, your output should be the same as the output below.

Please enter a word or type "quit" to exit: apple

apple has 2 vowels.

Please enter a word or type "quit" to exit: twang

twang has 1 vowel.

Please enter a word or type "quit" to exit: xyz

xyz has 0 vowels.

Please enter a word or type "quit" to exit: aeiou

aeiou has 5 vowels.

Please enter a word or type "quit" to exit: antidisestablishmentarianism

antidisestablishmentarianism has 11 vowels.

Please enter a word or type "quit" to exit: quit

Goodbye!

Template for Program:

#include<iostream>

#include<iomanip>

#include<fstream>

using namespace std;

bool isVowel(char);

int countVowels(string); .

int main ( )

{

string word;

int numVowels;cout << "Please enter a word or type \"quit\" to exit: ";

cin >> word;

while ()

{

cout << "Please enter a word or type \"quit\" to exit: ";

cin >> word;

}

cout << "Goodbye!" << endl;

return 0;

}

// This function returns the number of vowels in s.

// This function will call isVowel.

int countVowels(string s)

{

}

// This function returns true if c is a vowel and false otherwise

bool isVowel(char c)

{

}

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

bool isVowel(char);

int countVowels(string);

int main()
{
    string word;
    int numVowels;
    cout << "Please enter a word or type \"quit\" to exit: ";
    cin >> word;
    //looping as long as word is not "quit"
    while ( word!="quit") {
        //counting vowels
        numVowels=countVowels(word);
        //displaying results
        cout<<word<<" has "<<numVowels;
        //printing "vowel." if count is 1, "vowels." if count is not 1
        cout<<(numVowels==1?" vowel.":" vowels.")<<endl;
        //asking, reading next word
        cout << "Please enter a word or type \"quit\" to exit: ";
        cin >> word;
    }
    cout << "Goodbye!" << endl;
    return 0;
}

// This function returns the number of vowels in s.
// This function will call isVowel.
int countVowels(string s)
{
        //initializing count to 0
        int c=0; 
        //looping through s
        for(int i=0;i<s.length();i++){
                //checking if char at i is vowel
                if(isVowel(s.at(i))){
                        //updating count
                        c++;
                }
        }
        return c;
}

// This function returns true if c is a vowel and false otherwise
bool isVowel(char c)
{
        //returning true if c is a/e/i/o/u or A/E/I/O/U
        return c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='A' || c=='E' || c=='I' || c=='O' || c=='U';
}

/*OUTPUT*/

Please enter a word or type "quit" to exit: apple
apple has 2 vowels.
Please enter a word or type "quit" to exit: twang
twang has 1 vowel.
Please enter a word or type "quit" to exit: xyz
xyz has 0 vowels.
Please enter a word or type "quit" to exit: aeiou
aeiou has 5 vowels.
Please enter a word or type "quit" to exit: antidisestablishmentarianism
antidisestablishmentarianism has 11 vowels.
Please enter a word or type "quit" to exit: quit
Goodbye!

Related Solutions

The following program should swap the vowels between two strings as long as the end of...
The following program should swap the vowels between two strings as long as the end of either string has not been reached. Example Enter the first string: james Enter the second string: naomi jamos naemi Complete the program by finishing the swap_vowels function. You may not modify ANY existing code given. #include #include #define MAX_SIZE 128 int isvowel(char c) { switch (c) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case...
DESCRIPTION Complete the given program to simulate the roll of two 6-sided dice and count the...
DESCRIPTION Complete the given program to simulate the roll of two 6-sided dice and count the number of rolls of each possible roll value (2 to 12). The number of rolls will be input by the user. Count the rolls of each type and then "draw" a histogram by printing a "*" for each roll of each type. The shape of the histogram will follow the "probability distribution" for large numbers of rolls, i.e., it will show more rolls for...
Write a program that reads in characters until end of file. The program should count and...
Write a program that reads in characters until end of file. The program should count and print the number of characters, printable characters, vowels, digits, and consonants in the input. Use functions to check whether a character is a vowel, a consonant, or a printable character. Define and use macros to test if a character is a digit or a letter.
Reversing Digits - Complete the template program in C++ (Be Original) // reverseNumber.cpp // Reverse the...
Reversing Digits - Complete the template program in C++ (Be Original) // reverseNumber.cpp // Reverse the digits of a number. #include <iostream> using std::cin; using std::cout; using std::endl; #include <iomanip> using std::setw; /* Write prototype for reverseDigits */ // STUDENT WRITES CODE HERE int main() { int number; // input number cout << "Enter a number between 1 and 9999: "; cin >> number; cout << "The number with its digits reversed is: "; // find number with digits reversed...
Complete the assignment as follows: Using the Milestone One SWOT Template provided, conduct a SWOT for...
Complete the assignment as follows: Using the Milestone One SWOT Template provided, conduct a SWOT for the pet supply store’s new product. Consider how this information can help to develop the marketing strategy. You will post your SWOT to the discussion topic as an image. Review this tutorial for assistance with saving your slide as an image and uploading an image to the discussion. In your post, discuss which of the product’s strengths you will be leveraging in your marketing...
C++ Download the attached program and complete the functions. (Refer to comments) main.cpp ~ #include #include...
C++ Download the attached program and complete the functions. (Refer to comments) main.cpp ~ #include #include #define END_OF_LIST -999 using namespace std; /* * */ int exercise_1() { int x = 100; int *ptr; // Assign the pointer variable, ptr, to the address of x. Then print out // the 'value' of x and the 'address' of x. (See Program 10-2) return 0; } int exercise_2() { int x = 100; int *ptr; // Assign ptr to the address of...
Complete the 13-slide Erikson’s Eight Stages of Psychosocial Development presentation template. Instructions for what to include...
Complete the 13-slide Erikson’s Eight Stages of Psychosocial Development presentation template. Instructions for what to include in the presentation are provided in the speaker notes section for each slide, as you work through the presentation template, you will replace the instructions in the speaker notes section with actual speaker notes—that is, sentences that represent what you would say about each slide if you were to give the presentation in person.
Complete P9-3 using the template provided here. P9-3 Perform ratio analysis, and discuss change in financial...
Complete P9-3 using the template provided here. P9-3 Perform ratio analysis, and discuss change in financial position and operating results Condensed balance sheet and income statement data for Jergan Corporation are presented here. JERGAN CORPORATION Balance Sheet December 31 2017 2016 2015 Cash $30,000 $20,000 $18,000 Accounts receivable (net) 50,000 45,000 48,000 Other current assets 90,000 95,000 64,000 Investments 55,000 70,000 45,000 Plant and equipment (net) 500,000 370,000 358,000 $725,000 $600,000 $533,000 Current liabilities $85,000 $80,000 $70,000 Long-term debt 145,000...
Complete the code provided to add the appropriate amount to totalDeposit. #include <iostream> using namespace std;...
Complete the code provided to add the appropriate amount to totalDeposit. #include <iostream> using namespace std; int main() { enum AcceptedCoins {ADD_QUARTER, ADD_DIME, ADD_NICKEL, ADD_UNKNOWN}; AcceptedCoins amountDeposited = ADD_UNKNOWN; int totalDeposit = 0; int usrInput = 0; cout << "Add coin: 0 (add 25), 1 (add 10), 2 (add 5). "; cin >> usrInput; if (usrInput == ADD_QUARTER) { totalDeposit = totalDeposit + 25; } /* Your solution goes here */ else { cout << "Invalid coin selection." << endl;...
#include <iostream> using namespace std; void count( int begin[], int end[] ) { int index, current[4]...
#include <iostream> using namespace std; void count( int begin[], int end[] ) { int index, current[4] = { begin[0], begin[1], begin[2], begin[3] }; add: goto print; carry: if ( current[index] < end[index] - 1 ) { current[index]++; goto add; } else if ( index > 0 ) { current[index] = begin[index]; index--; goto carry; } else return; print: cout << current[0] << current[1] << current[2] << current[3] << endl; index = 3; goto carry; } int main( ) { int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT