Please help me write these algorithms :)

Desop

Member
May 16, 2000
34
0
0
hi there... for my computing class i have to write an algorithm for the following procedures and am really struggling, if any programming gurus could lend a hand i would greatly appreciate it

1. write an algorithm in psuedo code that reads through a string and counts the number of lower case vowels

2. write an algorithm to generate random numbers, store them in an array, sort them and print them in order (descending and ascending)

3. modify an algorithm to change order in a selection sort


Im at a complete loss as to how to approach these... any help would be appreciated
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
when writing algorithms/pseudocodes, it's easier to think of how you would solve the problem if you were only given paper and pencil to work with .... i'll only consider question 1 here...

start with setting a counter variable to zero ...
read in a string...
go through the string one by one
for every character that's lower case vowel, add one to the counter
when you reach the end of the string, you're done

btw, the above is not really a pseudocode, but how you can go about doing it if you were only using paper and pencil (or some other prehistoric tools). now think about it, what kind of pattern are you repeating? in this case, you repeat the pattern of "comparing a character to lower case letter, see if the character is one". you also keep adding the counter if you encounter a lower case vowel... for the repeated patterns, you can use a loop .... and since you don't add the counter with every loop, you will need a logical if statement to control when the counter is incremented....

i know it's not clear, but i hope it gives you idea on how to work on the rest of them.... just start by thinking not in computer/programming terms, but think in human/paper/pencil term ... when you get the pattern, then you translate it to the way how a computer may think .....

good luck :)

-1030-
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Figure out how you would tackle the problem without programming. Describe your method. Then convert your description into psuedo code
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
what EagleKeeper said

have you done question 1? when you're done, post what you think your solution is and we'll add more comments as necessary...

use similar method for question 2 ... i'm assuming the portion for "generating random numbers" is just like that ... "generate random numbers". what will you do with each random number that's generated? put them in array... how long should you continue doing it? (hint: loop)... what to do after that? and how do you do them? that's the pseudocodes you have to come up with...

for question 3, you'll have to know how to do a selection sort (which i admit i don't know). and what do you mean by "change order"? seems like the questions are summarized here?

when is your homework due anyway? ;)

-1032-

edit in reply to the two messages below since i'm too lazy to bump the thread ... :p

-- you're welcome :) .... actually it makes sense because i ended up giving part of the solution to you (that's the problem with pseudocodes). good hint would be like EagleKeeper's, not giving too much ... but in any case, students often think that i'm a good teacher because of the above (i don't go the distance to think of a way to give hints without giving out part of the answer). i would be glad go back to teaching if it's possible, although that's a different story altogether :) but oh well, glad to help ... :)

never mind me, i'm just too tired after first day back at taking classes .....
 

Desop

Member
May 16, 2000
34
0
0


<<

use similar method for question 2 ... i'm assuming the portion for "generating random numbers" is just like that ... "generate random numbers". what will you do with each random number that's generated? put them in array... how long should you continue doing it? (hint: loop)... what to do after that? and how do you do them? that's the pseudocodes you have to come up with...

when is your homework due anyway? ;)

-1032-
>>



thanks stndn.... that actually makes sense :p your doing a way better job than my teacher :)