0% found this document useful (0 votes)
11 views

Sample_Questions_SWE_320__Fall_2022.docx

Uploaded by

abeeruxx99
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)
11 views

Sample_Questions_SWE_320__Fall_2022.docx

Uploaded by

abeeruxx99
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/ 5

Sample Questions SWE-320 Fall 2022

Q1. What is the output of the following piece of code?

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

Q2. What is the output of the following code?


class change:
def __init__(self, x, y, z):
self.a = x + y + z

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

Q3. 1 The output of the code shown below is:


def f1():
x=15
print(x)
x=12
f1()

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

Q4. What is the output of this Python code?

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())

Ahmed Sam, Engineer

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:

''' this class represnts person'''

#constructor

def __init__(self):

self._pname= ""

#setter and getter

def setpname(self,name):

self._pname=name

def getpname(self):

return self._pname

class Student(Person):

''' This represents students class'''

#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

#setter and getter

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):

if self.getsscore() > 100 or self.getsscore()<0:

return("score is not valid")

elif self.getsscore() < 60 and self.getsscore() >0:

return ("fail")

else:

return ("pass")

def __str__(self):

return "\n student name :{} \n Studentid :{}\n studentclass:{}\nstudentscore:{}\n


studentacadstand:{}".format(self.getpname(),self.getsid(), self.getsclass(),
self.getsscore(),self.getacadstand())

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)

You might also like