[go: up one dir, main page]

0% found this document useful (0 votes)
105 views27 pages

Course Title: Programming Language II Course Code: CSE 111 Lab Assignment No: 3 & 4 Merged

The document contains instructions for 7 programming tasks involving object-oriented concepts like classes, objects, methods, and constructors in Python. The tasks involve designing classes for patients, shapes, calculators, programmers, food delivery orders, customers, and cats to produce the given sample outputs. The document provides hints and driver code for each task without revealing the actual implementation required. Students need to define the necessary classes, methods, constructors and instance variables to achieve the expected behavior.

Uploaded by

Ahnaf Chowdhury
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views27 pages

Course Title: Programming Language II Course Code: CSE 111 Lab Assignment No: 3 & 4 Merged

The document contains instructions for 7 programming tasks involving object-oriented concepts like classes, objects, methods, and constructors in Python. The tasks involve designing classes for patients, shapes, calculators, programmers, food delivery orders, customers, and cats to produce the given sample outputs. The document provides hints and driver code for each task without revealing the actual implementation required. Students need to define the necessary classes, methods, constructors and instance variables to achieve the expected behavior.

Uploaded by

Ahnaf Chowdhury
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Course Title: Programming Language II

Course Code: CSE 111


Lab Assignment no: 3 & 4 Merged
Task 1
Implement the design of the Patient class so that the following output is produced:

[For BMI, the formula is BMI = weight/height^2, where weight is in kg and height in
meters]

Driver Code Output


# Write your code here Name: A
Age: 55
p1 = Patient("A", 55, 63.0, 158.0)
Weight: 63.0 kg
p1.printDetails()
Height: 158.0 cm
print("====================")
BMI: 25.236340330075304
p2 = Patient("B", 53, 61.0, 149.0)
====================
p2.printDetails()
Name: B
Age: 53
Weight: 61.0 kg
Height: 149.0 cm
BMI: 27.476239809017613 
Task 2

Design a class Shape for the given code below.


• Write a class Shape.
• Write the required constructor that takes 3 parameters and initialize the instance
variables accordingly.
• Write a method area() that prints the area.
Hint: the area method can calculate only for the shapes: Triangle, Rectangle, Rhombus,
and Square. So, you have to use conditions inside this method
For this task, assume that --
● for a triangle, the arguments passed are the base and height
● for a rhombus, the arguments passed are the diagonals
● for a square or rectangle, the arguments passed are the sides.

Driver Code Output


# Write your code here Area: 125.0
==========================
triangle = Shape("Triangle",10,25) Area: 100
==========================
triangle.area()
Area: 225.0
print("==========================") ==========================
Area: 450
square = Shape("Square",10,10)
==========================
square.area() Area: Shape unknown 
print("==========================")
rhombus = Shape("Rhombus",18,25)
rhombus.area()
print("==========================")
rectangle = Shape("Rectangle",15,30)
rectangle.area()
print("==========================")
trapezium = Shape("Trapezium",15,30)
trapezium.area()
Task 3
Implement the design of the Calculator class so that the following output is produced:

Driver Code Output


# Write your code here Calculator is ready!
==================
c1 = Calculator() Returned value: 30
10 + 20 = 30
print("==================")
==================
val = c1.calculate(10, 20, '+') Returned value: 20
30 - 10 = 20
print("Returned value:", val)
==================
c1.showCalculation() Returned value: 100
20 * 5 = 100
print("==================")
==================
val = c1.calculate(val, 10, '-') Returned value: 6.25
100 / 16 = 6.25
print("Returned value:", val)
c1.showCalculation()
print("==================")
val = c1.calculate(val, 5, '*')
print("Returned value:", val)
c1.showCalculation()
print("==================")
val = c1.calculate(val, 16, '/')
print("Returned value:", val)
c1.showCalculation()
Task 4

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

[You are not allowed to change the code below]

# Write your code here. OUTPUT:


p1 = Programmer("Ethen Hunt", "Java", 10) Horray! A new programmer is born
Name: Ethen Hunt
p1.printDetails()
Language: Java
print('--------------------------') Experience: 10 years.
p2 = Programmer("James Bond", "C++", 7) --------------------------
Horray! A new programmer is born
p2.printDetails() Name: James Bond
print('--------------------------') Language: C++
Experience: 7 years.
p3 = Programmer("Jon Snow", "Python", 4) --------------------------
p3.printDetails() Horray! A new programmer is born
Name: Jon Snow
p3.addExp(5)
Language: Python
p3.printDetails() Experience: 4 years.
Updating experience of Jon Snow
Name: Jon Snow
Language: Python
Experience: 9 years.
Task 5
Implement the design of the UberEats class so that the following output is produced:

[For simplicity, you can assume that a customer will always order exact 2 items]

Driver Code Output


# Write your code here Shakib, welcome to UberEats!
=========================
order1 = UberEats("Shakib", "01719658xxx", "Mohakhali") =========================
User details: Name: Shakib, Phone:
print("=========================")
01719658xxx, Address: Mohakhali
order1.add_items("Burger", "Coca Cola", 220, 50) Orders: {'Burger': 220, 'Coca Cola': 50}
Total Paid Amount: 270
print("=========================")
=========================
print(order1.print_order_detail()) Siam, welcome to UberEats!
=========================
print("=========================")
=========================
order2 = UberEats ("Siam", "01719659xxx", "Uttara") User details: Name: Siam, Phone:
01719659xxx, Address: Uttara
print("=========================")
Orders: {'Pineapple': 80, 'Dairy Milk': 70}
order2.add_items("Pineapple", "Dairy Milk", 80, 70) Total Paid Amount: 150
print("=========================")
print(order2.print_order_detail())
Task 6

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.

[You are not allowed to change the code below]

# Write your codes for subtasks 1-4 here. OUTPUT:


Hello! 
customer_1 = Customer("Sam") Sam, you purchased 3 item(s): 
customer_1.greet() chips
customer_1.purchase("chips", "chocolate", "orange juice") chocolate
print("-----------------------------") orange juice
customer_2 = Customer("David") -----------------------------
customer_2.greet("David") Hello David!
customer_2.purchase("orange juice") David, you purchased 1 item(s): 
orange juice
Task 7
Analyze the given code below to write Cat class to get the output as shown.
Hints:
● Remember, the constructor is a special method. Here, you have to deal with
constructor overloading which is similar to method overloading.
● You may need to use the keyword None
● Your class should have 2 variables
[You are not allowed to change the code below]

#Write your code here OUTPUT


  White cat is sitting
c1 = Cat()
Black cat is sitting
c2 = Cat("Black")
Brown cat is jumping
c3 = Cat("Brown", "jumping")
Red cat is purring
c4 = Cat("Red", "purring")
Blue cat is sitting
c1.printCat()
Purple cat is jumping
c2.printCat()
c3.printCat()
c4.printCat()
c1.changeColor("Blue")
c3.changeColor("Purple")
c1.printCat()
c3.printCat()
Task 8

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.'

[You are not allowed to change the code below]

# Write your code here. OUTPUT:


harry = Student('Harry Potter', 123) Name: Harry Potter
harry.dailyEffort(3) ID: 123
harry.printDetails() Department: CSE
print('========================') Daily Effort: 3 hour(s)
john = Student("John Wick", 456, "BBA") Suggestion: Keep up the good work!
john.dailyEffort(2) ========================
john.printDetails() Name: John Wick
print('========================') ID: 456
naruto = Student("Naruto Uzumaki", 777, "Ninja") Department: BBA
naruto.dailyEffort(6) Daily Effort: 2 hour(s)
naruto.printDetails() Suggestion: Should give more effort!
========================
Name: Naruto Uzumaki
ID: 777
Department: Ninja
Daily Effort: 6 hour(s)
Suggestion: Excellent! Now motivate others.
Task 9
Implement the design of the Batsman class so that the following output is produced:

Hint: Batting strike rate (s/r) = runsScored / ballsFaced x 100.

Driver Code Output

# Write your code here Name: New Batsman


b1 = Batsman(6101, 7380) Runs Scored: 6101 , Balls Faced: 7380
b1.printCareerStatistics() ============================
print("============================") Name: Liton Das
b2 = Batsman("Liton Das", 678, 773) Runs Scored: 678 , Balls Faced: 773
b2.printCareerStatistics() ----------------------------
print("----------------------------") 87.71021992238033
print(b2.battingStrikeRate()) ============================
print("============================") Name: Shakib Al Hasan
b1.setName("Shakib Al Hasan") Runs Scored: 6101 , Balls Faced: 7380
b1.printCareerStatistics() ----------------------------
print("----------------------------") 82.66937669376694
print(b1.battingStrikeRate())
Task 10
Implement the design of the Author class so that the following output is produced:

Driver Code Output


# Write your code here Author Name: Humayun
Ahmed
auth1 = Author('Humayun Ahmed') --------
List of Books:
auth1.addBooks('Deyal', 'Megher Opor Bari')
Deyal
auth1.printDetails() Megher Opor Bari
===================
print("===================")
Default
auth2 = Author() ===================
Author Name: Mario Puzo
print(auth2.name) --------
auth2.changeName('Mario Puzo') List of Books:
The Godfather
auth2.addBooks('The Godfather', 'Omerta', 'The Sicilian') Omerta
print("===================") The Sicilian
===================
auth2.printDetails() Author Name: Paolo Coelho
print("===================") --------
List of Books:
auth3 = Author('Paolo Coelho', 'The Alchemist', 'The Fifth Mountain') The Alchemist
auth3.printDetails() The Fifth Mountain

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.

Driver Code Output


# Write your code here --------------------------------------
# Do not change the following lines of code. Dear Walker! Welcome to TaxiLagbe.
Dear Wood! Welcome to TaxiLagbe.
Dear Matt! Welcome to TaxiLagbe.
taxi1 = TaxiLagbe('1010-01', 'Dhaka') Dear Wilson! Welcome to TaxiLagbe.
--------------------------------------
print('-------------------------------')
Trip info for Taxi number: 1010-01
taxi1.addPassenger('Walker_100', 'Wood_200') This taxi can cover only Dhaka area.
Total passengers: 4
taxi1.addPassenger('Matt_100')
Passenger lists:
taxi1.addPassenger('Wilson_105') Walker, Wood, Matt, Wilson
Total collected fare: 505 Taka
print('-------------------------------')
--------------------------------------
taxi1.printDetails() Taxi Full! No more passengers can be added.
--------------------------------------
print('-------------------------------')
Trip info for Taxi number: 1010-01
taxi1.addPassenger('Karen_200') This taxi can cover only Dhaka area.
Total passengers: 4
print('-------------------------------')
Passenger lists:
taxi1.printDetails() Walker, Wood, Matt, Wilson
Total collected fare: 505 Taka
print('-------------------------------')
--------------------------------------
taxi2 = TaxiLagbe('1010-02', 'Khulna') Dear Ronald! Welcome to TaxiLagbe.
Dear Parker! Welcome to TaxiLagbe.
taxi2.addPassenger('Ronald_115')
--------------------------------------
taxi2.addPassenger('Parker_215') Trip info for Taxi number: 1010-02
This taxi can cover only Khulna area.
print('-------------------------------')
Total passengers: 2
taxi2.printDetails() Passenger lists:
Ronald, Parker
Total collected fare: 330 Taka
Task 12
Implement the design of the Account class so that the following output is produced:

Driver Code Output


# Write your code here Default Account
0.0
a1 = Account() ------------------------
Oliver
print(a1.details())
10000.0
print("------------------------") ------------------------
Liam
a1.name = "Oliver"
0.0
a1.balance = 10000.0 ------------------------
Noah
print(a1.details())
400.0
print("------------------------") ------------------------
Sorry, Withdraw unsuccessful! The account
a2 = Account("Liam")
balance after deducting withdraw amount is
print(a2.details()) equal to or less than minimum.
------------------------
print("------------------------")
Sorry, Withdraw unsuccessful! The account
a3 = Account("Noah",400) balance after deducting withdraw amount is
equal to or less than minimum.
print(a3.details())
------------------------
print("------------------------") Withdraw successful! New balance is:
3071.0
a1.withdraw(6930)
 
print("------------------------")
a2.withdraw(600)
print("------------------------")
a1.withdraw(6929)

Task 13
Implement the design of the StudentDatabase class so that the following output is
produced:

GPA = Sum of (Grade Points * Credits)/ Credits attempted

Driver Code Output


# Write your code here Grades for Pietro
{'Summer2020': {('CSE230', 'CSE220',
# Do not change the following lines of code. 'MAT110'): 4.0}, 'Summer2021':
{('CSE250', 'CSE330'): 3.85}}
-----------------------------------------------
s1 = StudentDatabase('Pietro', '10101222') Name: Pietro
ID: 10101222
s1.calculateGPA(['CSE230: 4.0', 'CSE220: 4.0', 'MAT110: 4.0'],
Courses taken in Summer2020:
'Summer2020') CSE230
CSE220
s1.calculateGPA(['CSE250: 3.7', 'CSE330: 4.0'], 'Summer2021')
MAT110
print(f'Grades for {s1.name}\n{s1.grades}') GPA: 4.0
Courses taken in Summer2021:
print('------------------------------------------------------')
CSE250
s1.printDetails() CSE330
GPA: 3.85
s2 = StudentDatabase('Wanda', '10103332')
-----------------------------------------------
s2.calculateGPA(['CSE111: 3.7', 'CSE260: 3.7', 'ENG101: 4.0'], Grades for Wanda
{'Summer2022': {('CSE111', 'CSE260',
'Summer2022')
'ENG101'): 3.8}}
print('------------------------------------------------------') -----------------------------------------------
Name: Wanda
print(f'Grades for {s2.name}\n{s2.grades}')
ID: 10103332
print('------------------------------------------------------') Courses taken in Summer2022:
CSE111
s2.printDetails()
CSE260
ENG101
GPA: 3.8
Task 14
1 class Test3:
2     def __init__(self):
3         self.sum, self.y = 0, 0
4     def methodA(self):
5         x, y = 2, 3
6         msg = [0]
7         msg[0] = 3
8         y = self.y + msg[0]
9         self.methodB(msg, msg[0])
10         x = self.y + msg[0]
11         self.sum = x + y + msg[0]
12         print(x, y, self.sum)
13     def methodB(self, mg2, mg1):
14         x = 0
15         self.y = self.y + mg2[0]
16         x = x + 33 + mg1
17         self.sum = self.sum + x + self.y
18         mg2[0] = self.y + mg1
19         mg1 = mg1 + x + 2
20 print(x, self.y, self.sum)

Write the output of the x y sum


following code:
t3 = Test3()
t3.methodA()
t3.methodA()
t3.methodA()
t3.methodA()
Task 15
1 class Test5:
2     def __init__(self):
3         self.sum, self.y = 0, 0
4     def methodA(self):    
5         x = 0
6         z = 0
7         while (z < 5):
8             self.y = self.y + self.sum
9             x = self.y + 1
10             print(x, self.y, self.sum)
11             self.sum = self.sum + self.methodB(x, self.y)
12             z += 1
13     def methodB(self, m, n):
14         x = 0
15         sum = 0
16         self.y = self.y + m
17         x = n - 4
18         sum = sum + self.y
19         print(x, self.y, sum)
20 return self.sum

Write the output of the x y sum


following code:

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

What is the output of the x y sum


following code sequence?

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

What is the output of x y sum


the following code
sequence?

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

What is the output of x y sum


the following code
sequence?

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

Driver Code Output


# Write your code here Student name and department need to be set
=========================
# Do not change the following lines of code. Department for Carol needs to be set
s1 = Student() =========================
print("=========================") Jon is from EEE department
s2 = Student("Carol") =========================
print("=========================") ###########################
s3 = Student("Jon", "EEE") Name: Bob
print("=========================") Department: CSE
s1.update_name("Bob") Bob enrolled in 3 course(s):
s1.update_department("CSE") CSE110, MAT110, ENG091
s2.update_department("BBA") =========================
s1.enroll("CSE110", "MAT110", "ENG091") Name: Carol
s2.enroll("BUS101") Department: BBA
s3.enroll("MAT110", "PHY111") Carol enrolled in 1 course(s):
print("###########################") BUS101
s1.printDetail() =========================
print("=========================") Name: Jon
s2.printDetail() Department: EEE
print("=========================") Jon enrolled in 2 course(s):
s3.printDetail() MAT110, PHY111
Task 21

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]

Driver Code Output


# Write your code here ##########################
Name: Alice
# Do not change the following lines of code. ID: 20103012
s1 = Student(“Alice”,“20103012”,“CSE”) Department: CSE
s2 = Student(“Bob”, “18301254”,“EEE”) ##########################
Name: Bob
s3 = Student(“Carol”, “17101238”,“CSE”) ID: 18301254
print(“##########################”) Department: EEE
print(s1.details()) ##########################
Alice, you have taken 9.0 credits.
print(“##########################”)
List of courses: CSE110, MAT110, PHY111
print(s2.details()) Status: Ok
print(“##########################”) ##########################
Bob, you have taken 6.0 credits.
s1.advise(“CSE110”, “MAT110”, “PHY111”)
List of courses: BUS101, MAT120
print(“##########################”) Status: You have to take at least 1 more course.
s2.advise(“BUS101”, “MAT120”) ##########################
Carol, you have taken 15.0 credits.
print(“##########################”)
List of courses: MAT110, PHY111, ENG102,
s3.advise(“MAT110”, “PHY111”, “ENG102”, CSE111, CSE230
“CSE111”, “CSE230”) Status: You have to drop at least 1 course.
Task 22

Write the Hotel class with the required methods to give the following output as shown.

Driver Code Output


# Write your code here Staff With ID 1 is added
=================================
# Do not change the following lines of code. Staff ID: 1
Name: Adam
h = Hotel("Lakeshore")
Age: 26
h.addStuff( "Adam", 26) Phone no.: 000
=================================
print("=================================")
Guest With ID 1 is created
print(h.getStuffById(1)) =================================
Guest ID: 1
print("=================================")
Name: Carol
h.addGuest(“Carol”,35,”123”) Age: 35
Phone no.: 123
print("=================================")
=================================
print(h.getGuestById(1)) Guest With ID 2 is created
=================================
print("=================================")
Guest ID: 2
h.addGuest("Diana", 32, “431”) Name: Dianal
Age: 32
print("=================================")
Phone no.: 431
print(h.getGuestById(2)) =================================
All Staffs:
print("=================================")
Number of Staff: 1
h.allStaffs() Staff ID: 1 Name: Adam Age: 26 Phone no: 000
=================================
print("=================================")
All Guest:
h.allGuest() Number of Guest: 2
Guest ID: 1 Name: Carol Age: 35 Phone no.: 123
Guest ID: 2 Name: Dianal Age: 32 Phone no.: 431
Task 23

Write the Author class with the required methods to give the following outputs as
shown.

Driver Code Output


# Write your code here =================================
A book can not be added without author name
# Do not change the following lines of code. =================================
a1 = Author() Number of Book(s): 1
print("=================================") Author Name: Anna Kavan
Science Fiction: Ice
a1.addBook(“Ice”, “Science Fiction”)
=================================
print("=================================") =================================
a1.setName(“Anna Kavan”) Number of Book(s): 2
a1.addBook(“Ice”, “Science Fiction”) Author Name: Humayun Ahmed
a1.printDetail() Science Fiction: Onnobhubon
print("=================================") Horror: Megher Upor Bari
a2 = Author(“Humayun Ahmed”) =================================
Number of Book(s): 3
a2.addBook(“Onnobhubon”, “Science Fiction”)
Author Name: Humayun Ahmed
a2.addBook(“Megher Upor Bari”, “Horror”) Science Fiction: Onnobhubon, Ireena
print("=================================") Horror: Megher Upor Bari
a2.printDetail() =================================
a2.addBook(“Ireena”, “Science Fiction”)
print("=================================")
a2.printDetail()
print("=================================")
Task 24
Implement the design of the Hospital, Doctor and Patient class so that the following
output is produced:

Driver Code Output


# Write your code here =================================
Doctor's ID: 1d
# Do not change the following lines of code. Name: Samar Kumar
h = Hospital("Evercare") Speciality: Neurologist
d1 = Doctor("1d","Doctor", "Samar Kumar", "Neurologist") =================================
=================================
h.addDoctor(d1)
Patient's ID: 1p
print("=================================") Name: Kashem Ahmed
print(h.getDoctorByID("1d")) Age: 35
print("=================================") Phone no.: 12345
p1 = Patient("1p","Patient", "Kashem Ahmed", 35, 12345) =================================
h.addPatient(p1) =================================
print("=================================") Patient's ID: 2p
Name: Tanina Haque
print(h.getPatientByID("1p"))
Age: 26
print("=================================") Phone no.: 33456
p2 = Patient ("2p","Patient", "Tanina Haque", 26, 33456) =================================
h.addPatient(p2) All Doctors:
print("=================================") Number of Doctors: 1
print(h.getPatientByID("2p")) {'1d': ['Samar Kumar', 'Neurologist']}
print("=================================") All Patients:
Number of Patients: 2
h.allDoctors()
{'1p': ['Kashem Ahmed', 35, 12345], '2p':
h.allPatients() ['Tanina Haque', 26, 33456]}
Task 25

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]

Driver Code Output


# Write your code here =================================
1st dose done for Bob
astra = Vaccine("AstraZeneca", "UK", 60) =================================
Name: Bob Age: 21 Type: Student
modr = Vaccine("Moderna", "UK", 30)
Vaccine name: AstraZeneca
sin = Vaccine("Sinopharm", "China", 30) 1st dose: Given
p1 = Person("Bob", 21, "Student") 2nd dose: Please come after 60 days
print("=================================") =================================
p1.pushVaccine(astra) Sorry Bob, you can’t take 2 different vaccines
print("=================================") =================================
p1.showDetail() 2nd dose done for Bob
=================================
print("=================================")
Name: Bob Age: 21 Type: Student
p1.pushVaccine(sin, "2nd Dose") Vaccine name: AstraZeneca
print("=================================") 1st dose: Given
p1.pushVaccine(astra, "2nd Dose") 2nd dose: Given
print("=================================") =================================
p1.showDetail() =================================
print("=================================") Sorry Carol, Minimum age for taking vaccines is
25 years now.
p2 = Person("Carol", 23, "Actor")
=================================
print("=================================") =================================
p2.pushVaccine(sin) 1st dose done for David
print("=================================") =================================
p3 = Person("David", 34) Name: David Age: 34 Type: General Citizen
print("=================================") Vaccine name: Moderna
1st dose: Given
p3.pushVaccine(modr)
2nd dose: Please come after 30 days
print("=================================") =================================
p3.showDetail() 2nd dose done for David
print("=================================")
p3.pushVaccine(modr, "2nd Dose")

You might also like