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

Username:   Password: 
 RegisterRegister   
 String Problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Jurica




PostPosted: Mon Nov 10, 2008 4:23 pm   Post subject: String Problem

Alright having problems with string now, tried to do it but couldn't figure it out. I've done some of it but not all of it.

Question: Write a Turing program that accepts a word typed at the keyboard. Your program will then create the pattern illustrated like this one:

word
o__ r
r__ o Ignore the ___'s.
drow

var word : string

% Tells you to enter a word
put "Enter word: " ..
get word
% Determines how much letters are in the words
put word, " has ", length (word), " letters."
put ""
% Top row

% Right row

% Bottom row

% Left row
for i : 1 .. length (word)
put word (i)
end for
Sponsor
Sponsor
Sponsor
sponsor
OneOffDriveByPoster




PostPosted: Mon Nov 10, 2008 4:34 pm   Post subject: Re: String Problem

You can use code tags:
code:
[code]word
o  r
r  o
drow[/code]

gets you
code:
word
o  r
r  o
drow


Anyhow, the first and last rows are obvious.
The middle rows will follow a pattern: (2nd letter) ((length - 2) spaces) (2nd-to-last letter), etc.
Jurica




PostPosted: Mon Nov 10, 2008 4:38 pm   Post subject: RE:String Problem

Said there were 3 errors, and 2 warnings.
Jurica




PostPosted: Mon Nov 10, 2008 4:45 pm   Post subject: RE:String Problem

Okay, got it. But they put a random word, so it won't be the letter word that will be there, can be anything.
OneOffDriveByPoster




PostPosted: Mon Nov 10, 2008 4:48 pm   Post subject: Re: RE:String Problem

Jurica @ Mon Nov 10, 2008 4:45 pm wrote:
Okay, got it. But they put a random word, so it won't be the letter word that will be there, can be anything.
What I said applies to any input string. You need a loop for the middle rows. Follow the pattern and you will know what to put inside the loop.
Jurica




PostPosted: Tue Nov 11, 2008 3:37 pm   Post subject: RE:String Problem

Okay, I finished it. The code to do it is:

code:

var word : string
var current_line : int := 5
word := "word"
put ""
% Tells you to enter a word
put "Please enter a word: " ..
get word
% Determines how much letters are in the words
put "The word '", word, "' has ", length (word), " letters."
put ""
% Top Row
put word
% Left Row
for i : 2 .. length (word)-1
    put word (i)
end for
% Bottom Row
for decreasing i : length (word) .. 1
    put word (i) ..
end for
% Right Row
for decreasing a : length (word)-1 .. 2
    locate (current_line, length (word))
    put word (a)
    current_line := current_line + 1
end for
Jurica




PostPosted: Tue Nov 11, 2008 3:38 pm   Post subject: RE:String Problem

Opps, made a mistake. Here's the right one:

Turing:

% Variables
var word : string
var current_line : int := 5

% Tells you to enter a word
put "Please enter a word: " ..
get word

% Determines how much letters are in the words
put "The word '", word, "' has ", length (word), " letters."
put ""

% Top Row
put word

% Left Row
for i : 2 .. length (word)-1
    put word (i)
end for

% Bottom Row
for decreasing i : length (word) .. 1
    put word (i) ..
end for

% Right Row
for decreasing a : length (word)-1 .. 2
    locate (current_line, length (word))
    put word (a)
    current_line := current_line + 1
end for
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  [ 7 Posts ]
Jump to:   


Style:  
Search: