Note that there are some explanatory texts on larger screens.

plurals
  1. POStrings and Recursion
    primarykey
    data
    text
    <p>So I was looking around online and I found some assignment question someone had posted, and I think I'd like to have a go at it. It deals with a class and something called a derived class which I'm not interested in trying, (mostly because I don't have a clue what that is), but I saw these requirements and was wondering if they can all be done with recursion, using like a void or int function. Here's what I've got:</p> <blockquote> <p>A method called strLength that returns the length of the string.</p> <p>A method called lowerCase that returns the number of lower case characters.</p> <p>A method called upperCase that returns the number of upper case characters .</p> <p>A method called vowelCnt that returns the number of vowels in a string.</p> <p>A method called charSum that returns the sum of all characters within the string.</p> </blockquote> <p>I think I can do that last one:</p> <pre><code>int charSum(string x, int i) { if(x.size() == i) return (0 + x[i]); else return charSum(x, i + 1) + x[i]; } </code></pre> <p>Although I'm not all that sure about doing it with an actual char, but for the purpose of practicing and seeing how its done using recursion, I'm not too worried about weather it's a char or a string, just that it works.</p> <p>Check that, I found this, (note, I didn't come up with this one, someone named eazar001 did...):</p> <pre><code>int countString(char sample[], int i, int total) { if(sample[i] == 0) { return total; } else { return countString(sample, i+1, ++total); } } </code></pre> <p>Does anybody know how to do the other ones on the list, or have something they can point me to that can show me how to scan a string to look for these things, (especially the upper and lower case stuff, I had no idea there was a difference). Thanks a million to anyone willing to walk me though this stuff as I try to self teach!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload