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

Username:   Password: 
 RegisterRegister   
 need help with a turing program. detecting anagrams
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zangard




PostPosted: Tue Dec 13, 2016 8:46 am   Post subject: need help with a turing program. detecting anagrams

so i have an assignment where i have to write a code that will detect an anagram from a .txt file i have some code that i wrote up but im stuck on getting it to detect the anagrams, ill be posting the code upon request.
Sponsor
Sponsor
Sponsor
sponsor
NightOwl




PostPosted: Tue Dec 13, 2016 6:22 pm   Post subject: RE:need help with a turing program. detecting anagrams

What have you done so far? Can you post the code for people to see so they can actually help you?

Also, what do you exactly mean by "detecting anagrams? Can you describe it in more specific details?
zangard




PostPosted: Wed Dec 14, 2016 8:19 am   Post subject: Re: RE:need help with a turing program. detecting anagrams

NightOwl @ Tue Dec 13, 2016 6:22 pm wrote:
What have you done so far? Can you post the code for people to see so they can actually help you?

Also, what do you exactly mean by "detecting anagrams? Can you describe it in more specific details?


Problem Description
An anagram is a word or a phrase formed by rearranging the letters of another phrase such as
“ITEM” and “TIME”. Anagrams may be several words long such as “CS AT WATERLOO” and
“COOL AS WET ART”. Note that two phrases may be anagrams of each other even if each
phrase has a different number of words (as in the previous example). Write a program to
determine if two phrases are anagrams of each other.
Input Specifications
The program should read two phrases at a time from a text file called “anagrams.txt”. You may
assume that the input only contains upper case letters and spaces. Each phrase will be on a
separate line.
Output Specifications
The program will output both phrases on the screen, and then print out one of two statements: ”Is
an anagram.” or ”Is not an anagram.” The program should terminate once the end of file has
been reached.

Hint
Use arrays to keep track of the frequencies of each letter in each phrase. If the frequencies match
for both phrases then the two phrases must be anagrams of each other. You could have an array
that holds 26 elements, where the first element is the frequency of the letter ‘A’, and the second
element is the frequency of the letter ‘B’, and so on
zangard




PostPosted: Wed Dec 14, 2016 8:54 am   Post subject: Re: need help with a turing program. detecting anagrams

var freq1: array 1..26 of int:=init (65, 66,67,68,69,70,71,72,73,74,75,76,77,79,80,81,82,83,84,85,86,87,88,89,90,91)
var anagrams : int

var phrase, phrase2 : string
var wordcount : int := 0
open : anagrams, "anagram.txt", get

loop
for x :1..length(phrase)
put freq1(ord(phrase(x))-64)
get : anagrams, skip
exit when eof (anagrams)
get : anagrams, phrase : *
get : anagrams, skip
exit when eof (anagrams)
get : anagrams, phrase2 : *
end for
end loop




heres what i have so far
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  [ 4 Posts ]
Jump to:   


Style:  
Search: