CSE111 Lab Assignment 8
CSE111 Lab Assignment 8
Write the ComplexNumber class so that the following code generates the output
below.
cn1 = ComplexNumber()
print(cn1)
print('---------')
cn2 = ComplexNumber(5,7)
print(cn2)
Task - 2
Write the ComplexNumber class so that the following code generates the output
below.
r1 = RealNumber(3)
r2 = RealNumber(5)
print(r1+r2)
cn1 = ComplexNumber(2, 1)
print(cn1)
cn2 = ComplexNumber(r1, 5)
print(cn2)
cn3 = cn1 + cn2
print(cn3)
cn4 = cn1 - cn2
print(cn4)
Task - 3
Write the CheckingAccount class so that the following code generates the output
below:
def hasFormalin(self):
return self.__formalin
class testFruit:
def test(self, f):
print('----Printing Detail----')
if f.hasFormalin():
print('Do not eat the',f.getName(),'.')
print(f)
else:
print('Eat the',f.getName(),'.')
print(f)
m = Mango()
j = Jackfruit()
t1 = testFruit()
t1.test(m)
t1.test(j)
Task - 5
Write the ScienceExam class so that the following code generates the output below:
Given the following class, write the code for the Sphere and the Cylinder class so that
the following output is printed.
sph = Sphere('Sphere', 5)
print('----------------------------------')
sph.calc_surface_area()
print(sph)
print('==================================')
cyl = Cylinder('Cylinder', 5, 10)
print('----------------------------------')
cyl.calc_surface_area()
print(cyl)
Task - 7
Write the PokemonExtra class so that the following code generates the output below:
------------Pokemon 2 Info:--------------
def get_move(self):
Name: Charizard, HP: 78, Weakness: Water
return 'Basic move: ' + 'Quick Attack'
Main type: Fire, Secondary type: Flying
Basic move: Quick Attack
def __str__(self): Other move: Fire Spin, Fire Blaze
return "Name: " + self.name + ", HP: " +
str(self.hit_point) + ", Weakness: " + self.weakness
print('\n------------Basic Info:--------------')
pk = PokemonBasic()
print(pk)
print(pk.get_type())
print(pk.get_move())
print('\n------------Pokemon 1 Info:-------------')
charmander = PokemonExtra('Charmander', 39, 'Water',
'Fire')
print(charmander)
print(charmander.get_type())
print(charmander.get_move())
print('\n------------Pokemon 2 Info:-------------')
charizard = PokemonExtra('Charizard', 78, 'Water',
'Fire', 'Flying', ('Fire Spin', 'Fire Blaze'))
print(charizard)
print(charizard.get_type())
print(charizard.get_move())