You are on page 1of 8

Object Oriented programming

Lab Report

Fall 2022

Python Codes

Submitted by: Muneeza Rehman


Registration No.: 21PWCSE2019
Class Section: C

 “On my honor, as student of University of Engineering and Technology, I have neither given
nor received unauthorized assistance on this academic work.”

Submitted to: 
Sumayyea Salahuddin
(December 22, 2022)

Department of Computer Systems Engineering


University of Engineering and Technology, Peshawar
ACTIVITY 1.3.9

In this activity we implement a basic syntax structure for classes. The program does not run properly on
terminal but this is for practicing of Class syntax in python

ACTIVITY 2.3.6
 In this example we make class with a non-parametrized constructor and a parameterized
constructor.
 Then we make a set value function and a show function inside the class
 All of the functions have common argument self with r ,I in parameterized constructor and rr , ii
in the setvalue function
 Python does not requires a main function so we make obj1 and obj2 .Obj1 is directly passed
value and Obj2 is passed value by setvalue function
ACTIVITY 4.3.10
 In this example, we have functions of addCom and negate. The addCom can add complex
numbers. The negate function changes the sign of real and imaginary parts of the complex
number then we have the show function and two constructors one parameterized and one non
parameterized.
 The things to take care of are the constructors do not use the class name instead they use
__init_ and all the functions of class one argument self always

ACTIVITY 5.3.7

 This activity focuses on the copy constructors which are deep and shallow copy constructors. In
Python first we need to import the library copy to use copy constructors.
 The deep copy mechanism of Python is very different from C++ which is that in python we make
object and then we assign whether we are going to use shallow copy by copy.copy() or deep
copyby copy.deepcopy()
 The destructor is used by syntax __del__ this is different to C++ where we use ~ with class name.
 The destructor also takes an argument self and also we need to delete objects s1 , s2 ,s3 by
using del s1 , s2 , s3.
ACTIVITY 8.3.8
In this activity we use operator overloading .The unique thing about this program is that if you want to
invert complex number we use the ~ with object as in line 38 of the program as illustrated in image .

You might also like