Computer Science With Python Chapter 2 Concept Of Object Oriented Programming
  • Sponsor Area

    NCERT Solution For Class 12 Computer+and+communication+technology Computer Science With Python

    Concept Of Object Oriented Programming Here is the CBSE Computer+and+communication+technology Chapter 2 for Class 12 students. Summary and detailed explanation of the lesson, including the definitions of difficult words. All of the exercises and questions and answers from the lesson's back end have been completed. NCERT Solutions for Class 12 Computer+and+communication+technology Concept Of Object Oriented Programming Chapter 2 NCERT Solutions for Class 12 Computer+and+communication+technology Concept Of Object Oriented Programming Chapter 2 The following is a summary in Hindi and English for the academic year 2021-2022. You can save these solutions to your computer or use the Class 12 Computer+and+communication+technology.

    Question 1
    CBSEENCO12011537

    List four characteristics of Object Oriented programming.

    Solution
    Encapsulation – Encapsulation is capturing data and keeping it safely and securely from outside interfaces.
    Inheritance- This is the process by which a class can be derived from a base class with all features of the base class and some of its own. This increases code reusability.
    Polymorphism- This is the ability to exist in various forms. For example, an operator can be overloaded so as to add two integer numbers and two floats.
    Abstraction- The ability to represent data at a very conceptual level without any details.
    Question 2
    CBSEENCO12011538

    class Test:
    	rollno=1
    	marks=75
    	def __init__(self,r,m): #function 1
    		self.rollno=r
    		self.marks=m
    	def assign(self,r,m):     #function 2
    		rollno = r
    		marks = m
    	def check(self):          #function 3
    		print self.rollno,self.marks
    		print rollno,marks

    (i) In the above class definition, both the functions - function 1 as well as function 2 have a similar definition. How are they different in execution?

    (ii) Write statements to execute function 1 and function 2.

    Solution

    i) Function 1 is the constructor which gets executed automatically as soon as the object of the class is created. Function 2 is a member function which has to be called to assign the values to rollno and marks.

    ii) Function 1 E1=Test(1,95) # Any values in the parameter
        Function 2 E1.assign(1,95) # Any values in the parameter

    Question 3
    CBSEENCO12011584

    List four characteristics of Object Oriented programming.

    Solution
    Encapsulation – Encapsulation is capturing data and keeping it safely and securely from outside interfaces.
    Inheritance- This is the process by which a class can be derived from a base class with all features of the base class and some of its own. This increases code reusability.
    Polymorphism- This is the ability to exist in various forms. For example, an operator can be overloaded so as to add two integer numbers and two floats.
    Abstraction- The ability to represent data at a very conceptual level without any details.
    Question 4
    CBSEENCO12011632

    What is the difference between Multilevel and Multiple inheritance? Give suitable examples to illustrate both.

    Solution
    Multiple Inheritance Multilevel inheritance
    “Multiple Inheritance” refers to the concept of one class extending (Or inherits) more than one base class. Multilevel inheritance refers, where one can inherit from a derived class, thereby making this derived class the base class for the new class. As you can see in below flow diagram Zis subclass or child class of Y and B is a child class of X.
    Question 5
    CBSEENCO12011633

    What will be the output of the following python code considering the following set of inputs?

    JAYA
    My 3 books
    PICK2
    2120

    Also, explain the try and except used in the code.

    Counter=0
    while True:
    	try:
    		Number=int(raw_input('Give a Number'))
    		break
    	except ValueError:
    		Counter=Counter+2
    		print('Reenter Number')
    print(Counter)

    Solution

    Output:

    Give a Number JAYA
    Reenter Number
    Give a Number My 3 books
    Reenter Number
    Give a Number PICK2
    Reenter Number
    Give a Number 2120
    6

    Explanation: The code inside try makes sure that the valid number is entered by the user. When any input other than an integer is entered, a value error is thrown and it prompts the user to enter another value.

    Question 6
    CBSEENCO12011634

    Write a class CITY in Python with following specifications
    Instance Attributes

    -Code   # Numeric value
    -Name # String value
    -Pop      #Numeric value of population
    -KM      # Numeric value
    -Density #Numeric value for Population Density

    Methods:
    CalDen()# Method to calculate Density as Pop/KM
    Record()# Method to allow user to enter values
    Code,Name,Pop,KM and call CalDen() method
    See()# Method to display all the members also display
                  a message ”Highly Populated Area” 
                  if the Density is more than 12000

    Solution
    class CITY:
    
    	def __init__(self):
    		self.Code = 0
    		self.Name = ''
    		self.Pop = 0
    		self.KM =0
    		self.Density=0
    
    	def CalDen(self):
    		self.Density = self.Pop / self.KM
    
    	def Record(self):
    		self.Code = input('Enter Code')
    		self.Name = raw_input('Enter Name')
    		self.Pop = input('Enter population')
    		self.KM = input(“Enter KM”)
    		CalDen(self) // or self.CalDen()
    			
    	def See(self):
    		print Code,Name,Pop, KM, Density
    		if self.Density > 12000:
    			print('Highly Populated Area')

     

    Mock Test Series

    Sponsor Area

    Sponsor Area

    NCERT Book Store

    NCERT Sample Papers

    Entrance Exams Preparation