Page 363 - C++
P. 363
CBSE AISSCE 2017-2018 Marking Scheme for Computer Science
(2018-2019 Sub Code: 083 Paper Code: 91)
Methods
- CalVolume() # To calculate volume
# as per the Type of container
# With the formula as given below:
Type Formula to calculate Volume
1 3.14 * Radius * Height
3 3.14 * Radius * Height/3
- GetValue() # To allow user to enter values of
# Radius, Height and Type.
# Also, this method should call
# CalVolume() to calculate Volume
- ShowContainer()# To display Radius, Height, Type
# Volume of the Container
Ans class CONTAINER: # class CONTAINER():/class CONTAINER(Object):
def __init__(self): # def __init__(self,R,H,T,V):
self.Radius=0 # self.Radius=R
self.Height=0 # self.Height=H
self.Type =0 # self.Type=T
self.Volume=0 # self.Volume=V
def CalVolume(self):
if self.Type == 1:
self.Volume = 3.14 * self.Radius * self.Height
elif self.Type ==3:
self.Volume = 3.14 * self.Radius * self.Height /3
def GetValue(self):
self.Radius = input("Enter Radius")
self.Height = input("Enter Height")
self.Type = input("Enter type")
self.CalVolume() # OR CalVolume(self)
def ShowContainer(self):
print self.Radius
print self.Height
print self.Type
print self.Volume
(½ Mark for correct syntax for class header)
(½ Mark for correct declaration of instance attributes)
(1 Mark for correct definition of CalVolume() function)
(1 Mark for correct definition of GetValue() with proper invocation of
CalVolume( ))
(1 Mark for correct definition of ShowContainer())
Page #21/35