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

CSE111 Lab Assignment 7

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

CSE111 Lab Assignment 7

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Course Title: Programming Language II

Course Code: CSE 111


Lab Assignment no: 7
** You are not allowed to change any of the code of the tasks
** Use Inheritance to solve all problems

Task - 1
Given the following classes, write the code for the BBA_Student class so that the
following output is printed:

class Student: Output:


def __init__(self, name='Just a student', dept='nothing'): Name: default Department: BBA
self.__name = name Name: Humpty Dumpty Department: BBA
Name: Little Bo Peep Department: BBA
self.__department = dept
def set_department(self, dept):
self.__department = dept
def get_name(self):
return self.__name
def set_name(self,name):
self.__name = name
def __str__(self):
return 'Name: '+self.__name+' Department: '+self.__department

#write your code here

print(BBA_Student())
print(BBA_Student('Humpty Dumpty'))
print(BBA_Student('Little Bo Peep'))
Task – 2

class Vehicle: OUTPUT:


def __init__(self): Part 1
self.x = 0 ------
self.y = 0 (0 , 0)
(0 , 1)
def moveUp(self):
(-1 , 1)
self.y+=1
(-1 , 0)
def moveDown(self):
(0 , 0)
self.y-=1 ------
def moveRight(self): Part 2
self.x+=1 ------
def moveLeft(self): (0 , 0)
self.x-=1 (-1 , -1)
def __str__(self): False
return '('+str(self.x)+' , '+str(self.y)+')' True
#write your code here ------

print('Part 1')
print('------')
car = Vehicle()
print(car)
car.moveUp()
print(car)
car.moveLeft()
print(car)
car.moveDown()
print(car)
car.moveRight()
print(car)
print('------')
print('Part 2')
print('------')
car1 = Vehicle2010()
print(car1)
car1.moveLowerLeft()
print(car1)
car2 = Vehicle2010()
car2.moveLeft()
print(car1.equals(car2))
car2.moveDown()
print(car1.equals(car2))
A vehicle assumes that the whole world is a 2-dimensional graph paper. It maintains its
x and y coordinates (both are integers). The vehicle gets manufactured (constructed) at
(0, 0) coordinate.

Subtasks:

1. Design a Vehicle2010 class which inherits movement methods from Vehicle


and adds new methods called move UpperRight, UpperLeft, LowerRight,
LowerLeft. Each of these diagonal move methods must re-use two inherited and
appropriate move methods.
2. Write an “equals” method which tests if significant class properties are the
same (in this case x and y).

Note: All moves are 1 step. That means a single call to any move method changes
value of either x or y or both by 1.

Task - 3
Given the following classes, write the code for the Cricket_Tournament and the
Tennis_Tournment class so that the following output is printed.

class Tournament: OUTPUT:


def __init__(self,name='Default'): Cricket Tournament Name: Default
self.__name = name Number of Teams: 0
def set_name(self,name): Type: No type
self.__name = name -----------------------
def get_name(self): Cricket Tournament Name: IPL
return self.__name Number of Teams: 10
Type: t20
#write your code here -----------------------
Tennis Tournament Name: Roland Garros
ct1 = Cricket_Tournament() Number of Players: 128
print(ct1.detail())
print("-----------------------")
ct2 = Cricket_Tournament("IPL",10,"t20")
print(ct2.detail())
print("-----------------------")
tt = Tennis_Tournament("Roland Garros",128)
print(tt.detail())
Task - 4
Given the following classes, write the code for the Book and the CD class so that the
following output is printed.

class Product: OUTPUT:


def __init__(self,id, title, price): ID: 1 Title: The Alchemist Price: 500
self.__id = id ISBN: 97806 Publisher: HarperCollins
self. __title = title -----------------------
self. __price = price ID: 2 Title: Shotto Price: 300
def get_id_title_price(self): Band: Warfaze Duration: 50minutes
return "ID: "+str(self.__id)+" Title:"+self.__title+ Genre: Hard Rock
"Price: "+str(self.__price)

#write your code here

book = Book(1,"The Alchemist",500,"97806","HarperCollins")


print(book.printDetail())
print("-----------------------")
cd = CD(2,"Shotto",300,"Warfaze",50,"Hard Rock")
print(cd.printDetail())
Task - 5
Given the following classes, write the code for the Dog and the Cat class so that the following
output is printed.

class Animal: OUTPUT:


def __init__(self,sound): Animal does not make sound
self.__sound = sound meow
bark
def makeSound(self):
return self.__sound

class Printer:
def printSound(self, a):
print(a.makeSound())

#write your code here

d1 = Dog('bark')
c1 = Cat('meow')
a1 = Animal('Animal does not make sound')
pr = Printer()
pr.printSound(a1)
pr.printSound(c1)
pr.printSound(d1)
Task - 6
Given the following classes, write the code for the Triangle and the Trapezoid class so that
the following output is printed.

class Shape: OUTPUT:


Shape name: Default
def __init__(self, name='Default', height=0, base=0): Height: 0, Base: 0
self.area = 0 Area: 0.0
self.name = name ---------------------------
self.height = height Shape name: Triangle
self.base = base Height: 10, Base: 5
Area: 25.0
---------------------------
def get_height_base(self): Shape name: Trapezoid
return "Height: "+str(self.height)+",Base: "+str(self.base) Height: 10, Base: 6, Side_A: 4
Area: 50.0
#write your code here

tri_default = triangle()
tri_default.calcArea()
print(tri_default.printDetail())
print('--------------------------')
tri = triangle('Triangle', 10, 5)
tri.calcArea()
print(tri.printDetail())
print('---------------------------')
trap = trapezoid('Trapezoid', 10, 6, 4)
trap.calcArea()
print(trap.printDetail())
Task - 7
Given the following classes, write the code for the Player and the Manager class so that the
following output is printed. To calculate the match earning use the following formula:
1. Player: (total_goal * 1000) + (total_match * 10)
2. Manager: match_win * 1000

class Football: OUTPUT:


Name: Ronaldo, Team Name: Juventus
def __init__(self, team_name, name, role): Team Role: Striker
self.__team = team_name Total Goal: 25, Total Played: 32
self.__name = name Goal Ratio: 0.78125
self.role = role Match Earning: 25320K
self.earning_per_match = 0 ----------------------------------
Name: Zidane, Team Name: Real Madrid
Team Role: Manager
def get_name_team(self): Total Win: 25
return 'Name: '+self.__name+', Team Name: ' +self.__team Match Earning: 25000K

#write your code here

player_one = Player('Juventus', 'Ronaldo', 'Striker', 25, 32)


player_one.calculate_ratio()
player_one.print_details()
print('------------------------------------------')
manager_one = Manager('Real Madrid', 'Zidane', 'Manager', 25)
manager_one.print_details()

You might also like