首页 > > 详细

Lab 10 Practice with designing your own types with classes

 Lab 10

Objectives 
• Practice with designing your own types with classes
• Practice with creating and using instances of a class (objects)
Getting started 
1. Create a new file called lab10.py and open it in your Wing editor
2. Download student.py and the sample input files to the same directory as lab10.py
3. Add documentation for the methods within student.py where it is missing. (ie. type hints and 
docstring with purpose and examples)
4. Design the methods within student.py and functions within lab10.py according to 
specifications below.
Submission
1. Double check your file before submission to avoid a zero grade for your submission for issues 
described in the Grading section of this document:
a. Open and run lab10.py in your Wing editor using the green arrow. 
You should see no errors and no output. 
If there are errors, you must fix them before submitting. 
If there is output printed to the shell, find and remove any top-level print statements and/or 
top level function calls.
b. At the shell prompt in Wing (>>>) type the following: import student
At the shell prompt in Wing (>>>) type the following: import lab10
You should not see any output. If there are errors, you must fix them before submitting.
c. At the shell prompt in Wing (>>>), make calls to the required methods in student.py and 
functions in lab10.py to ensure you have named them correctly. Ensure the method/
function is exhibiting the expected behaviour when called and does not contain any 
unexpected output. You should be able to make calls to the following methods/functions 
with expected input (remember, to call the methods you must first create an instance of the 
Student class to call the method with):
i. is_grade_above
ii. get_students
iii. get_classlist
iv. count_above
v. get_average_grade
2. Upload your student.py and lab10.py containing the completed function designs
Reminder: Your code is to be designed and written by only you and not to be shared with anyone else. 
See the Course Outline for details explaining the policies on Academic Integrity. Submissions that 
violate the Academic Integrity policy will be forwarded directly to the Computer Science Academic 
Integrity Committee.
Grading…
• Late submissions will be given a zero grade. • The file you submit must be named lab10.py
The filenames must be EXACT for them to work with our grading scripts. Errors in the 
filenames will result in a zero grade. 
Example mistakes often made by students include but are not limited to: spelling errors, different 
case letters, space characters and incorrect extension (not using .py) 
• Your function names and the order of your function arguments must match EXACTLY as 
specified in this document or you will be given a zero grade. Use the example tests we give you 
to ensure your function header is correct.
• Your submission must not contain any print statements that are not required in the specification 
or any top-level calls to functions. This unexpected code can cause the automated tester to crash 
and will result in a zero grade. • We will do spot-check grading in this course. That is, all submissions are graded BUT only a 
subset of your code might be graded. You will not know which portions of the code will be 
graded, so all of your code must be complete and adhere to specifications to receive marks.
• Your code must run without errors with Python 3. If you tested your configuration with setup.py 
file this would have verified you are using Python 3. Code that generates errors cannot be tested 
and will be given a zero grade. 
Marks will be awarded for correctness, considering:
• the function signature matches the description given (has the name and arguments EXACTLY as 
specified)
• the function has the expected behaviour
and for code quality according to software engineering properties such as:
• documentation in docstring format: type hints, purpose, examples
• readability
o use of whitespace
o splitting complex computation or long statements across multiple lines 
• meaningful variable names o lower case, starting with an alpha-character
• proper use of constants (avoid magic numbers)
o defined above all function definitions
o in UPPERCASE
• use of code constructs (functions, variables, conditions) to: o eliminate redundant code and redundant computation
• testing coverage
o you have added an example in your docstring to cover each boundary case within your 
program
NOTE: examples given in the function specification do not necessarily cover all 
boundary case – often you will have to create additional examples.
o you have added an example to cover each boundary case within your program 
Method/Function Specifications
Within student.py: 
1. Design a method to compare equality of Student instances in student.py. When your 
implementation is complete, when an instance of a Student is compared to another Student
using == it should evaluate to True if the sid values of the two Student instances are the same and 
False otherwise. NOTE: the header must be exact for the overriding to work correctly. See lecture 
examples for help.
2. Design a method called is_grade_above that takes as arguments a self-reference to the Student 
instance (self) and an additional argument as a threshold grade. The method should determine 
whether the grade of self is above the given threshold grade.
Within lab10.py: 
1. Add the necessary imports to your file for testing, type hints and for you student class
2. Design a function called get_students that takes a name of a file and creates and returns a new 
list of Students from data in filename where each line of file has a student id and grade separated by 
a comma. If the file is empty the function should return an empty list.
3. Design a function called get_classlist that takes a list of Student instances and creates and 
returns a new list of just the student ids of all Student instances in the list.
4. Design a function called count_above that takes a list of Student instances and an additional 
argument as a threshold grade. The function should return a count of the number of Student 
instances in the list that have a grade above the given threshold grade.
5. Design a function called get_average_grade that takes a list of Student instances. The 
function should calculate and return the average grade of all Student instances in the list as a floating 
point number. Your function should assume that the list is not empty.
联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!