Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
Need some help with this one. Totally lost

Write a function that takes as a parameter a string and returns the vowels (a,e,i,o,u).

The function prototype should look like this

void countVowels(string str, int& aCt, int& eCt, int& iCt, int& oCt, int& uCt);

any help would be greatly appreciated.
Posted
Updated 21-May-11 10:00am
v2

If you really cannot figure this out then you need to spend some (or a lot of) time with your C++ reference manuals. Look at the string functions such as strchr, and the for, while and if statements.
 
Share this answer
 
This is obviously homework. If we were to do this (trivial) task for you, how would you learn ? A clue - a string is an array of characters. You know how to access items in an array, right ?
 
Share this answer
 
Comments
Richard MacCutchan 22-May-11 3:47am    
You know how to access items in an array, right ?

I don't think you should make too many assumptions. :)

Good to see you back, by the way.
Why are you 'totally lost'?
As already suggested, the trick is accessing the string as an array of characters (string provides the [] operator for the purpose), so your algorithm would be, basically:
  1. Reset vowel counters (aCt=0; ...).
  2. Reset index (say n=0).
  3. if n>=length of the string then exit.
  4. if character at index n, namely str[n] is 'a' then increment aCt else if it is 'e' then increment eCt else if ...
  5. increment index n.
  6. go to point 3.


    1. Would you like some fries too?
      :-)
 
Share this answer
 
v2
Comments
Hans Dietrich 21-May-11 22:14pm    
Yes, and could you double-size me, too?
CPallini 22-May-11 12:44pm    
Of course, sir.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900