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 the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I -...
Complete the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I - Declaring a five by five array /* II - Read data from data.txt and use them to create the matrix in the previous step*/    // III - Count and print the number of even integers in the matrix. /* IV - Calculate and print the sum of all integers in the columns with an even index value. Please note the column index begins...
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 program #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int main(int argc, char**...
complete the program #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int main(int argc, char** argv) { int number, sum, count; // Write a while loop that reads a number from the user and loop // until the number is divisible by 7 cout << "What is the number? "; cin >> number; while ( ... ) { ... } cout << number << " is divisible by 7!! << endl << endl; // Write a for loop that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT