Sample_Questions_SWE_320__Fall_2022.docx
Sample_Questions_SWE_320__Fall_2022.docx
class A:
def __init__(self,x):
self.x = x
def count(self,x):
self.x = self.x+1
class B(A):
def __init__(self, y=0):
A.__init__(self, 3)
self.y = y
def count(self):
self.y += 1
def main():
obj = B()
obj.count()
print(obj.x, obj.y)
main()
A) 31
B) 30
C) 29
D) 32
x = change(1,2,3)
y = getattr(x, 'a')
setattr(x, 'a', y+1)
print(x.a)
A) 6
B) 7
C) Error
D) 0
This study source was downloaded by 100000880009465 from CourseHero.com on 12-05-2024 10:24:05 GMT -06:00
https://www.coursehero.com/file/177775941/Sample-Questions-SWE-320-Fall-2022docx/
A) Error
B) 12
C) 15
D) 1512
class Person:
def __init__(self,firstName,lastName):
self.firstName = firstName
self.lastName = lastName
class Employee(Person):
def __init__(self,firstName="",lastName="",position="Manager"):
Person.__init__(self,firstName,lastName)
self.position=position
def getFullInfo(self):
return self.firstName+" "+self.lastName+", "+self.position
# Create object
person=Person("Ahmed","Samir")
employee=Employee(person.firstName,"Sam","Engineer")
print(employee.getFullInfo())
Q5. The class Employee has four private attributes to define its first name, last name, address, and a
Boolean value indicating whether the employee is parttime or not. Implement the function
getHoursOfWeek based on the logic, if the employee is part-time, it will be 20 hours per week,
otherwise, it will be 40 hours per week. Also, write some code to test your code
ANSWER
Class Employee:
def __init__(self,firstName=””,lastName=””,address=””,partTime=False):
self.__firstName=firstName
self.__lastName=lastName
self.__address=address
self.__partTime=partTime
def getHoursOfWeek(self):
if self.__partTime==True:
return 20
else:
return 40
This study source was downloaded by 100000880009465 from CourseHero.com on 12-05-2024 10:24:05 GMT -06:00
https://www.coursehero.com/file/177775941/Sample-Questions-SWE-320-Fall-2022docx/
emp1=Employee(“Ahmed”,”Salem”,”Khalifa”,False)
print(emp1.getHoursOfWeek())
Q6.
Consider the relationship, “Student is-a Person”, in the context of a school. The id, name, class, and
score are some attributes of a student. All students have a score between 0 and 100. If the student's
score is less than 60% then the student fails, and otherwise, the student passes.
Create a Python program to represent the above scenario. Your program must have proper
documentation, create at least two objects to test the functionalities, and display all relevant details.
One of the following online Python interpreters can be used to verify your code:
class Person:
#constructor
def __init__(self):
self._pname= ""
def setpname(self,name):
self._pname=name
def getpname(self):
return self._pname
class Student(Person):
#constructor
def __init__(self):
Person.__init__(self)
self.__sid=""
self.__sclass=""
This study source was downloaded by 100000880009465 from CourseHero.com on 12-05-2024 10:24:05 GMT -06:00
https://www.coursehero.com/file/177775941/Sample-Questions-SWE-320-Fall-2022docx/
self.__sscore=0.0
def setsid(self,id):
self.__sid=id
def getsid(self):
return self.__sid
def setsclass(self,clas):
self.__sclass=clas
def getsclass(self):
return self.__sclass
def setsscore(self,score):
self.sscore=score
def getsscore(self):
return self.sscore
def getacadstand(self):
return ("fail")
else:
return ("pass")
def __str__(self):
stud1= Student()
stud1.setpname("Belsabel")
stud1.setsid("m8008182")
This study source was downloaded by 100000880009465 from CourseHero.com on 12-05-2024 10:24:05 GMT -06:00
https://www.coursehero.com/file/177775941/Sample-Questions-SWE-320-Fall-2022docx/
stud1.setsclass("A2")
stud1.setsscore(70)
stud1.getacadstand()
print(stud1)
stud2= Student()
stud2= Student()
stud2.setpname("Sebah")
stud2.setsid("m800929")
stud2.setsclass("A3")
stud2.setsscore(40)
print(stud2)
stud3= Student()
stud3= Student()
stud3.setpname("Salina")
This study source was downloaded by 100000880009465 from CourseHero.com on 12-05-2024 10:24:05 GMT -06:00
https://www.coursehero.com/file/177775941/Sample-Questions-SWE-320-Fall-2022docx/
Powered by TCPDF (www.tcpdf.org)