CSSE 120 -- Intro. to Software Development

Homework 6

Reminder: for each class session and associated homework:
  • You do the Reading Quiz on Angel.
  • You do all other work in Eclipse in the project that you checked out for that session.
  • You turn in your Eclipse work by committing that project:
    • Right-click on the project name in the Package Explorer view.
    • Select Team ~ Commit
    • In the message box that appears, put a message to yourself if you wish (eventually, these messages will be for your teammates) and press OK.

Do all your work for this homework in the project you checked out in class today:

    06-StringsAndLists

  1. There is no reading quiz today.
  2. (15 pts) Encoding and Decoding messages: Suppose you are a security agent who encrypts messages that you send to other agents. Of course, the receiving agents need to be able to decode the encoded messages they receive from you.

    1. First, examine the encode function (that's ENCODE, not DECODE) in the 3-encodeDecode.py module of today's project.
      • We implemented that module for you.
      • For the ENCODE function, all that you have to do, per the TODO in the file, is to write a doc-comment for that function.

        Recall that:

        • A doc-comment is a TRIPLE-quoted string placed immediately after the function header.
        • The doc-comment should say WHAT the function does, NOT HOW it does it. Here, that means that the doc-comment should say:
          • What the function inputs (from the user): what it is, and in what form it should be typed.
          • What the function prints (to the console): what it is, and in what form it will appear.
        • Here is partial example (YOU fill in the dots if you use this template!):
          def encode():
              '''
                  Asks the user for a message (as a string, input on a single line) to encode
                  and a key (number) with which to ...
                  Then encodes ...
                    ...
                  The function prints ...
              '''    
          
              # Gets the message and key from the user
              etc
          
    2. Second, examine the decode function (that's DECODE, not ENCODE) in the same module: 3-encodeDecode.py module of today's project.
      • YOU implement this module.
      • Your decode function should be able to:
        • 1. Prompt the user for a list of integer codes that represent a secret message encoded by the encode function above. (See notes below re the form of this input.)
        • 2. Prompt the user for a secret key (the same key used for encoding this secret message).
        • 3. Reverse-engineer the calculation of the encode function to decode the secret message.
        • 4. Display the decoded message to the console.
      • The first thing that you should write for the decode function is its doc-comment. You can't implement something before you know WHAT it is supposed to do!
        • Much of that doc-comment can be obtained by copy-and-paste from the above informal description of the problem.
        • However, the above purposefully leaves some decisions to you. Your doc-comment must specify what you decided re:
          • The form of the input: do you want the user to type:

            A comma-separated sequence of numbers, e.g.:

               184, 181, 188, 188, 191, 112, 196, 184, 181, 194, 181
            
            or the same thing but with the brackets (list notation), e.g.:
               [184, 181, 188, 188, 191, 112, 196, 184, 181, 194, 181]
            
            or the same thing as the first form but with spaces (not commas) separating the numbers:
               184   181   188   188   191   112   196   184   181   194   181
            
            or the numbers on separate lines with (say) -1 to signal end-of-input (warning: this approach would require you knowing how to do an IF statement):
               184
               181
               188
                 etc
               181
               -1
            
            or something else?

          • The form of the output: do you want to print the decoded string as:

            A list of characters, separated by spaces, e.g.:

               h   e   l  l   o      t   h   e   r   e
            
            or a string, e.g.:
               hello there
            
            or something else?

        • Any of the above examples for the input (and possibly other choices too) seem reasonable to me. For the output, the second example above seems much better than the first example above, to me.
      • You will face a number of technical challenges in this problem.
        Click here for some comments/hints.
  3. (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, 4-funcDisplay.py, that implements the following design:

  4. (15 pts) Approximation of pi:

    Do the exercise in the 5-approximatePi.py module of today's project. It asks you to solve a version of exercise 15 on page 78 of your text.

  5. (10 pts) Challenge Problem: This problem is not required, but is an interesting extension that you might like to try.

    In your 4-funcDisplay.py module write and test a version of the functionDisplay function, called enhancedFunctionDisplay() that prompts the user to enter the function for column 2 instead of hard-coding the function, as is done in functionDisplay.

  6. Web links, bacon, eggs, and spam: One of today's in-class examples was a reference to the Penguin sketch. We hope you enjoy this four minute cultural experience!