This is an open book, open notes, and open computer test. You may not use any books other than your textbook, and you may not use Internet resources from off campus. If you get stuck, talk to Jeff Ondich. Don't talk to anyone else.
max := 0; for i := 1 to N do begin for j := 1 to N do begin if a[i] - a[j] > max then max := a[i] - a[j] end end
Below is a program that prints out N! for all values of N between 1 and 50. Run it, and then answer the questions that follow.
program factorials(input,output); const top = 50; var k : integer; function factorial( n : integer ) : integer; begin if n <= 1 then factorial := 1 else factorial := factorial( n - 1 ) * n end; begin for k := 1 to top do writeln( k, '! = ', factorial( k ) ) end.
{================================================== Returns true if the given word is an English word, and false otherwise. ==================================================} function IsInDictionary( word : string ) : boolean; {================================================== Returns the next word from standard input in the variable parameter "word". ==================================================} procedure ReadWord( var word : string );Using these routines, write a main program that takes input from a file in our usual way (using "<" on the command line), and prints out all the words in the file that are misspelled--that is, all the words that do not appear in the dictionary.
Note that you should NOT try to write
IsInDictionary or ReadWord.
One approach to the search for anagrams is to list all possible rearrangements (also known as "permutations") of the word or words in question, after which the permutations can be looked up in the dictionary. For example, the six permutations of the letters in "TEA" are "AET," "ATE," "EAT," "ETA," "TAE," and "TEA," five of which appear in the Official Scrabble Players' Dictionary.
Suppose you wanted to generate all the permutations of the word "BREAD". You could approach the task like so:
Generate all permutations that start with B Generate all permutations that start with R Generate all permutations that start with E Generate all permutations that start with A Generate all permutations that start with DHow would you go about doing that first step? Well, you might do the following:
B followed by all permutations of READ starting with R B followed by all permutations of READ starting with E B followed by all permutations of READ starting with A B followed by all permutations of READ starting with DIf this looks recursive to you, good.
Here are your tasks.
{================================================== Permute prints out all the permutations of the character string s in which s[1],...,s[index] are fixed. ==================================================} procedure Permute( s : string; index : integer );You can, of course, use the built-in function length that returns the length of a string. Also, if you use the above interface, you'll want to call it initially with index = 0, like this: Permute('BREAD',0).