Course Title: Programming Language II Course Code: CSE 111 Lab Assignment No: 3 & 4 Merged
Course Title: Programming Language II Course Code: CSE 111 Lab Assignment No: 3 & 4 Merged
[For BMI, the formula is BMI = weight/height^2, where weight is in kg and height in
meters]
Design the Programmer class in such a way so that the following code provides the
expected output.
Hint:
o Write the constructor with appropriate printing and multiple arguments.
o Write the addExp() method with appropriate printing and argument.
o Write the printDetails() method
[For simplicity, you can assume that a customer will always order exact 2 items]
Write a class called Customer with the required constructor and methods to get the
following output.
Subtasks:
1. Create a class called Customer.
2. Create the required constructor.
3. Create a method called greet that works if no arguments are passed or if one
argument is passed. (Hint: You may need to use the keyword NONE)
4. Create a method called purchase that can take as many arguments as the user
wants to give.
Design the Student class such a way so that the following code provides the expected
output.
Hint:
● Write the constructor with appropriate default value for arguments.
● Write the dailyEffort() method with appropriate arguments.
● Write the printDetails() method. For printing suggestions check the following
instructions.
⮚ If hour <= 2 print 'Suggestion: Should give more effort!'
⮚ If hour <= 4 print 'Suggestion: Keep up the good work!'
⮚ Else print 'Suggestion: Excellent! Now motivate others.'
Task 11
Using TaxiLagbe apps, users can share a single taxi with multiple people.
Implement the design of the TaxiLagbe class so that the following output is produced:
Hint:
1. Each taxi can carry maximum 4 passengers
2. addPassenger() method takes the last name of the passenger and ticket fare for that
person in an underscore (-) separated string.
Task 13
Implement the design of the StudentDatabase class so that the following output is
produced:
t5 = Test5()
t5.methodA()
Task 16
1 class FinalT6A:
2 def __init__(self, x, p):
3 self.temp, self.sum, self.y = 4, 0, 1
4 self.temp += 1
5 self.y = self.temp - p
6 self.sum = self.temp + x
7 print(x, self.y, self.sum)
8 def methodA(self):
9 x = 0
10 y = 0
11 y = y + self.y
12 x = self.y + 2 + self.temp
13 self.sum = x + y + self.methodB(self.temp, y)
14 print(x, y, self.sum)
15 def methodB(self, temp, n):
16 x = 0
17 temp += 1
18 self.y = self.y + temp
19 x = x + 3 + n
20 self.sum = self.sum + x + self.y
21 print(x, self.y, self.sum)
22 return self.sum
q1 = FinalT6A(2,1)
q1.methodA()
q1.methodA()
Task 17
1 class Test5:
2 def __init__(self):
3 self.sum = 0
4 self.y = 0
5 def methodA(self):
6 x=y=k=0
7 msg = [5]
8 while (k < 2):
9 y += msg[0]
10 x = y + self.methodB(msg, k)
11 self.sum = x + y + msg[0]
12 print(x ," " , y, " " , self.sum)
13 k+=1
14 def methodB(self, mg2, mg1):
15 x = 0
16 self.y += mg2[0]
17 x = x + 3 + mg1
18 self.sum += x + self.y
19 mg2[0] = self.y + mg1
20 mg1 += x + 2
21 print(x , " " ,self.y, " " , self.sum)
22 return mg1
t1 = Test5()
t1.methodA()
t1.methodA()
t1.methodA()
Task 18
1 class Test4:
2 def __init__(self):
3 self.sum, self.y = 0, 0
4 def methodA(self):
5 x, y = 0, 0
6 msg = [0]
7 msg[0] = 5
8 y = y + self.methodB(msg[0])
9 x = y + self.methodB(msg, msg[0])
10 self.sum = x + y + msg[0]
11 print(x, y, self.sum)
12 def methodB(self, *args):
13 if len(args) == 1:
14 mg1 = args[0]
15 x, y = 0, 0
16 y = y + mg1
17 x = x + 33 + mg1
18 self.sum = self.sum + x + y
19 self.y = mg1 + x + 2
20 print(x, y, self.sum)
21 return y
22 else:
23 mg2, mg1 = args
24 x = 0
25 self.y = self.y + mg2[0]
26 x = x + 33 + mg1
27 self.sum = self.sum + x + self.y
28 mg2[0] = self.y + mg1
29 mg1 = mg1 + x + 2
30 print(x, self.y, self.sum)
31 return self.sum
t3 = Test4() x y sum
t3.methodA()
t3.methodA()
t3.methodA()
t3.methodA()
Task 19
1 class msgClass:
2 def __init__(self):
3 self.content = 0
4 class Q5:
5 def __init__(self):
6 self.sum = 1
7 self.x = 2
8 self.y = 3
9 def methodA(self):
10 x, y = 1, 1
11 msg = []
12 myMsg = msgClass()
13 myMsg.content = self.x
14 msg.append(myMsg)
15 msg[0].content = self.y + myMsg.content
16 self.y = self.y + self.methodB(msg[0])##
17 y = self.methodB(msg[0]) + self.y
18 x = y + self.methodB(msg[0], msg)
19 self.sum = x + y + msg[0].content
20 print(x," ", y," ", self.sum)
21 def methodB(self, mg1, mg2 = None):
22 if mg2 == None:
23 x, y = 5, 6
24 y = self.sum + mg1.content
25 self.y = y + mg1.content
26 x = self.x + 7 +mg1.content
27 self.sum = self.sum + x + y
28 self.x = mg1.content + x +8
29 print(x, " ", y," ", self.sum)
30 return y
31 else:
32 x = 1
33 self.y += mg2[0].content
34 mg2[0].content = self.y + mg1.content
35 x = x + 4 + mg1.content
36 self.sum += x + self.y
37 mg1.content = self.sum - mg2[0].content
38 print(self.x, " ",self.y," ", self.sum)
39 return self.sum
q = Q5()
q.methodA()
Practice Task (20 - 25) Ungraded
Task 20
Design a Student class so that the following output is produced upon executing the
following code
Design a Student class so that the following output is produced upon executing the
following code:
[Hint: Each course has 3.0 credit hours. You must take at least 9.0 and at most 12.0
credit hours]
Write the Hotel class with the required methods to give the following output as shown.
Write the Author class with the required methods to give the following outputs as
shown.
Design the Vaccine and Person class so that the following expected output is
generated.
[N.B: Students will get vaccines on a priority basis. So, age for students doesn’t matter]