Part 12

In this part you will implement a class. The first file you will create will be called student.py and will contain a class called Student. Class Student needs to keep track of the data for a single student and so should have attributes and methods as shown in the two tables below.

You can create your own names for the attributes (those given will not work as they contain spaces). This will not cause a problem as the attributes are only used by methods in this file. You must use the names given in the table below for the methods as they will be used by code in another file.

Create a file called student.py which will contain the class description for Student. The Student class should contain:

  • the five attributes given in the first table below,
  • a constructor with the name and course as parameters,
  • the eleven methods given in the second table below.

Most of these methods are simple getters and setters so no design is required for this class.

Attribute / Type / Initial value
student name / single text value / Provided by a constructor parameter
course name / single text value / Provided by a constructor parameter
average mark / single numeric value / 0
grade / single text value / “none”
assignment scores / list of up to four numeric values / Empty list
Method / Parameters provided when called / Action
getName / returns the value of the student name attribute
getCourse / returns the value of the course name attribute
getAverage / returns the value of the average mark attribute
getGrade / returns the value of the grade attribute
getMarks / returns the value of the assessment scores attribute
setAverage / mark / Sets the value of the average attribute to the value of the parameter mark
setGrade / Grade / Sets the value of the grade attribute to the value of the parameter grade
setMarks / marks / Sets the value of the assignment marks attribute to the value of the parameter marks
addMark / score / Appends the value score to the assignment scores list then calls calculateAverage and determineGrade
calculateAverage / If any scores are saved for this student, calculates and returns the average mark. If no marks are saved for this student it returns 0.
determineGrade / Checks the value of the average attribute and uses this to assign a value to the grade attribute. Values are assigned according to the following:
average >=70, grade = “A”
average>=60, grade = “B+”
average>=50, grade=”B”
average>=40, grade=”C”
arerage < 40, grade=”F”

For this part you will submit the file student.py

Part 13

In this part you will design and implement a class. The next file you will create will be called module.py. It will import Student and contain the description for class Module. Class Module will contain one attribute which will be a list calledstudentList. Module will contain

  • The attribute studentList
  • A constructor that takes no additional parameters and simply initialises studentList to an empty list
  • the methods given in the table below

Method / Parameters provided when called / Action
addStudent / name, course / Creates a Student object using the values name and course then appends this new object to studentList
findStudent / name / Returns either the number of the position in studentList where the name was found or -1 if the name was not found
removeStudent / name / Removes from studentList the first object whose name attribute has the same value as the name parameter
getStudent / Pos / Returns the student object found at position pos in studentLIst
addScore / name, score / Adds the value of the attribute score to the assignment marks list for the student whose name matches the value of the parameter name
moduleAverage / Returns the average of the average marks for all the students in studentList
displayTable / Prints to the screen the data for all the students in studentList. It should first print headings in the order: name, course, average, grade, marks. Each line below that should contain the data for one student in the same order as the headings.
saveTable / filename / Saves all the data currently in student list to a file whose name is the value of the parameter filename. Each student should be on one line in the file and you should put a specific separator between each value, e.g. _ or # for example
loadTable / filename / Loads the data saved in the file whose name matches the value of the attribute filename and prints it to the screen using one line for each student. Note: it should not display the separators that you saved into the file so you should remove these.

For this part, You should submit a pseudocode design for each method and the file module.py

Part 14

In this part, you will design, implement and test a program. The main program should be in a file called main.py and will import module. It will not import student. This file first creates an object of type Module called students then provides the user interface and uses the facilities of Module to carry out the actions on this object. The interface should be a standard text interface as has been used in examples throughout the course

The interface should offer the user options until the user enters q when it should quit. If the user enters an invalid letter when asked for an option, it should tell the user their mistake and continue asking until they offer a valid entry. When a valid letter is entered, it should carry out the associated action. The table below summarises the expected behaviour.

Key to press / Name of option / Action
A / Add a student / Asks the user for a name and course then creates a student with these values and adds it to the list in students
R / Remove a student / Asks the user for a name then searches the list in students to find it. If the name is found, its object is deleted. If the name is not found a message is displayed saying so.
M / Add a mark for a student / Asks the user for the name of a student to add a mark to the searches the list in students for the name.
If the name is not found, it prints a message saying so.
If instead the name is found but there are already 4 marks stored for this student, it prints a message saying so.
If instead the name is found and it has less than four marks stored, the user is asked for a value to store.
While the value entered is not in the range 0 to 100, the user is repeatedly asked to enter a valid value until an in range value is entered. This mark is then added to the list of marks for the student
D / Display the list of students / Prints a line of headings then the data stored for each student
C / Calculate the overall average for the module / Calculates the average of the average marks stored for each student in the list in students and prints it to the screen with a suitable message explaining what is being displayed.
S / Save the current data to a file / Saves the data stored in students to the file students.txt
L / Load that data from a file and print it to the screen / Loads the data stored in students.txt and prints it to the screen after first printing a suitable set of headings. You are only required to print the data to the screen. You are not required to copy the values into the list in students.

If you wish to create a GUI, then you can but there are no additional marks for this. The GUI still needs to do the data validation in the table.

For this part you should submit, a design for the main program, test cases and test data with results and the file main.py.

1