B02C-2018 – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-CBSE12A-2018-B02C #PYTHON#6120    siteicon   siteicon  

Problem Statement - B02C-2018

Define a class CONTAINER in Python with following specifications

Instance Attributes
- Radius,Height   # Radius and Height of Container
- Type            # Type of Container
- Volume          # Volume of Container

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

Solution

TC++ #6120

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


Share

CSKC| Created: 9-Jan-2019 | Updated: 9-Jan-2019|CBSE12A-2018









Back