CSSE 120 — Introduction to Software Development

Homework 9

Reminder: for each class session and associated homework:

  1. Complete the assigned reading for the next session: Zelle, chapter 6.
  2. (38 points) In ANGEL, complete the Reading Quiz over the above reading.
  3. Pair Programming with someone that you have not paired with previously. All your work for this homework should be done in the 09-StringsFormattingAndFiles project that you checked out from SVN in class. You'll continue these problems in class tomorrow and they'll be do with HW9 on Tuesday after break.

    Be sure to follow the advice for pair-programming so that both partners learn all the material covered and get credit for the work.

    1. (20 pts) Loops and string formatting: Storing information in files is a very important exercise for engineers running experiments that generate a large quantity of useful data.  The stored data can later be analyzed, categorized, and manipulated to allow engineers to draw useful conclusions.  For now, you will write the data to the screen; in a later exercise, you will actually write it to a file.

      Often, the generated data is formatted so that another program can automate the process of analyzing, categorizing, and manipulating the data. In this problem you are to write and test a function functionDisplay in module, funcDisplay.py, that implements the following design:

      • Prompt the user for a number of data points, num,  to print.
      • Write that many points to the screen, as described below. Each line should have the data:

        n      200 + 200cos(n * pi /180)

        where n ranges from 0 to num - 1. Make sure the output is neatly formatted so that numbers and decimal points line up. Below is a sample of the last lines of expected output when n = 123. Your program's output should match this format exactly.

         98   172.165
         99   168.713
        100   165.270
        101   161.838
        102   158.418
        103   155.010
        104   151.616
        105   148.236
        106   144.873
        107   141.526
        108   138.197
        109   134.886
        110   131.596
        111   128.326
        112   125.079
        113   121.854
        114   118.653
        115   115.476
        116   112.326
        117   109.202
        118   106.106
        119   103.038
        120   100.000
        121    96.992
        122    94.016
        

      Submit your Python source file by committing your changes to your SVN repository.

    2. (no part b)
    3. (40 points) Cross Words: This problem requires you to combine string and sequence methods, loops, and graphics. You'll develop a program that accepts two words from the user using a GUI. Then it finds the first character in the second word that happens to appear in the first word. It draws the two words so that they cross through each other.

      You'll solve the problem in stages, with partial credit for each stage completed. The stages are given by TODO items in the module crosswords.py. Below are some sample outputs that are part of the specification. Your program must behave like these examples to receive full credit.

      UPDATE: Here's a video demo of my solution that you might find useful.

      First Word Second Word Expected Display
      hello world
          W
      HELLO
          R
          L
          D
      
      pale ale
      PALE
       L
       E
      
      cAt BoT
        B
        O
      CAT
      
      Ames Iowa
      I
      O
      W
      AMES
      
      Fat Tire
      FAT
        I
        R
        E
      
      Happy Hanukah
      HAPPY
      A
      N
      U
      K
      A
      H
      
      Joyous Festivus
           F
           E
      JOYOUS
           T
           I
           V
           U
           S
      
      Merry Christmas
        C
        H
      MERRY
        I
        S
        T
        M
        A
        S
      

      Note that the correct output for "hello" and "world" is not

      
        W
        O
        R            <--- WRONG, WRONG, WRONG
      HELLO
        D
      

      After each TODO item that you successfully complete, and more often if you wish, commit your work to your SVN repository.

    4. (10 points bonus) Bonus: Modify your crosswords.py module so that instead of exiting after two words, it repeats. With each repeat, pick a new, random location on the window at which to draw the words. Be sure to commit your work for the previous part before attempting this part. I don't want you to lose regular points because you attempted the bonus and broke something.