Due on Sunday 7th July (11pm-ish)
You will benefit greatly by working in pairs if desired. Plan and think out carefully before you start programming.
The point of these questions is to get you to be able to work with strings, tuples, lists, files, functions, and classes.
Question 1:
Imagine that points in the plane have two coordinates (not necessarily integer-valued). Start by writing a program
which will ask the user to enter several points (ie a pair of numbers per line) and output three lists, one
being those tuples corresponding to points above the line y=x, one being those on that line, and the other
being those points below that line. Your program should also decide which of those three tuples has the
most points, and which the least, and print to the screen (for example) "Above > Below > On" (if there are
more points above the line, than below the line, than on the line).
Now that you've done that, it would be good to allow the user to
specify a file from which your program can read the pairs of coordinates, and then not only show on the screen
the numbers of points above/on/below the line, but also output to a file the three lists you'd made in such a
way that you could later on read that file to recreate those lists.
You might also consider extensions to this program which allow the user to enter equations for different lines, or to
allow counting of points on either side and on other geometric shapes.
Question 2:
One way to model a crossword game would be to have a collection of 'cells', each of which can point to other cells which
are either left, right, up, or down from the current cell. Each cell could contain a letter or a blank (ie a letter
yet to be assigned) or a block (ie no letter can appear there ... a black square in a regular crossword). Build a
class (called cell) to model each of these 'cells', and a class (called crossword) which can hold an arrangement of
these cells. Write a program which allows the user to create such a crossword.
There's a particular puzzle called 'codeword' which, unlike a regular crossword, has no formal clues, but which could be
built by filling in a regular crossword skeleton with words, and then replaces all the letters by numbers from 1 to
26, so that for example every letter 'f' gets replaced by the number 19. Typically, two or three of the number-letter
pairings are told to the player, and then the player has to guess the rest and fill in all the remaining blanks.
Write a program which uses the classes you built for cell and crossword, and gives a user-friendly way for user_1 to
create such a codeword puzzle by entering the 'answer' words in the right places, and then presents user_2 with the
puzzle (ie all the letters have been replaced by numbers and three randomly chosen number-letter pairs have been given
to user_2. Note that we are not asking you to make a pretty graphics display of this, although it's not very
hard to make a rather basic print output (eg using * or ** for a block and then letters, spaces or numbers for the
content of each cell, with the cell being printed using perhaps [ ] as an example), nor are we asking you
to make a program which allows user_2 to actually play this game!!!!
|