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

Username:   Password: 
 RegisterRegister   
 Right justisfy?! Help ASAP
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
chibitenshi_03




PostPosted: Wed Feb 11, 2004 9:27 pm   Post subject: Right justisfy?! Help ASAP

var text : int
var maxLength : int :=60
var word : string
var lineLength : int := 0
open : text, "NewText.txt", get
loop
get : text, skip
exit when eof (text)
get : text, word
if lineLength + length (word) < maxLength then
put " ", word ..
lineLength := lineLength + length (word) + 1
else
put " "
put word ..
lineLength := length (word)
end if
end loop
put " "
How do i make the words right justisfy instead of left justify???
Sponsor
Sponsor
Sponsor
sponsor
McKenzie




PostPosted: Wed Feb 11, 2004 9:34 pm   Post subject: (No subject)

Should have stayed after school today Smile

As you know right is a lot harder than left. The problem is you need to insert spaces at the front of each line, but you don't know how many until you have read more than 60 characters. You will need a string variable that you use to keep track of (by concatenating) the words in the sentence. When you can't add any more words output the line then start again. Watch out for:
1. What happens to that last word that did not fit.
2. The last sentance in your data file.
Paul




PostPosted: Wed Feb 11, 2004 9:37 pm   Post subject: (No subject)

Wow Mackenzie, you hand out some tough assignments, i hope this is not in grade 10...
Im in grade 10, and the first thing that comes to mind here to me is use locate or put " ":10 or drawtext would be easier.
chibitenshi_03




PostPosted: Wed Feb 11, 2004 9:38 pm   Post subject: (No subject)

huh? i'm confused? Confused
McKenzie




PostPosted: Wed Feb 11, 2004 9:42 pm   Post subject: (No subject)

First Paul, it's not my assignment (we have two CS teachers here at Massey) and this one is straight out of the book. The code you see is also straight out of the book (gr 11).

OK, Chi, how well do you understand the code you posted?
Paul




PostPosted: Wed Feb 11, 2004 9:43 pm   Post subject: (No subject)

Mackenzie, would it be alright if say I were doing the assignment and I made the drawtext exactly the same as the output font, and then I counted the number of letters and stuff and then messed around with it so that the coordinate would minus from maxy? and it changes with the length of string so that it would fit perfectly, as in right align. And then Im outta this teacher student conversation.
chibitenshi_03




PostPosted: Wed Feb 11, 2004 9:44 pm   Post subject: (No subject)

not that well... Sad
McKenzie




PostPosted: Wed Feb 11, 2004 9:53 pm   Post subject: (No subject)

The problem, Paul, is knowing where the spaces are. Because you are reading from a file you don't know where to locate until it is too late (short of doing a Pic.New/Pic.Draw manipulation.

Back to the problem
~~~~~~~~~~~~~
Cut your code down to where you understand and add comments to be sure you get it. I suggest starting with:
code:
var text : int
var maxLength : int := 60
var word : string
var lineLength : int := 0
open : text, "NewText.txt", get
loop
    get : text, skip
    exit when eof (text)
    get : text, word
    put word ..

end loop
put " "
Sponsor
Sponsor
Sponsor
sponsor
chibitenshi_03




PostPosted: Wed Feb 11, 2004 10:11 pm   Post subject: (No subject)

umm i don't understand what this line means:
lineLength := lineLength + length (word) + 1
and this one:
lineLength := length (word)
Confused
jonos




PostPosted: Wed Feb 11, 2004 10:17 pm   Post subject: (No subject)

that is just setting the linelength variable to something else, in the first case:

linelength (previously), the length of the word, and 1

in the second case, it is initializing lineLength to the length of word
McKenzie




PostPosted: Wed Feb 11, 2004 10:21 pm   Post subject: (No subject)

Quote:
lineLength := lineLength + length (word) + 1

they are keeping track of how far along the line they are. With each new word they must add on the length of the word plus the length of the space. They need to do this to know when to stop putting them on the same line.

Quote:
lineLength := length (word)

When we find that the last word does not fit that word becomes the first in the next line, so the length of that line is the length of the word itself.
chibitenshi_03




PostPosted: Wed Feb 11, 2004 10:25 pm   Post subject: (No subject)

ohhhhh i get it now! thanks Very Happy
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 1  [ 12 Posts ]
Jump to:   


Style:  
Search: