COS 100: Introduction to Programming

Interim 2020

HW Project 10: Gradebook

Due: 01/27 Mon 10pm

For we must all appear before the judgment seat of Christ, that each one may receive the things done in the body, according to what he has done, whether good or bad.
2 Corinthians 5:10
If you are pair programming, do NOT start coding without your partner. You should read the assignment first, feel free to think about it, but do not actually start coding.

Project goal

Create a simple gradebook application.

Prerequisites

Sample run

This time we'll start with a sample run. More detailed specifications will follow.

Project specification

Follow the steps below to write a simple gradebook program.
  1. Create a file named gradebook.txt with the content as the example above.
    • Each line consists of a string followed by some integers, all separated by commas.
    • The string represents a name. The integers represent grades for each assignments.
    • Assume each line has the same number of commas.
    • Your program should work for any similarly-formatted file, not just this one. In particular, it should handle more students and more assignments.
    • Feel free to change this file to test various cases. You do not need to turn in this file. When grading, we will test your program using a different file (same format, but more students and assignments).
  2. Write a function loadGrades(fileName) that takes a file name as input, loads the gradebook data from that file, and returns a 2D list.
    • Open the file given by the file name, read it line by line, and close the file as soon as you can.
    • Assume that the file is properly formatted as described above (but may have more students and assignments).
    • The 2D list should have one row corresponding to each line.
    • The first row is not actually a student, but the fake student "Max Perfect" representing the maximum number of points for each assignment.
    • Each subsequent row is a real student.
    • Make sure you convert all the numbers from strings to integers.
    • print(loadGrades("gradebook.txt")) prints
      [['Max Perfect', 6, 10, 20, 20], ['Rory Gilmore', 5, 9, 13, 7], ['Paris Geller', 6, 10, 20, 19]]
      
    • For convenience, we will refer to the return value of loadGrades as a gradebook matrix.
  3. Write a function printGrades(grades) that takes a gradebook matrix as input and prints it out nicely.
    • Do not print the fake student Max.
    • Number the rest of the students starting at 1; so, e.g., Rory's student ID is 1 and Paris's student ID is 2.
    • For each real student, print, on a single line, the student ID, name, and assignment grades.
    • printGrades(loadGrades("gradebook.txt")) prints
      Student 1       Rory Gilmore    5       9       13      7
      Student 2       Paris Geller    6       10      20      19
      
    • Notice how I got the "13" and the "20" to line up even though "9" is shorter than "10"?
    • Just like \n is a single character marking a new line, \t is a single character that represents a "tab."
    • Print tabs between columns so they line up nicely.
    • (If a student's name is particularly short or long, a single tab might not cause items to line up; you may, but are NOT required to, fix this.)
  4. Write a function getStudentAverage(grades, studentID) that takes a gradebook matrix and a student ID as input and returns the average (out of 100) for that student as a float.
    • Calculate the percentage of each assignment, based on the maximum points.
    • For example, Rory's percentages are 0.8333333333333334, 0.9, 0.65, and 0.35.
    • Calculate their average and multiply by 100.
    • getStudentAverage(loadGrades("gradebook.txt"), 1) returns 68.33333333333333.
    • If you got 60.71428571428571, then you likely divided the total points earned (34) by the total points possible (56), which is not what you are supposed to do.
  5. Write a function getAssignmentStats(grades, assignmentID) that takes a gradebook matrix and an assignment ID as input and returns several statistics as a list.
    • Number the assignments starting at 1.
    • For example, assignment 4 is where Rory got 7 and Paris got 19.
    • Return a list of four items, in this order:
      1. the lowest score received by the students,
      2. the average score of all the students,
      3. the highest score attained by the students,
      4. the maximum points allotted (i.e., the score of the fake student Max).
    • getAssignmentStats(loadGrades("gradebook.txt"), 4) returns [7, 13.0, 19, 20].
    • Note the distinction between the highest score attained (19) and the maximum points allotted (20).
  6. Write a function override(grades) that takes a gradebook matrix and lets the user interactively change some grade items.
    • NOTE: You may want to delay working on this function until after lab12.
    • This function does not return any value (well, it returns None).
    • Instead, it simply changes the gradebook matrix directly in place.
    • Repeatedly ask if the user wants to override a grade.
    • If yes, ask for student ID, assignment ID, reports the current score, asks for a new score, and reports the change as confirmation.
    • See the sample run above for how override might work.
    • gradebook = loadGrades("gradebook.txt")
      override(gradebook)
      printGrades(gradebook)
      
      should print the updated gradebook.
  7. Write (and call) a main function to put all this together.
    • See the sample run above.

Notes and hints

Suggested order of development

The following general strategy should work for almost every project that you encounter.

Start early, have fun, and discuss questions on Moodle.