Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 help me expain this assignment on strings
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
asianrandy




PostPosted: Mon Nov 24, 2008 1:43 pm   Post subject: help me expain this assignment on strings

Strings

1.k in class i have to creating a program which offers the user an opportunity to analyze statisical information about a sentence of their choice. don't get it. help me explain it
2.your program will start by asking the user to input a sentence which will be stored in a variable. it can be of any size. then your program should offers a menu with the following choices. i don't get it explain it for me.in the bold, does it mean the size of the font.

a) total letters in the entire sentence (punctution is included)
b) longest word (and its numbers of letters)
c)total words in the sentence
d) total amount of each letter (ex. 5 a's, 3 b's, etc).
Sponsor
Sponsor
Sponsor
sponsor
Unforgiven




PostPosted: Mon Nov 24, 2008 1:49 pm   Post subject: RE:help me expain this assignment on strings

I'm reasonably sure that the assignment doesn't care about font. The obvious solution is to just ask your instructor, that's what they're there for.

Failing that, though, I'd assume they mean that the length of the string can be of any size.
Insectoid




PostPosted: Mon Nov 24, 2008 2:26 pm   Post subject: RE:help me expain this assignment on strings

You could use getch() to add characters to a flexible array of string, and move to the next index when a space is entered. This would be a little buggy, but would be able to easily give you the number of words (using upper() ), the longest word (for loop counting length of each word), total letters (for loop adding length of words to running total) and number of each letter (running total of each word, used in a for loop).
andrew.




PostPosted: Mon Nov 24, 2008 4:06 pm   Post subject: RE:help me expain this assignment on strings

But you can't backspace or change a word you previously entered using insectoid's method. I think the best way to do it is like this:
code:
var sentence : string
put "Enter a sentence"
get sentence : *

The main thing to note in the above code is that after get I have : *, which means don't ignore the spaces and copy the whole sentence into one variable.
Insectoid




PostPosted: Mon Nov 24, 2008 4:10 pm   Post subject: RE:help me expain this assignment on strings

Andrew- It was complicated, but if you look at my blackjack program (somewhere in Turing Submissions), you can see that I did indeed implement the backspace key into it. It took only a few lines of code and a for loop (because Turing doesn't know how to draw) to use backspace with getch.
andrew.




PostPosted: Mon Nov 24, 2008 4:34 pm   Post subject: RE:help me expain this assignment on strings

Well, maybe that method would work but I find my method easier. Anyways, I finished making the program using my method and I think it's easier for a beginner to understand although I do see how your program works. I just think it's hard for a beginner.
Insectoid




PostPosted: Mon Nov 24, 2008 4:37 pm   Post subject: RE:help me expain this assignment on strings

True. But it would be FAR easier to do the actual task once you have the whole 'getch()' bit done. I like doing it the complicated but awesomer way. (yippee! incorrect grammar!)
asianrandy




PostPosted: Tue Nov 25, 2008 1:41 pm   Post subject: Re: help me expain this assignment on strings

so far i got this. but i need help fixing this and I'm trying to figure out the total amount of each letter( ex. 5 a's, 3 b's, etc).



code:
var sentence : string
var line := % lnitialize line to the empty string
loop
    put "Enter sentence" ..
    get sentence
    exit when sentence = "end"
    put sentence, " has ", length (sentence), "letters" %total words in the sentence
    for i : 1 .. 5000 % %the longest word you can enter in a sentence
        get sentence
        line := line + sentence + " "
    end loop
end for
put line

%total amount of each letter( ex. 5 a's, 3 b's, etc).
Sponsor
Sponsor
Sponsor
sponsor
andrew.




PostPosted: Tue Nov 25, 2008 8:16 pm   Post subject: RE:help me expain this assignment on strings

First of all, you have end loop before end for. They should be switched. Second, your for loop would take waaayyyyy too long to exit. Add an exit condition (exit when....) or make the loop smaller. Third, for counting each letter, you may want to look into arrays because that's the only way I can think of doing it.
asianrandy




PostPosted: Wed Nov 26, 2008 1:52 pm   Post subject: RE:help me expain this assignment on strings

man i can't find it. ahhhh. my head hurts.
jbking




PostPosted: Wed Nov 26, 2008 3:55 pm   Post subject: RE:help me expain this assignment on strings

There is a brute force way to do this with a little over a couple dozen individual counters but an array makes for a nicer solution if you find the trick.
asianrandy




PostPosted: Thu Nov 27, 2008 1:32 pm   Post subject: RE:help me expain this assignment on strings

i can't find any array, to find the total amount of each letter?
jbking




PostPosted: Thu Nov 27, 2008 2:07 pm   Post subject: RE:help me expain this assignment on strings

You don't find an array, you make the array. The array holds 26 numbers which are the number of occurances of a,b,c,...,x,y,z is where we are trying to steer you.
asianrandy




PostPosted: Sat Nov 29, 2008 12:57 pm   Post subject: RE:help me expain this assignment on strings

i need help organzation this and problem need to be fix.

code:
var pos, count, size : int
var sentence, pattern : string
put "Enter a sentence"
get pattern : *
put sentence, " has ", length (sentence), "letters" % total letters in the entire sentence
get sentence
for i : 1 .. 1000 % longest words in a sentence
    size : length (pattern)
    loop
        pos := index (sentence, pattern
        exit when pos = 0
        count := count + 1
        word := word (pos + size .. *)
    end loop
    put "the number of occurrences: ", count
    % This contain the abc's
for i : 65 .. 90
        put chr (i), chr (i + 32), " " ..
    end for
Tyr_God_Of_War




PostPosted: Mon Dec 01, 2008 2:21 pm   Post subject: RE:help me expain this assignment on strings

You have 'get pattern' and 'get sentence' reversed.
You are missing a bracket.
What are you trying to do with
"word := word (pos + size .. *) " ?
You don't have an enough 'end for's.

I can't understand how you are trying to do what you want to do.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: