
-----------------------------------
Tallguy
Thu Feb 19, 2009 10:45 am

Sorting vowels  and consonants
-----------------------------------
Hey, doing a new asignment that is as follows..
/*5. Input text from the user until a sentinel indicates end of input. After the user indicates
 that there is no more input, clear the screen and redisplay the input so that the original
 word is in one column, vowels are in another column and consonants are in the last
 column. Save as lastname_array#5.t.*/

I got the user to enter their words and all that, but i don't know how to sort the vowels and consonants, i know i', supose to use 'index' and the 'lenght' function this is wat i haveso far...
var counter : int := 0
var words : array 1 .. 9999 of string
put "Please enter text:End with the word '*'"

for i : 1 .. 9999
    get words (i) : *
    counter := counter + 1
    if words (i) = "*" then
        counter := counter - 1
    end if
    exit when words (i) = "*"
end for

var yeah : array 1 .. counter of string

for i : 1 .. counter
    yeah (i) := words (i)
end for

cls

put "You entered, ", counter, " words."
put ""
put "Word               Vowels               Consonants"
put ""

for i : 1 .. counter
    put yeah (i)
    if index (yeah (i), "aeiouAEIOU") not= 0 then
        put yeah (i)
    end if
end for

-----------------------------------
A.J
Thu Feb 19, 2009 10:56 am

Re: Sorting vowels  and consonants
-----------------------------------
so, you have to output all the vowels and the consanants in the input phrase in sorted order ?

a good way of doing this is have an array that stores all the vowels and consanants already preordered.

now, everytime you get to a letter in the input phrase, make it 'checked' on the array..

then, eventually, just wlk through the array and output all the 'checked'  vowels and consanants, and since you already preordered the letters, they are guarenteed to be in order.

-----------------------------------
Tallguy
Thu Feb 19, 2009 10:59 am

RE:Sorting vowels  and consonants
-----------------------------------
so how would one precheck them?, thats wat i'm having problems with..

-----------------------------------
DemonWasp
Thu Feb 19, 2009 11:03 am

RE:Sorting vowels  and consonants
-----------------------------------
The simplest way of doing this is to manually sort each letter in each word into vowel or consonant, then output.

Once you have your user input, inside the for-loop that goes over each word, you need another for-loop that goes over each letter of the given word. Inside this second loop, check whether that letter is a vowel or consonant and add it to the appropriate string. Once you've done that for each letter in the word, output.

This looks like (pseudocode, you'll need to convert it yourself):


for each word (you have for i : 1 .. counter )
    for each letter in word
        if letter is a vowel then
            vowels := vowels + letter
        else
            consonants := consonants + letter
        end if
    end for
    output word, vowels, consonants all on one line here
end for


-----------------------------------
A.J
Thu Feb 19, 2009 11:05 am

Re: Sorting vowels  and consonants
-----------------------------------
just have an array with a preordered copy of all the letters (vowels and consanants).

by 'checking', I mean having a array of boolean that all starts at 'false'....then set it to 'true'
eventually, just output all the elements in the array set to 'true'...

-----------------------------------
Tallguy
Fri Feb 20, 2009 12:11 pm

Re: Sorting vowels  and consonants
-----------------------------------
var counter : int := 0
var words : array 1 .. 9999 of string
put "Please enter text:End with the word '*'"

for i : 1 .. 9999
    get words (i) : *
    counter := counter + 1
    if words (i) = "*" then
        counter := counter - 1
    end if
    exit when words (i) = "*"
end for

var yeah : array 1 .. counter of string

for i : 1 .. counter
    yeah (i) := words (i)
end for

cls

put "You entered, ", counter, " words."
put ""
put "Word               Vowels               Consonants"
put ""

for i : 1 .. counter
    put words (i)
end for

var vowel, consonant : string := ""

for i : 1 .. counter
    for d : 1 .. length (yeah (i))
        if index (yeah (i), "aeiouAEIOU") not= 0 then
            consonant := consonant + yeah (i)
        else
            vowel := vowel + yeah (i)
        end if
    end for
    put yeah (i) : 20, vowel : 20, consonant
end for 

Ok, i did wat you reconmeneded
The simplest way of doing this is to manually sort each letter in each word into vowel or consonant, then output.

Once you have your user input, inside the for-loop that goes over each word, you need another for-loop that goes over each letter of the given word. Inside this second loop, check whether that letter is a vowel or consonant and add it to the appropriate string. Once you've done that for each letter in the word, output.

This looks like (pseudocode, you'll need to convert it yourself):


for each word (you have for i : 1 .. counter )
    for each letter in word
        if letter is a vowel then
            vowels := vowels + letter
        else
            consonants := consonants + letter
        end if
    end for
    output word, vowels, consonants all on one line here
end for



but i still am having problems, i dunno wat it is though

-----------------------------------
DemonWasp
Fri Feb 20, 2009 1:03 pm

RE:Sorting vowels  and consonants
-----------------------------------
First, you need to remember to tell us the exact error message when you post (including what line or lines it complains about). Otherwise, we have to copy-paste your code and run it.

Second, read Turing's documentation for what the index() method does. I think you'll find that:
index (yeah(i),"aeiouAEIOU") not =0
doesn't actually determine whether yeah(i) is a vowel or not. It'd be easier to manually check whether yeah(i) is 'a', 'e', 'i', 'o' or 'u'.

Third, you need to check the index you've given in your assignment statements. It doesn't appear to do what you want it to do (it's using the length of string number i as an index into your array of words, which is incorrect).

-----------------------------------
DemonWasp
Fri Feb 20, 2009 1:21 pm

RE:Sorting vowels  and consonants
-----------------------------------
Addendum: yeah(i) is a string, not a character. You need to test yeah (i) (d), which is character #d of word #i.

-----------------------------------
Jessica359
Fri Feb 20, 2009 1:35 pm

Re: Sorting vowels  and consonants
-----------------------------------
Alright so i'm posting this for alex since were in the same programming class but he does not have access to a coputer right now.
This is the code he has so far, it only displays the first vowel and then first consonant of the word. 

 

/*5. Input text from the user until a sentinel indicates end of input. After the user indicates
 that there is no more input, clear the screen and redisplay the input so that the original
 word is in one column, vowels are in another column and consonants are in the last
 column. Save as lastname_array#5.t.*/

var counter : int := 0
var words : array 1 .. 9999 of string
put "Please enter text:End with the word '*'"

for i : 1 .. 9999
    get words (i) : *
    counter := counter + 1
    if words (i) = "*" then
        counter := counter - 1
    end if
    exit when words (i) = "*"
end for

var yeah : array 1 .. counter of string

for i : 1 .. counter
    yeah (i) := words (i)
end for

cls

put "You entered, ", counter, " words."
put ""
put "Word               Vowels               Consonants"
put ""

var vowel, consonant, watever : string := ""

for i : 1 .. counter
    watever := yeah (i)
    for d : 1 .. length (yeah (i))
        if index ("aeiouAEIOU", watever (d)) not= 0 then
            vowel := vowel + watever (d)
        else
            consonant := consonant + watever (d)
        end if
    end for
end for

for i : 1 .. counter
    put yeah (i) : 20, vowel(i) : 20, consonant(i)
end for




-----------------------------------
DemonWasp
Fri Feb 20, 2009 2:42 pm

RE:Sorting vowels  and consonants
-----------------------------------
Your output is still incorrect. Currently, it will keep track of all the vowels and consonants for ALL of the words in a single variable for each. This isn't what your assignment asks for.

Look more carefully at the flow-of-control I outlined a few posts back. Look where the output occurs.

Secondly, you don't want to output vowel(i) or consonant(i), you want to output vowel and consonant.

-----------------------------------
Tallguy
Sun Feb 22, 2009 6:24 pm

Re: Sorting vowels  and consonants
-----------------------------------
okay, so i got it 2 work, but it outputs everything from before as well as the new 'info', is there a way to 'cancel the old output', if you know wat i mean

/*5. Input text from the user until a sentinel indicates end of input. After the user indicates
 that there is no more input, clear the screen and redisplay the input so that the original
 word is in one column, vowels are in another column and consonants are in the last
 column. Save as lastname_array#5.t.*/
setscreen ("graphics:550,450")
var counter : int := 0
var words : array 1 .. 9999 of string
put "Please enter text:End with the word '*'"

for i : 1 .. 9999
    get words (i) : *
    counter := counter + 1
    if words (i) = "*" then
        counter := counter - 1
    end if
    exit when words (i) = "*"
end for

var yeah : array 1 .. counter of string

for i : 1 .. counter
    yeah (i) := words (i)
end for

cls

put "You entered, ", counter, " words."
put ""
put "Word               Vowels               Consonants"
put ""

var vowel, consonant, watever : string := ""
var count : int := 0

for i : 1 .. counter
    count := count + 11
    locatexy (0, 400 - count)
    put yeah (i)
    watever := yeah (i)
    for d : 1 .. length (yeah (i))
        if index ("aeiouAEIOU", watever (d)) not= 0 then
            vowel := vowel + watever (d)
            locatexy (175, 400 - count)
            put vowel
        else
            consonant := consonant + watever (d)
            locatexy (360, 400 - count)
            put consonant
        end if
    end for
end for





-----------------------------------
DemonWasp
Mon Feb 23, 2009 1:27 am

RE:Sorting vowels  and consonants
-----------------------------------
The problem is that you keep adding to "vowel" and "consonant" without ever clearing the values of either. You can set them each to an empty string by something like this:


vowel := ""
consonant := ""


Now you just need to figure out where to do that.

-----------------------------------
Tallguy
Mon Feb 23, 2009 2:04 pm

Re: Sorting vowels  and consonants
-----------------------------------

setscreen ("graphics:550,450")
var counter : int := 0
var words : array 1 .. 9999 of string
put "Please enter text:End with the word '*'"

for i : 1 .. 9999
    get words (i) : *
    counter := counter + 1
    if words (i) = "*" then
        counter := counter - 1
    end if
    exit when words (i) = "*"
end for

var yeah : array 1 .. counter of string

for i : 1 .. counter
    yeah (i) := words (i)
end for

cls

put "You entered, ", counter, " words."
put ""
put "Word               Vowels               Consonants"
put ""

var vowel, consonant, watever : string := ""
var count : int := 0

for i : 1 .. counter
    count := count + 11
    locatexy (0, 400 - count)
    put yeah (i)
    watever := yeah (i)
    for d : 1 .. length (yeah (i))
        if index ("aeiouAEIOU", watever (d)) not= 0 then
            vowel := vowel + watever (d)
            locatexy (175, 400 - count)
            put vowel
        else
            consonant := consonant + watever (d)
            locatexy (360, 400 - count)
            put consonant
        end if
    end for
    vowel := ""
    consonant := ""
end for





Okay, so it works for some words and doesn't for others, ...

-----------------------------------
Razgriz
Mon Feb 23, 2009 2:21 pm

RE:Sorting vowels  and consonants
-----------------------------------
Works for me.

Kinda cool too :]

-----------------------------------
Jessica359
Mon Feb 23, 2009 2:22 pm

Re: Sorting vowels  and consonants
-----------------------------------
Just to add on to Alex's question, words like "house" and "horse" when there inputed in the program together don't work because the consonants are duplicates, they cancel each other out for some reason and just don't show up?

-----------------------------------
DemonWasp
Mon Feb 23, 2009 2:36 pm

RE:Sorting vowels  and consonants
-----------------------------------
Alright. See up a few posts where I said you should do something like this:


for each word (you have for i : 1 .. counter )
    for each letter in word
        if letter is a vowel then
            vowels := vowels + letter
        else
            consonants := consonants + letter
        end if
    end for
    output word, vowels, consonants all on one line here
end for 


You're pretty close, but your output is still incorrect. The reason that we've got the variables 'vowel' and 'consonant' is so that we can save outputting them until after we've figured out what ALL the vowels / consonants we need to list are.


var vowel, consonant, watever : string := ""
%var count : int := 0 % Don't need this, you were only using it for output. There's an easier way!

for i : 1 .. counter
    %count := count + 1 % Don't need this
    %locatexy (0, 400 - count)
    %put yeah (i)  % Save this for when we've figured out everything we want to say about that word...
    watever := yeah (i)
    for d : 1 .. length (yeah (i))
        if index ("aeiouAEIOU", watever (d)) not= 0 then
            vowel := vowel + watever (d)
            %locatexy (175, 400 - count) % Save it...
            %put vowel
        else
            consonant := consonant + watever (d)
            %locatexy (360, 400 - count) % Stay on target...
            %put consonant
        end if
    end for

    % Okay, now we can output our results. The :20 part ensures that each takes up exactly 20 spaces
    put yeah (i) : 20, vowel : 20, consonant : 20
    vowel := ""
    consonant := ""
end for

