联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp2

您当前位置:首页 >> Python编程Python编程

日期:2020-07-24 11:33

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 the provided starter files: student.py and sample input files provided 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. Upload student.py and lab10.py files in CourseSpaces before the deadline.

Grading…

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

? a zero grade will be given for programs with incorrect filenames

? a zero grade will be given for programs who have errors or cannot run with Python 3

and for quality according to software engineering properties such as:

? program structure

o import statements are at the top of the file

o constants defined after import statements with CAPITAL LETTERS

o no test calls are left within the file (it only contains your function definitions)

? documentation

o type hints

o purpose

o examples

? meaningful variable names

? proper use of constants

? use of code constructs (functions, variables, condition statements) to

o eliminate redundant code and redundant computation

o make complex code easier to read

? testing coverage

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 does not exist or 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 and an

additional argument as a threshold grade. 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.


版权所有:编程辅导网 2018 All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。