Lab Prelim3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Navarro, Jules Rhenz February 17, 2022

1-CPE-A Object-Oriented Programming

1. Source Code:

class Room:
def __init__(self, roomNo, roomType, roomArea):
self.roomno = roomNo
self.roomtype = roomType
self.roomarea = roomArea
def __int__(self):
return int(self.roomno)
def __str__(self):
return str(self.roomtype)
def __float__(self):
return float(self.rooamarea)
class setData:
def __init__(self, roomNo, roomType, roomArea, ACmachine):
self.acmachine = ACmachine
Room.__init__(self, roomNo, roomType, roomArea)
def __bool__(self):
return bool(self.acmachine)
def displayData(self):
print("The room no. is: ",self.roomno)
print("\nThe room type is: ",self.roomtype)
print("\nThe room area is: ",self.roomarea)
print("\nis the AC machine needed? ",self.acmachine)

sample = setData("69","Single Room","420.00","Yes")


sample.displayData()

Screenshot of the working output:


2. Source Code:

class SimpleObject:
def __init__(self, object):
self.Object = object

def displayObject(self):
print(“The simple object that describes you is: “, self.Object)

object = “ A book because you cannot be judge only by your outside appearance”

o1 = simpleObject(object)
o1.displayObject()

Screenshot of the working output:

3. Source Code:

class ValueReference:
def CallByValue(name):
print()
name = "John"
print("Inside Content: ", name)

print("Called By Value")
name = "Jules"
CallByValue(name)
print("Inside Content: ", name)
print()

def CallByReference(cars):
cars[0] = "Porsche"
print("Inside Content: ", cars)

print("Called By Reference")
cars = ["Honda","Ford","Lamborghini"]
print()
CallByReference(cars)
print("Outside Content: ",cars)

Screenshot of the working output:

4. Source Code:

class square:
def __init__(this,sides):
this.sides = sides

def AreaOfSquare(this):
area = (this.sides*this.sides)*1
print("Side lenght: ",this.sides,"m")
print()
print("The area of a square that has a side lenght"
,this.sides,"is {} m^2".format(area))
print()

print("The computed area of the square using the class\n")


lenght = 3
sq1 = square(lenght)
sq1.AreaOfSquare()
Screenshot of the working output:

You might also like