CSC 551: Web Programming
Spring 2004

HW5: CGI Programming


Word ladders are puzzles in which a person is given two words and is challenged to find a sequence of words connecting them, with each word in the sequence differing from the previous one by only one letter. For example, given the two words "love" and "hate", the following word ladders suffices:

love live hive have hate

For this assignment, you are to write a CGI program in C++ that presents a word ladder puzzle to the user and also judges his or her solution. Your program will have access to a dictionary of 5-letter words, which will be stored in a file named words5.txt, one word per line, in the same directory as your program. When called initially (with no input string), your program should select two words at random from this file and return a Web page that contains those two words, a text area for the user's solution (a series of words comprising the ladder), and a submit button for submitting the solution. When your program is called with the word ladder as input, it should verify the correctness of the solution. That is, it should make sure that the ladder begins and ends with the desired words, that each word in the ladder is in the dictionary, and that each word differs by exactly one letter from the previous word. If the ladder is correct, then your program should respond with a page that displays the ladder and confirms its correctness. If it is not correct, the response page should identify the error in the proposed ladder. This final page should also give the user the option of playing again with a new pair of ladder words.

Note: you will be developing your CGI program on your own computer, and only uploading it to a Web server when it is completed. This means that you will need to test your program by providing the input string directly as standard input. Thus, if you want to test the program on an empty input string, execute it and hit ^Z to terminate the input with no string value. When you want to test the program on a ladder, you will need to simulate the URL-encoded input string that will be generated by your page. For example:

ladder=love+live+hive+have+hate

In completing your progam, you may find the following source files useful: