Question

I'm having trouble to write a value-returning function, isVowel, that returns the value true if a...

I'm having trouble to write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false. Can I get help with this?

0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #2
#include<iostream>

using namespace std;

int isVowel(string s)

{

 int f=0;

 char ch;

 for(int i=0;i<s.length();i++)

 {

 ch=toupper(s[i]);

 if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')

 {

 f=f+1;

 }

 }

 return f;

}

int main()

{

 string s;

 cout<<"Enter a string ";

 cin>>s;

 cout<<"There are "<<isVowel(s)<<" vowels in this sentence.";

}


answered by: samama7777
Add a comment
Answer #1

//Code.cpp

#include<iostream>

using namespace std;

bool isVowel(char ch){
   if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'){
       return true;
   }
   return false;
}

int main(){
   //In c we have to represent the string as array of characters
   char string[100];
   char ch;
   cout<<"Input string: ";
   cin>>ch;
   if(isVowel(ch)==1){
       cout<<ch<<" is a vowel"<<endl;
   }
   else{
       cout<<ch<<" is NOT a vowel"<<endl;
   }
   return 0;
}

input string: 1.82 seconds with Process exited after Press any key to continue - - return val

\small \color{red}Please\; upvote\;the \;solution \;if \;it \;helped.\;Thanks!

Add a comment
Know the answer?
Add Answer to:
I'm having trouble to write a value-returning function, isVowel, that returns the value true if a...
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 write a value-returning function, isVowel, that returns the value true if a...

    Write a program that write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false. You must insert the following comments at the beginning of your program and write our commands in the middle: Write a C++ Program: /* // Name: Your Name // ID: Your ID */ using namespace std; #include <iostream> using namespace std; bool isVowel(char ch); int main() {     char ch;     …     …         ...

  • c++ language Write a program that contains the following functions, i. A function isVowel that takes...

    c++ language Write a program that contains the following functions, i. A function isVowel that takes in a character and returns true if it is a vowel and false otherwise ii. A function that request from the user to enter in a sequence of characters, and outputs the number of vowels entered. (Use Function in a) to assist you, a sentinel value can be used to specify the end of the user input iii. A function that reads 3 test...

  • I'm having trouble getting my program to output this statement Enter a sentence: Test! There are...

    I'm having trouble getting my program to output this statement Enter a sentence: Test! There are 5 total characters. There are 1 vowel. There are 1 UPPERCASE letters. There are 3 lowercase letters. There are 1 other characters. Here's my code: #include<string.h> #include<stdio.h> #include<stdbool.h> int main() { char str[100]; int i; int vowels=0; int UC; int LC; int Others; int c; printf("Enter a sentence: \n"); gets(s); LC=countLC(&s); UC=countUC(&s); Others=countOthers(&s); printf("There are %d total characters.\n", ; for(i=0; i<strlen(str); i++){ if(isVowel(str[i])) vowels++;...

  • Can I see that source code in python Write the following value-returning function: encoded - Takes...

    Can I see that source code in python Write the following value-returning function: encoded - Takes a string as parameter and returns the string with each vowel substituted by its corresponding number as follows: a -1 e-2 0-4 。u_5 The function MUST USE string slicing Write a main program that will take an input string (text) from command line and it will display the input text encoded. You will call the encoded function to get the text encoded.

  • Write a C++ program that will count the number of words and vowels in a sentence....

    Write a C++ program that will count the number of words and vowels in a sentence. Create a bool function called isVowel that accepts a character as a parameter and returns a true if it’s a vowel (aeiou) and false otherwise. Create an int function named countVowels that will accept a string variable as a parameter and will return the number of vowels in it. Call the isVowel function as part of this process. Write an int function named countWords...

  • use JavaScript in Atom Q1: create functions.js. You do not need to create a web page...

    use JavaScript in Atom Q1: create functions.js. You do not need to create a web page (.html) for this requirement. As you write each function, test it using the DevTools console. When it is correct, move on to the next function. A) Write a function named isVowel that accepts a character and returns true if the character a vowel, false otherwise. Use a RegExp to solve this problem, and arrow function syntax. Examples: > isVowel('Y') > true > isVowel('@') >...

  • write a complete function for a value returning function called getName with no parameters, that returns...

    write a complete function for a value returning function called getName with no parameters, that returns a persons name. the function should prompt the user for a name and return it. declare any local variable as neccasasry. for c++

  • Write a C++ function that has a parameter of char type. The function returns true if...

    Write a C++ function that has a parameter of char type. The function returns true if the character is ‘Y’ or ‘y’, and returns false if the character is ‘N’ or ‘n’. You are not allowed to use any pre-defined function.

  • (c++) (codeblocks) Write a program that contains a value-returning function that returns a value to be...

    (c++) (codeblocks) Write a program that contains a value-returning function that returns a value to be displayed in main() with the function call. No values are passed to the function. The function body should be written to generate a random number from 1-10 as its return value. Display with the call to function in main(): The function returned the value of <return value> when it was called in main.

  • write a recursive function that returns true if the digits of a positive integer are in...

    write a recursive function that returns true if the digits of a positive integer are in increasing order ; otherwise, the function returns false. Also write a program to test your function.

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