Computer Science With Python Chapter 4 Inheritance
  • Sponsor Area

    NCERT Solution For Class 12 Computer And Communication Technology Computer Science With Python

    Inheritance Here is the CBSE Computer And Communication Technology Chapter 4 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 Inheritance Chapter 4 NCERT Solutions for Class 12 Computer And Communication Technology Inheritance Chapter 4 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 2
    CBSEENCO12011589

    What will be the status of the following list after the First, Second and Third pass of the bubble sort method used for arranging the following elements in ascending order ?

    Note: Show the status of all the elements after each pass very clearly underlining the changes.
    52, 42, -10, 60, 90, 20

    Solution

    I Pass

    52 42 -10 60 90 20
    42 52 -10 60 90 20
    42 -10 52 60 90 20
    42 -10 52 60 90 20
    42 -10 52 60 90 20
    42 -10 52 60 20 90
     
    II Pass
    42 -10 52 60 20 90
    -10 42 52 60 20 90
    -10 42 52 60 20 90
    -10 42 52 60 20 90
    -10 42 52 20 60 90

    III Pass
    -10
    42
    52
    20
    60
    90
    -10
    42
    52
    20
    60
    90
    -10
    42
    52
    20
    60
    90
    -10
    42
    20
    52
    60
    90
    Question 3
    CBSEENCO12011591

    Write Addnew(Member) and Remove(Member) methods in python to Add a new Member and Remove a Member from a List of Members, considering them to act as INSERT and DELETE operations of the data structure Queue.

    Solution
    class queue:
    	Member=[]
    	def Addnew(self):
    		a=input('enter member name: ')
    		queue.Member.append(a)
    	def Remove(self):
    		if (queue.Member==[]):
    			print 'Queue empty'
    		else:
    			print 'deleted element is: ',queue.Member[0]
    del queue.Member[0] # queue.Member.delete()
    Question 5
    CBSEENCO12011595

    Write a method in python to read lines from a text file MYNOTES.TXT, and display those lines, which are starting with an alphabet ‘K’.

    Solution
    def display():
    	file=open('MYNOTES.TXT','r')
    	line=file.readline()
    	while line:
    		if line[0]=='K' :
    			print line
    			line=file.readline()
    			file.close()
    Question 8
    CBSEENCO12011638

    For a given list of values in descending order, write a method in python to search for a value with the help of Binary Search method. The method should return the position of the value and should return -1 if the value not present in the list.

    Solution
    def binarysrch(nums,x):
    	high = len(nums)
    	low =0
    	while low < high:
    		mid = (low + high)//2
    		midval = nums[mid]
    		if midval > x:
    			low = mid + 1
    		elif midval < x:
    			high = mid
    		else:
    			return mid
    			return 1
    Question 9
    CBSEENCO12011639

    Write Insert(Place) and Delete(Place) methods in python to add Place and RemovePlace considering them to act as Insert and Delete operations of the data structure Queue.

    Solution
    class queue:
    	
    	place = [ ]
    	def insert(self):
    		a = raw_input('Enter place')
    		queue.place.append(a)
    	def delete(self):
    		if (queue.place == [ ] ):
    			print('Queue empty')
    		else:
    			print('Deleted element is', queue.place[0])
    			queue.place.delete()
    Question 10
    CBSEENCO12011640

    Write a method in python to find and display the prime numbers between 2 to N.Pass N as the argument to the method.

    Solution
    def prime(N):
    	for a in range(2,N):
    		for I in range(2,a):
    			if a%i ==0:
    				break
    			else:
    				print a
    Question 11
    CBSEENCO12011684

    Illustrate the concept inheritance with the help of a python code.

    Solution

    The concept of inheritance is given below:

    class Base:
    	def __init__ (self):
    		print 'Base Constructor at work...'
    	def show(self):
    		print 'Hello Base'
    		
    class Der(Base):
    	def __init__(self):
    		print 'Derived Constructor at work...'
    	def display(self):
    		print 'Hello from Derived'

    Question 13
    CBSEENCO12011686

    Write a class PICTURE in Python with following specifications:

    Instance Attributes
    ­ -Pno      # Numeric value
    ­ -Category # String value
    ­ -Location # Exhibition Location with String value
    
    Methods:
    ­ FixLocation () # A method to assign Exhibition
    	        # Location as per Category as
    	        # shown in the following table​
    Category Location
    Classic Amina
    Modern Jim Plaq
    Antique Ustad Khan
    ­ -Enter() 	# A function to allow user to
    		enter values
    		# Pno, Category and call
    -FixLocation() method
    ­-SeeAll()  # A function to display all the
    	   data members

    Solution
    class PICTURE:
    	Pno=0
    	Category=' '
    	Location=' '
    	def FixLocation():
    		if self.Category=='Classic':
    			self.Location='Amina'
    		elif self.Category=='Modern':
    			self.Location='Jim Plaq'
    		elif self.Category=='Antique':
    			self.Location='Ustad Khan'
    	def Enter():
    		self.Pno=int(input('Enter Pno:'))
    		self.Category=input('Enter Name:')
    		self.FixLocation()
    	def SeeAll()
    	print self.Pno,self.Category,self.Location
    Question 14
    CBSEENCO12011687

    What is operator overloading with methods? Illustrate with the help of an example using a python code.

    Solution

    Operator overloading is an ability to use an operator in more than one form.
    Examples:
    In the following example operator + is used for finding the sum of two integers:
         a = 7
         b = 5
         print(a+b) #gives the output: 12

    Whereas in the next example, shown below the same + operator is used to add two strings:
         a = 'Indian '
         b = 'Government'
         print(a+b) #gives the output: Indian Government

    Mock Test Series

    Sponsor Area

    Sponsor Area

    NCERT Book Store

    NCERT Sample Papers

    Entrance Exams Preparation

    27