Question

c++ microsoft visual studio Write a function that given a string it will return the number...

c++ microsoft visual studio

Write a function that given a string it will return the number of vowels in the string. Function prototype is given by: int getNumVowels(string s1);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include<string>

using namespace std;

int getNumVowels(string s1){
   const char* str = s1.c_str();
   int count = 0;
   for(int i = 0;str[i]!='\0';i++){
       if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' || str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U'){
           count++;
       }
   }
   return count;
}

int main() {
   cout<<getNumVowels("qwertyuiopasdfghjklzxcvbnm")<<endl;
   system("pause");
}

\color{red}\underline{Output:}

Press any key to continue - - - Process exited after 1.168 seconds with returnvalue 0 Press any key to continue - -

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

Add a comment
Know the answer?
Add Answer to:
c++ microsoft visual studio Write a function that given a string it will return the number...
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
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
ADVERTISEMENT