CMU 15-112 Spring 2019: Fundamentals of Programming and Computer Science
Lab 3 (Due as part of hw3 on Sunday 3-Feb, at 5pm)


Due to the Polar Vortex CMU shutdown, we'll be holding recitation during the lab slot on Friday. You may complete the lab problems collaboratively or solo at whatever time you want.


    Collaborative lab problems

  1. COLLABORATIVE Code Writing: gradebookSummary(gradebookFilename) [15 pts]
    For this problem, we'll assume that gradebooks are stored in .txt files. Each row of the gradebook file contains a student's name (one word, all lowercase), followed by one or more comma-separated integer grades. A gradebook always contains at least one student, and each row always contains at least one grade. Gradebooks can also contain blank lines and lines starting with the "#" character, which should be ignored.

    With this in mind, write the function gradebookSummary(gradebookFilename) that takes the filename of a gradebook as an argument and returns a summary of the gradebook as a string. This summary string should show each student followed by a tab followed by their average grade (rounded to the hundreth place). The summary string should have the students listed in their original order (separated by newlines, but without a newline at the end), but should get rid of any comments or blank lines.

    For example, here is a test case:

    # the following string is the content of the file gradebook1.txt """# ignore blank lines and lines starting with #'s wilma,91,93,94 fred,80,85,90,97,100 betty,88""" assert(gradebookSummary("gradebook1.txt") == "wilma\t92.67\nfred\t90.40\nbetty\t88.00"))

    Hint: You may wonder how to locate and distinguish the name on each gradebook line from the scores... one approach would be to look for the first comma after a newline.
    (Note: If you think you know an easy way to solve this problem but the linter bans your solution, it's probably because you're using a concept we haven't taught yet!)

  2. COLLABORATIVE Code Writing: applyCaesarCipher(message, shiftNum) [10 pts]
    A Caesar Cipher is a simple cipher that works by shifting each letter in the given message by a certain number. For example, if we shift the message "We Attack At Dawn" by 1 letter, it becomes "Xf Buubdl Bu Ebxo".

    Write the function applyCaesarCipher(message, shiftNum) which shifts the given message by shiftNum letters. You are guaranteed that message is a string, and that shiftNum is an integer between -25 and 25. Capital letters should stay capital and lowercase letters should stay lowercase, and non-letter characters should not be changed. Note that "Z" wraps around to "A". So, for example:

    assert(applyCaesarCipher("We Attack At Dawn", 1) == "Xf Buubdl Bu Ebxo") assert(applyCaesarCipher("zodiac", -2) == "xmbgya")

  3. If you finish early, consider working on the collaborative problem mostFrequentLetters from hw3.