cpsc111-Su16-Lab5.docx - CPSC111 Introduction to Computing...

This preview shows page 1 - 2 out of 3 pages.

CPSC111 - Introduction to ComputingSummer 2016Lab5 – Practice with Classes & Objects in PythonNO SUBMISSION FOR TODAY’S LAB BUTMAKE SURE YOU CHECK OUT BEFORE YOU LEAVETO GET YOURLAB SCORE!Today's lab exercises provide practice with classes and objects, the main components of Object Oriented Programming (OOP). You will work with a partner on this Lab5. Two students should work at a single computer. Occasionally switch the student who is typing. Talk to each other about what you are doing and why so that both of you understand each step; very important for preparing for final exam. Part A: Class Point1. Examine the Python program below and predict the values which will be displayed.class Point : :#used to create objects of type ‘Point’def __init__(self, a, b) : #initialize the created object of type Pointself.x = aself.y = bdef __add__(self, other) : # used to add two objects of type Pointnew_x = self.x + other.xnew_y = self.y + other.yreturn Point(new_x, new_y)def __rmul__(self, number) : #(Point * number) => r stands for right

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture