Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objective: Write void functions, value-returning functions, Boolean functions, u

ID: 3668450 • Letter: O

Question

Objective: Write void functions, value-returning functions, Boolean functions, using cin.get method, if statements, and loops.

Write a C++ program that counts the number of vowels in a text. The program should start by asking the user enter lines of characters terminated by a ‘!’. The program should output the number of vowels. Continue processing lines of characters until the user decides to quit (e.g. ask a y/n question).

For this assignment you must use cin.get() to read a single character. For example, cin.get(ch);

Will read a character from the keyboard and stores it in ch.

Write functions to do each of the following (Required): • A function that return true if a character is a vowel false otherwise. • A function that prints the results.

Note: programs that do not use functions will not be accepted and will get zero points.

Extra credit• Write a function that returns true if a character is a consonant. • Write a function that returns true if a character is a white space. • output the results in the same output function defined above.

Sample input/output: Enter lines of characters terminated by !. A single line of characters. ! There are 9 vowels in the text. Continue (y/n)? y

Explanation / Answer

#include<iostream.h>

#include<conio.h>

#include<string.h>

#include<sstream.h>

int main()

{

string input=" ";

int length,i;

char ch;

char reply;

boolean flag,flag1,flag2;

cout<<"Do you want to continuey: Yes, n: No";

cin>>reply;

while(reply.equals("y")) // or while(reply == "y")

{

cout<<" Enter lines of characters terminated by !";

getLine(cin,input);

length= strlen(input);

for(i=0;i<length;i++)

{

ch= cin.get(i);

}

/*also we can do it as :

while(cin.get(ch) != '!')

{

flag=checkVowel(ch);

flag1=checkConsonant(ch);

flag2= isBlank(ch);

}

} // end of the while

}

boolean checkVowel(char ch)

{

int count=0;

if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')

{

count++;

return true;

}

print(count);

}

void print(int counter)

{

cout<<"there are total"<<counter<<"vowels in the text";

}

boolean checkConsonant(char ch)

{

int count1=0;

if(ch != "a" && ch != "e" && ch!= "i" && ch!="o" && ch!="u")

{

return true;

count1++;

}

print(ch,count1);

}

void print(char ch,int counter) // function overloading

{

cout<<"the consonant" <<ch;

cout<<"total number of consonants are:"<<counter;

}

boolean isBlank(char ch)

{

int count2=0;

if(ch == " ")

{

return true;

count2++;

}

printer(ch,count2);

}

void printer(int counter)

{

cout<<"number of blank spaces are:"<<counter;

}