.py
files containing your work.This homework assignment must be submitted in Gradescope by Noon central time on Tuesday 31 January 2023.
Collaboration is prohibited, and you may only access resources (books, online, etc.) listed below.
This assignment is about object-oriented programming, based on worksheets 1-3 and lectures 1-4. It focuses on the material of worksheet 3.
The course materials you may refer to for this homework are:
This homework assignment has 2 problems, numbered 2 and 3. The grading breakdown is:
Points | Item |
---|---|
3 | Autograder |
6 | Problem 2 |
6 | Problem 3 |
15 | Total |
The part marked "autograder" reflects points assigned to your submission based on some simple automated checks for Python syntax, etc. The result of these checks is shown immediately after you submit.
Ask your instructor or TA a question by email, in office hours, or on discord.
In Gradescope, the score assigned to your homework submission by the autograder (checking for syntax and docstrings) will be recorded as "Problem 1". Therefore, the numbering of the actual problems begins with 2.
This will happen on every assignment this semester. Starting on the next homework, I won't comment on this practice in the homework, and will just omit problem 1.
Put the work you do for this problem in a file hwk3prob2.py
.
Make a Python class UniversalMimic
whose constructor takes no arguments (e.g. you can make one with UniversalMimic()
). Use operator overloading to make it so that any instance of this class thinks it is equal to every other object. For example:
U = UniversalMimic()
1 == U
U == 0
U == None
U == "a slice of apple pie"
U == 2.75
U == { "course": "MCS 275", "meeting time": "12:00pm", "enrollment_max": 28 }
Note that in an expression like A == UniversalMimic()
, it's possible that A
might have its own __eq__
method that returns False
, and since Python checks with the left object first, you can't avoid this test returning False
. Don't worry about that. Just make your best effort to ensure all equality comparisons this class controls will return True
.
Remark: This is a contrived test of overloading, and not something you should do in actual code.
Put the work you do for this problem in a file hwk3prob3.py
.
In lecture 4, we built a module plane.py
that represents
Point2
class, andVector2
classTake that module and modify it (renaming it to hwk3prob3.py
) so that it instead contains these two classes:
Point3
representing three-dimensional points $(x,y,z)$ andVector3
representing three-dimensional vectors $\langle x,y,z \rangle$.Mostly this will involve small changes to account for the third coordinate/component.
But also add one new method to Vector3
:
def cross(self,other):
: Returns the vector cross product $(\mathrm{self}) \times (\mathrm{other})$. Thus if v
and w
are Vector3
objects, you can compute the cross product (which is another Vector3
) as v.cross(w)
.Also take care to update __abs__
so it knows the right way to compute length in 3 dimensions.
No prerequisite course of MCS 275 has 3-dimensional geometry in its required topic list, so here are the things you need to know in this problem:
If anything about the geometric side of this question is unclear, please ask! We mean for it to be a question about translating those ideas into code.