Professional Documents
Culture Documents
Authorized by Satheesha B N
1.0 Nov 2015 Roy Antony Arnold G Vani K N Mapped for Campus Connect
1.1 Dec 2015 Roy Antony Arnold G Vani K N Mapped for Campus Connect
CONFIDENTIAL
CONTENTS
CONFIDENTIAL
Infosys Limited Case Study for Object Oriented Programming using Python
Note: Read this case study fully and understand as this is going to be the business
scenario for all the hands-on assignments given in this document.
Assumption:
1. Decision of the branch of study a student is allocated, is not within the scope of
this case study
Objective: Read the above given business scenario to understand and identify OO
concepts
Problem Description:
Identify the OO concepts applicable for these scenarios:
1. More than 100 faculty members are working in the college to teach various
engineering subjects. Every faculty has some attributes and perform some
activities. How can these attributes and activities be represented using OO
concepts?
Summary of this assignment: In this assignment, you have learnt object oriented
concepts using scenarios
Objective: Read the above given business scenario to create student class and to
create objects for that class
Problem Description:
Write a Python program for the class diagram given below:
Student
-studentid : int
-qualifyingexammarks : float
-residentialstatus : char
-yearofengg : int
+setstudentid(int) : void
+setqualifyingexammarks(float) : void
+setresidentialstatus(char) : void
+setyearofengg(int) : void
+getstudentid() : int
+getqualifyingexammarks() : float
+getresidentialstatus(): char
+getyearofengg() : int
Step 5: Invoke the corresponding getter method to display the student details as given
below:
Student Id :
Qualifying Marks :
Residential Status :
Current Year of Engineering :
Objective: Understand the importance of self reference to access the object members.
Problem Description:
Debug the below given Python code to give the output, shown after the code.
class Registration:
def setregistrationid (self, rid):
__registrationid = rid
def getregistrationid(self):
return __registrationid
objreg = Registration()
objreg.setregistrationid(1001)
print("Registration Id : ", objreg.getregistrationid())
Output Expected:
Registration Id : 1001
Problem Description:
To initialize the members of the class during object instantiation __init__() method is
needed. By using default parameters in __init__() method we can initialize the members
as per the requirement. Write a Python program for the class diagram given below:
Student
+displayheader(char c) : void
+displayheader(char c, int n) : void
+displayheader(string s) : void
Default parameters need to be assigned properly in such a way to get following output
on the screen:
****************************************************************
Rict Engineering College
****************************************************************
Problem Description:
Chief accountant wants to take printout of some report. For which, need to print some
headers depends on the need. Should have ability of printing a string, or a character n
no. of times. Write a Python program for the class diagram given below:
Student
-studentid : int
-studentname : string
-qualifyingexammarks : float
-residentialstatus : char
-yearofengg : int
-branchname : string
+Student(int, string, float, char, int, string)
……
Test Case 1:
Display the default values of the __init__ method as given below
Student Id :
Student Name :
Qualifying Exam Marks :
Residential Status :
Current Year of Engineering :
Branch Name :
Test Case 2:
Pass following values to the parameters:
studentid 15001
studentname Jack
qualifyingexammarks 125.5
residentialstatus H
yearofengg 1
branchname Civil
Problem Description:
Some students and faculty members are expected to have two addresses namely
permanent address, and communication address. Write a python program to bring the
relationship between student and address class and also between faculty and address
class.
Address
-street : string
-area : string
-city : string
-zip : string
-state : string
+Address(string, string, string, string, string)
+setstreet(string) : void
+setarea(string) : void
+setcity(string) : void
+setzip(string) : void
+setstate(string) : void
+getstreet() : string
+getarea() : string
+getcity() : string
+getzip() : string
+getstate() : string
Student Faculty
-studentid : int -facultyid : int
-studentname : string -facultyname : string
-qualifyingexammarks : float -branchname : string
-residentialstatus : char -designation : string
-yearofengg : int -permanentaddress : Address
-branchname : string -commaddress : Address
-permanentaddress : Address ……
-commaddress : Address +setpermanentaddress(Address) : void
…… +setcommaddress(Address) : void
+setpermanentaddress(Address) : void +getpermanentaddress() : Address
+setcommaddress(Address) : void +getcommaddress() : Address
+getpermanentaddress() : Address
+getcommaddress() : Address
Problem Description:
Students are categorized as day scholar and hosteller. Hence, write a python program
to implement day scholar and hosteller class which are inherit from the student
class. The class diagram for this scenario is given below:
Student
-studentid : int Address
-studentname : string
-qualifyingexammarks : float -addressline : string
-residentialstatus : char -city : string
-yearofengg : int -zip : string
-branchname : string -state : string
-permanentaddress : Address +Address(string, string,
-counter : int ->static string, string)
+Student() +setaddressline(string) : void
+Student(int, string, float, char, int, string, Address) +setcity(string) : void
+setstudentid(int) : void +setzip(string) : void
+setstudentname(string) : void +setstate(string) : void
+setqualifyingexammarks(float) : void +getaddressline() : string
+setresidentialstatus(char) : void +getcity() : string
+setyearofengg(int) : void +getzip() : string
+setbranchname(string) : void +getstate() : string
+setpermanentaddress(Address) : void
+getstudentid() : int
+getstudentname() : string
+getqualifyingexammarks() : float
+getresidentialstatus() : char
+getyearofengg() : int
+getbranchname() : string
+getpermanentaddress() : Address
+getstudentcount() : int -> static
+validatestudentname() : boolean
+validatebranchname() : boolean
+validateexammarks() : boolean
Hosteller DayScholar
-hostelname : string
-roomnumber : int -residentialaddress : Address
-roomtype : string -distance : float
+Hosteller( int, string, float, char, int, string, Address, +DayScholar( int, string, float, char, int, string, Address,
string, int, string) Address, float)
+sethostelname(string) : void +setresidentialaddress(Address) : void
+setroomnumber(int) : void +setdistance(float) : void
+setroomtype(string) : void
+gethostelname() : string
+getroomnumber() : int
+getroomtype() : string
Guidelines:
Create a reference to the object created from the Hosteller class and initialize the
same with the following values through __init__() method:
Instance Variable Initial value
studentid 15001
studentname Jimmy
qualifyingexammarks 88.5
residentialstatus H
branchname CSE
yearofengg 1
addressline K-58, Xavier Enclave
city Chennai
state Tamilnadu
zip 600018
hostelname Boys Hostel – 1
roomnumber 102
roomtype shared
Student Id :
Student Name :
Qualifying Marks :
Residential Status :
Current Year of Engineering :
Branch Name :
Permanent Address :
Hostel Name :
Room Number :
Room Type :
Student Id :
Student Name :
Qualifying Marks :
Residential Status :
Current Year of Engineering :
Branch Name :
Permanent Address :
Residential Address :
Distance from College :
Problem Description:
What would be the output for the following programs? If there is an error in the program,
analyze it, fix it and execute it. Also write the inference drawn from each code snippet.
Code – 1:
class Parent:
def setnum(self, val):
self.__num = val
def getnum(self):
return self.__num
def display(self):
print("Number : ", self.__num)
class Child(Parent):
def setval(self, num):
self.__val = num
def getval(self):
return self.__val
def display(self):
print("Value : ", self.__val)
print("Number : ", self.__num)
child = Child()
child.setnum(10)
child.setval(20)
child.display()
Code – 2:
class Parent:
def setnum(self, val):
self.__num = val
def getnum(self):
return self.__num
def display(self):
print("Number : ", self.__num)
class Child(Parent):
def setval(self, num):
self.__val = num
def getval(self):
return self.__val
def display(self):
print("Value : ", self.__val)
super().display()
child = Child()
child.setnum(10)
child.setval(20)
child.display()
Code – 3:
class StaticDemo:
count = 10
def __init__(self):
StaticDemo.count = StaticDemo.count + 1
@staticmethod
def display():
print(count)
s1 = StaticDemo()
s2 = StaticDemo()
s1.display()
Code – 4:
class Animal:
@classmethod
def testclassmethod(cls):
print("Class Method in Animal class is invoked")
def testinstancemethod(self):
print("Instance Method in Animal class is invoked")
class Cat(Animal):
@classmethod
def testclassmethod(cls):
print("Class Method in Cat class is invoked")
def testinstancemethod(self):
print("Instance Method in Cat class is invoked")
mycat = Cat()
myanimal = Animal()
myanimal = mycat
Animal.testclassmethod()
myanimal.testinstancemethod()
Code – 5:
class ClassA:
def methodone(self):
print("First method in Class A")
def methodtwo(self):
print("Second method in Class A")
@staticmethod
def methodthree():
print("Third static method in Class A")
@staticmethod
def methodfour():
print("Fourth static method in Class A")
class ClassB(ClassA):
@staticmethod
def methodone():
print("First static method in Class B")
def methodtwo(self):
print("Second method in Class B")
super().methodtwo()
def methodthree(self):
print("Third method in Class B")
@staticmethod
def methodfour():
print("Fourth static method in Class B")
super().methodfour()
b = ClassB()
b.methodone()
b.methodtwo()
b.methodthree()
b.methodfour()