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:
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())
Task – 8
Implement the design of the FootBallTeam and the CricketTeam classes that inherit
from Team class so that the following code generates the output below:
f = FootBallTeam("Brazil")
c = CricketTeam("Bangladesh")
test = Team_test()
test.check(f)
test.check(c)
Task – 9
Implement the design of the Pikachu and Charmander classes that are derived from
the Pokemon class so that the following output is produced:
pk1 = Pikachu()
print("Pokemon:", pk1.pokemon)
print("Type:", pk1.kind())
print("Weakness:", pk1.weakness())
pk1.what_am_i()
print("========================")
c1 = Charmander()
print("Pokemon:", c1.pokemon)
print("Type:", c1.kind())
print("Weakness:", c1.weakness())
c1.what_am_i()
Task – 10
Implement the design of the CSE and EEE classes that are derived from the Department
class so that the following output is produced:
1 class A:
2 def __init__(self):
3 self.temp = 4
4 self.sum = 1
5 self.y = 2
6 self.y = self.temp - 2
7 self.sum = self.temp + 3
8 self.temp -= 2
9 def methodA(self, m, n):
10 x = 0
11 self.y = self.y + m + self.temp
12 self.temp += 1
13 x = x + 2 + n
14 self.sum = self.sum + x + self.y
15 print(x, self.y, self.sum)
16
17 class B(A):
18 def __init__(self, b=None):
19 super().__init__()
20 self.x = 1
21 self.sum = 2
22 if b == None:
23 self.y = self.temp + 3
24 self.sum = 3 + self.temp + 2
25 self.temp -= 1
26 else:
27 self.sum = b.sum
28 self.x = b.x
29 def methodB(self, m, n):
30 y = 0
31 y = y + self.y
32 self.x = y + 2 + self.temp
33 self.methodA(self.x, y)
34 self.sum = self.x + y + self.sum
35 print(self.x, y, self.sum)
Write the output of the following code:
a1 = A() Output:
b1 = B() x y sum
b2 = B(b1)
a1.methodA(1, 1)
b1.methodA(1, 2)
b2.methodB(3, 2)
Task – 12
1 class A:
2 temp = 4
3 def __init__(self):
4 self.sum = 0
5 self.y = 0
6 self.y = A.temp - 2
7 self.sum = A.temp + 1
8 A.temp -= 2
9 def methodA(self, m, n):
10 x = 0
11 self.y = self.y + m + (A.temp)
12 A.temp += 1
13 x = x + 1 + n
14 self.sum = self.sum + x + self.y
15 print(x, self.y, self.sum)
16
17 class B(A):
18 x = 0
19 def __init__(self,b=None):
20 super().__init__()
21 self.sum = 0
22 if b==None:
23 self.y = A.temp + 3
24 self.sum = 3 + A.temp + 2
25 A.temp -= 2
26 else:
27 self.sum = b.sum
28 B.x = b.x
29 b.methodB(2, 3)
30 def methodB(self, m, n):
31 y = 0
32 y = y + self.y
33 B.x = self.y + 2 + A.temp
34 self.methodA(B.x, y)
35 self.sum = B.x + y + self.sum
36 print(B.x, y, self.sum)
Write the output of the following code:
a1 = A() Output:
b1 = B() x y sum
b2 = B(b1)
b1.methodA(1, 2)
b2.methodB(3, 2)
Task – 13
1 class A:
2 temp = 3
3 def __init__(self):
4 self.sum = 0
5 self.y = 0
6 self.y = A.temp - 1
7 self.sum = A.temp + 2
8 A.temp -= 2
9
10 def methodA(self, m, n):
11 x = 0
12 n[0] += 1
13 self.y = self.y + m + A.temp
14 A.temp += 1
15 x = x + 2 + n[0]
16 n[0] = self.sum + 2
17 print(f"{x} {self.y} {self.sum}")
18
19 class B(A):
20 x = 1
21 def __init__(self, b = None):
22 super().__init__()
23 self.sum = 2
24 if b == None:
25 self.y = self.temp + 1
26 B.x = 3 + A.temp + self.x
27 A.temp -= 2
28 else:
29 self.sum = self.sum + self.sum
30 B.x = b.x + self.x
31 def methodB(self, m, n):
32 y = [0]
33 self.y = y[0] + self.y + m
34 B.x = self.y + 2 + self.temp - n
35 self.methodA(self.x, y)
36 self.sum = self.x + y[0] + self.sum
37 print(f"{self.x} {y[0]} {self.sum}")
Write the output of the following code:
x = [23] Output:
a1 = A() x y sum
b1 = B()
b2 = B(b1)
a1.methodA(1, x)
b2.methodB(3, 2)
a1.methodA(1, x)
Task – 14
1 class A:
2 temp = 7
3 def __init__(self):
4 self.sum, self.y = 0, 0
5 self.y = A.temp - 1
6 self.sum = A.temp + 2
7 A.temp -= 3
8 def methodA(self, m, n):
9 x = 4
10 n[0] += 1
11 self.y = self.y + m + A.temp
12 A.temp += 2
13 x = x + 3 + n[0]
14 n[0] = self.sum + 2
15 print(f"{x} {self.y} {self.sum}")
16 def get_A_sum(self):
17 return self.sum
18 def update_A_y(self, val):
19 self.y = val
20 class B(A):
21 x = 2
22 def __init__(self, b = None):
23 super().__init__()
24 self.sum = 2
25 if b == None:
26 self.y = self.temp + 1
27 B.x = 4 + A.temp + self.x
28 A.temp -= 2
29 else:
30 self.sum = self.sum + self.get_A_sum()
31 B.x = b.x + self.x
32 def methodB(self, m, n):
33 y = [0]
34 self.update_A_y(y[0] + self.y + m)
35 B.x = self.y + 4 + self.temp - n
36 self.methodA(self.x, y)
37 self.sum = self.x + y[0] + self.get_A_sum()
38 print(f"{self.x} {y[0]} {self.sum}")
Write the output of the following code:
x = [32] Output:
a1 = A() x y sum
b1 = B()
b2 = B(b1)
a1.methodA(2, x)
b2.methodB(2, 3)
a1.methodA(3, x)