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...
In C++ Complete the template program. ADD to your c++ program as a comment the PARTIAL...
In C++ Complete the template program. ADD to your c++ program as a comment the PARTIAL output from executing your program - Only copy the last 6 lines of output. There is no input data for this problem. // Find Pythagorean triples using brute force computing. #include <iostream> using std::cout; using std::endl; int main() { int count = 0; // number of triples found long int hypotenuseSquared; // hypotenuse squared long int sidesSquared; // sum of squares of sides cout...
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...
Create a complete java program called Week_Report. The program must include two array structures, a string...
Create a complete java program called Week_Report. The program must include two array structures, a string array called DaysOfWeek and a double array called Temp_Values. Store in the DaysOfWeek array the following values (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday). Store in the Temp_Values array the following (23.5, 34.0, 20.9, 45.7, 29.3, 34.5, 32.5). Using a for loop structure output the values for the two arrays. Day of the Week Temperature Values Monday 23.5 Tuesday 34.0 Wednesday 20.9 Thursday 45.7...
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...
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.
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 program used on the instructions given in the comments: C++ lang #include <string> #include...
Complete the program used on the instructions given in the comments: C++ lang #include <string> #include <vector> #include <iostream> #include <fstream> using namespace std; vector<float>GetTheVector(); void main() { vector<int> V; V = GetTheVector(); //reads some lost numbers from the file “data.txt" and places it in //the Vector V Vector<int>W = getAverageOfEveryTwo(V); int printTheNumberOfValues(W) //This should print the number of divisible values by 7 //but not divisible by 3. PrintIntoFile(W); //This prints the values of vector W into an output file...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT