# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/sreneee/OOP-58002/blob/main/OOP_2.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + [markdown] id="1HtAfOeRUw0c"
# Classes with Multiple Objects

# + colab={"base_uri": "https://localhost:8080/"} id="sdLfYw2xU7wv" outputId="93c414a4-a23d-4e9f-c602-fcab4f77c849"
class Birds:
  def __init__(self, bird_name):
    self.bird_name = bird_name
  
  def flying_birds(self):
    print(f"{self.bird_name} flies above clouds")

  def non_flying_birds(self):
    print(f"{self.bird_name} is the national bird of the Philippines")
  
vulture = Birds("Griffon Vulture")
crane = Birds("Common Crane")
emu = Birds("Emu")

vulture.flying_birds()
crane.flying_birds()
emu.non_flying_birds()


# + [markdown] id="dxBvjOgTXKrB"
# Encapsulation 

# + colab={"base_uri": "https://localhost:8080/"} id="PvalStpcXM-y" outputId="5d6bc264-ddf7-4d13-c165-1edc089d0b68"
class foo:
  def __init__(self, a , b):
    self.__a = a
    self.__b = b

  def add(self):
    return self.__a + self.__b
  def sub(self):
    return self.__a - self.__b
foo_object = foo(3,4)

print(foo_object.add()) #adding a and b
print(foo_object.sub()) #subtracting a and b

foo_object.__b = 5
foo_object.__a = 7

print(foo_object.add())
print(foo_object.sub())


# + [markdown] id="4qUfPbAGdcRS"
# Inheritance

# + colab={"base_uri": "https://localhost:8080/"} id="Q606wV01df1c" outputId="1d425254-d1ab-4095-ec56-b265d97f4e9a"
class Person:
  def __init__(self,firstname, surname):
    self.firstname = firstname
    self.surname = surname
  
  def printname(self):
    print(self.firstname, self.surname)

person = Person("Ashley", "Goce")
person.printname()

class Student(Person):
  pass

person = Student("Denise", "Goce")
person.printname()


# + [markdown] id="B5jcD9gcgax5"
# Polymorphism

# + colab={"base_uri": "https://localhost:8080/"} id="Yd1p7ps6gcgj" outputId="5f34030f-76d6-4920-86cc-228fd651931d"
class RegularPolygon:
  def __init__(self,side):
    self.side = side
class Square(RegularPolygon):
  def area(self):
    return self.side*self.side
class EquillateralTriangle(RegularPolygon):
  def area(self):
    return self.side*self.side*0.433

x = Square(4)
y = EquillateralTriangle(3)

print(x.area())
print(y.area())
    

# + [markdown] id="_kiHfkWXjVGu"
# Application 1

# + id="dgHFWNXjjWk1" outputId="02388092-bc2b-4c18-d205-e7e1178cc36c" colab={"base_uri": "https://localhost:8080/"}
class Person:
  def __init__(self,std1,pre,mid,fin):
    self.std1 = std1
    self.pre = pre
    self.mid = mid
    self.fin = fin

  def Grade(self):
    print(self.std1)
    print(self.pre)
    print(self.mid)
    print(self.fin)

s1 =Person("Student 1",'Prelim: 90','Midterm: 87','Finals: 94\n')
s1.Grade()

avg =(90+87+94)/3
print('Average grade is: ' + str(avg)+'\n')

def __init__(self,std2,pre,mid,fin):
  self.std2 = std2
  self.pre = pre
  self.mid = mid
  self.fin = fin

def Grade(self):
  print(self.std2)
  print(self.pre)
  print(self.mid)
  print(self.fin)

s2 =Person("Student 2",'Prelim: 77','Midterm: 83','Finals: 89\n')
s2.Grade()

avg =(77+83+89)/3
print('Average grade is: ' + str(avg)+'\n')

def __init__(self,std3,pre,mid,fin):
  self.std3 = std3
  self.pre = pre
  self.mid = mid
  self.fin = fin

def Grade(self):
  print(self.std3)
  print(self.pre)
  print(self.mid)
  print(self.fin)

s3 =Person("Student 3",'Prelim: 93','Midterm: 97','Finals: 84\n')
s3.Grade()

avg =(93+97+84)/3
print('Average grade is: ' + str(avg)+'\n')


StarcoderdataJupyterScriptsDedupFiltered