2018 CBSE Class 12 Computer Science Question Paper with Detailed Solutions

 

This is the Class 12 CBSE Final Term Computer Science Question Bank. The students’ challenges are met through a set of questions and answers that cut across all topics. The questions are divided into sections including multiple choice, very short answer, short answer and long answer questions so as to enhance the revision. Detailed answers are interspersed in any patient section that can be disclosed. Use this question bank for revising the concepts, practicing important questions or preparing for the final examination.

Note: These questions are based on the latest syllabus updates and include previous year questions for reference. Ensure to reshow the solved examples provided to grasp complex topics with ease.

Section B – Python Programming

1. (a) Differentiate between Syntax Error and Run-Time Error. Also, write a suitable example in Python to illustrate both.

SHOW ANSWER

Syntax Error: Occurs when Python can’t understand the code. Example:

print "Hello World"  # Missing parentheses

Run-Time Error: Occurs during execution. Example:

a = 10
b = 0
print(a / b)  # Division by zero

1. (b) Name the Python Library modules which need to be imported to invoke the following functions:

      • sin()

 

      • search()
SHOW ANSWER

sin()

      • requires

import math
search()

      • requires

import re

1. (c) Rewrite the following code in Python after removing all syntax errors.

SHOW ANSWER
Val = int(input("Value:"))  
Adder = 0  
for C in range(1, Val, 3):  
    Adder += C  
    if C % 2 == 0:  
        print(C * 10)  
    else:  
        print(C * 1)
print(Adder)

1. (d) Find and write the output of the following Python code:

Data = ["P", 20, "R", 10, "S", 30]
Times = 0
Alpha = ""
Add = 0
for C in range(1, 6, 2):
    Times = Times + C
    Alpha = Alpha + Data[C-1] + "$"
    Add = Add + Data[C]
print(Times, Add, Alpha)
SHOW ANSWER

Output: 9 60 P$R$S$

1. (e) Find and write the output of the following Python code:

class GRAPH:
    def __init__(self, A=50, B=100):
        self.P1 = A
        self.P2 = B
    def Up(self, B):
        self.P2 = self.P2 - B
    def Down(self, B):
        self.P2 = self.P2 + 2 * B
    def Left(self, A):
        self.P1 = self.P1 - A
    def Right(self, A):
        self.P1 = self.P1 + 2 * A
    def Target(self):
        print("(", self.P1, ":", self.P2, ")")

G1 = GRAPH(200, 150)
G2 = GRAPH()
G3 = GRAPH(100)
G1.Left(10)
G2.Up(25)
G3.Down(75)
G1.Up(30)
G3.Right(15)
G1.Target()
G2.Target()
G3.Target()
SHOW ANSWER

Output:

(190 : 120)
(50 : 75)
(130 : 250)

1. (f) What possible output(s) are expected to be displayed on screen at the time of execution of the program from the following code?

import random
POINTS = [30, 50, 20, 40, 45]
BEGIN = random.randint(1, 3)
LAST = random.randint(2, 4)
for C in range(BEGIN, LAST + 1):
    print(POINTS[C], "#", end=" ")
SHOW ANSWER

Possible outputs:

      • 50#20#40#

 

      • 50#20#40#45#

 

      • 20#40#45#

2. (a) What is the advantage of super() function in inheritance? Illustrate the same with the help of an example in Python.

SHOW ANSWER

super() allows a class to call methods of its parent class. This avoids direct references to parent class names and enables easier management of inheritance.

class Parent:
    def display(self):
        print("Parent class")

class Child(Parent):
    def display(self):
        super().display()
        print("Child class")

C = Child()
C.display()

2. (b) Consider the following Python code and answer the questions below:

class Vehicle:
    Type = 'Car'
    def __init__(self, name):
        self.Name = name
    def Show(self):
        print(self.Name, Vehicle.Type)

V1 = Vehicle("BMW")
V1.Show()
Vehicle.Type = "Bus"
V2 = Vehicle("VOLVO")
V2.Show()
SHOW ANSWER

(i) The difference between variables in Line 2 and Line 4 is:

      • Line 2 (Type) is a class variable, shared by all instances.

 

      • Line 4 (Name) is an instance variable, unique to each instance.

(ii) The output of the code is:

BMW Car
VOLVO Bus

2. (c) Define a class CONTAINER in Python with the following specifications:

SHOW ANSWER
class CONTAINER:
    def __init__(self):
        self.Radius = 0
        self.Height = 0
        self.Type = 0
        self.Volume = 0
    
    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 = float(input("Enter Radius: "))
        self.Height = float(input("Enter Height: "))
        self.Type = int(input("Enter Type (1 or 3): "))
        self.CalVolume()
    
    def ShowContainer(self):
        print("Radius:", self.Radius)
        print("Height:", self.Height)
        print("Type:", self.Type)
        print("Volume:", self.Volume)

C = CONTAINER()
C.GetValue()
C.ShowContainer()

2. (d) Answer the questions (i) to (iv) based on the following code:

class Top1(object):
    def __init__(self, tx):
        self.X = tx
    def ChangeX(self, tx):
        self.X = self.X + tx
    def ShowX(self):
        print(self.X)

class Top2(object):
    def __init__(self, ty):
        self.Y = ty
    def ChangeY(self, ty):
        self.Y = self.Y + ty
    def ShowY(self):
        print(self.Y, end=" ")

class Bottom(Top1, Top2):
    def __init__(self, tz):
        self.Z = tz
        Top2.__init__(self, 2 * tz)
        Top1.__init__(self, 3 * tz)
    def ChangeZ(self, tz):
        self.Z = self.Z + tz
        self.ChangeY(2 * tz)
        self.ChangeX(3 * tz)
    def ShowZ(self):
        print(self.Z, end=" ")
        self.ShowY()
        self.ShowX()

B = Bottom(1)
B.ChangeZ(2)
B.ShowZ()
SHOW ANSWER

(i) The type of inheritance is Multiple Inheritance.

(ii) The output is:

3 6 9

(iii) The methods in Line 1, Line 3, and Line 5 are known as constructors.

(iv) The difference between Line 6 and Line 7: Line 6 initializes the Z attribute in the Bottom class, while Line 7 calls the constructor of Top2 and initializes its Y attribute.

3. (a) Consider the following randomly ordered numbers stored in a list: 786, 234, 526, 132, 345, 467. Show the content of the list after the First, Second, and Third pass of the bubble sort method used for arranging in ascending order.

SHOW ANSWER

First Pass: [234, 526, 132, 345, 467, 786]

Second Pass: [234, 132, 345, 467, 526, 786]

Third Pass: [132, 234, 345, 467, 526, 786]

3. (b) Write the definition of a method ZeroEnding(SCORES) to add all those values in the list of SCORES, which are ending with zero (0) and display the sum.

SHOW ANSWER
def ZeroEnding(SCORES):
    total = 0
    for score in SCORES:
        if score % 10 == 0:
            total += score
    print("Sum of values ending with 0:", total)

# Example usage:
ZeroEnding([200, 456, 300, 100, 234, 678])

Output: 600

3. (c) Write AddClient(Client) and DeleteClient(Client) methods in Python to add a new Client and delete a Client from a List of Client Names, considering them to act as insert and delete operations of the queue data structure.

SHOW ANSWER
class ClientQueue:
    def __init__(self):
        self.clients = []
    
    def AddClient(self, client):
        self.clients.append(client)
    
    def DeleteClient(self):
        if self.clients:
            return self.clients.pop(0)  # Dequeue
        else:
            return "Queue is empty"

# Example usage:
queue = ClientQueue()
queue.AddClient("Client1")
queue.AddClient("Client2")
queue.DeleteClient()

3. (d) Write a definition of a method COUNTNOW(PLACES) to find and display those place names, in which there are more than 5 characters.

SHOW ANSWER
def COUNTNOW(PLACES):
    for place in PLACES:
        if len(place) > 5:
            print(place)

# Example usage:
COUNTNOW(["DELHI", "LONDON", "PARIS", "NEW YORK", "DUBAI"])

Output:

      • LONDON

 

      • NEW YORK

3. (e) Evaluate the following Postfix notation of expression: 22, 11, /, 5, 10, *, +, 12, -

SHOW ANSWER

The postfix expression is evaluated as:

        22 / 11 = 2
        5 * 10 = 50
        2 + 50 = 52
        52 - 12 = 40

Final Result: 40

4. (a) Write a statement in Python to open a text file STORY.TXT so that new contents can be added at the end of it.

SHOW ANSWER
file = open("STORY.TXT", "a")  # 'a' mode to append

4. (b) Write a method in Python to read lines from a text file INDIA.TXT, to find and display the occurrence of the word “India.”

SHOW ANSWER
def CountIndia():
    count = 0
    with open("INDIA.TXT", "r") as file:
        for line in file:
            count += line.lower().count("india")
    print("The word 'India' appeared", count, "times")

# Example usage:
CountIndia()

4. (c) Considering the following definition of class MULTIPLEX, write a method in Python to search and display all the contents in a pickled file CINEMA.DAT, where MTYPE is matching with the value ‘Comedy’.

class MULTIPLEX:
    def __init__(self, mno, mname, mtype):
        self.MNO = mno
        self.MNAME = mname
        self.MTYPE = mtype
    def Show(self):
        print(self.MNO, "*", self.MNAME, "$", self.MTYPE)
SHOW ANSWER
import pickle

def SearchComedy():
    with open("CINEMA.DAT", "rb") as file:
        try:
            while True:
                multiplex = pickle.load(file)
                if multiplex.MTYPE == "Comedy":
                    multiplex.Show()
        except EOFError:
            pass

# Example: 
# SearchComedy() will display all records where MTYPE is "Comedy".

Section C – Database and Boolean Algebra

5. (a) Observe the following tables VIDEO and MEMBER carefully and write the name of the RDBMS operation out of SELECTION, PROJECTION, UNION, CARTESIAN PRODUCT, which has been used to produce the output. Also, find the Degree and Cardinality of the final result.

SHOW ANSWER

Operation Used: CARTESIAN PRODUCT

Degree: 5

Cardinality: 9

5. (b) Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii) based on the following tables:

Table: ACCOUNT

ANO ANAME ADDRESS
101 Nirja Singh Bangalore
102 Rohan Gupta Chennai
103 Ali Reza Hyderabad
104 Rishabh Jain Chennai
105 Simran Kaur Chandigarh

Table: TRANSACT

TRNO ANO AMOUNT TYPE DOT
T001 101 2500 Withdraw 2017-12-21
T002 103 3000 Deposit 2017-06-01
T003 102 2000 Withdraw 2017-05-12
T004 103 1000 Deposit 2017-10-22
T005 101 12000 Deposit 2017-11-06
SHOW ANSWER

(i)

SELECT * FROM TRANSACT WHERE TYPE = 'Deposit';

(ii)

SELECT ANO, AMOUNT FROM TRANSACT WHERE DOT BETWEEN '2017-10-01' AND '2017-10-31';

(iii)

SELECT MAX(DOT) FROM TRANSACT WHERE ANO = 103;

(iv)

SELECT ACCOUNT.ANO, ANAME, DOT FROM ACCOUNT JOIN TRANSACT ON ACCOUNT.ANO = TRANSACT.ANO WHERE AMOUNT <= 3000;

6. (a) State any one Absorption Law of Boolean Algebra and verify it using a truth table.

SHOW ANSWER

Absorption Law: A + (A.B) = A

Truth Table:

| A | B | A.B | A + (A.B) |
|---|---|-----|-----------|
| 0 | 0 |  0  |     0     |
| 0 | 1 |  0  |     0     |
| 1 | 0 |  0  |     1     |
| 1 | 1 |  1  |     1     |

6. (b) Draw the Logic Circuit of the following Boolean Expression: (U’ + V).(V’ + W’)

SHOW ANSWER

The logic circuit is drawn as follows:

      • A NOT gate for U’ and V’

 

      • OR gates for (U’ + V) and (V’ + W’)

 

      • AND gate combining the results of both OR gates

6. (c) Derive a Canonical POS expression for a Boolean function FN, represented by the following truth table:

| X | Y | Z | FN(X, Y, Z) |
|---|---|---|-------------|
| 0 | 0 | 0 | 1           |
| 0 | 0 | 1 | 1           |
| 0 | 1 | 0 | 0           |
| 0 | 1 | 1 | 0           |
| 1 | 0 | 0 | 1           |
| 1 | 0 | 1 | 0           |
| 1 | 1 | 0 | 0           |
| 1 | 1 | 1 | 1           |
SHOW ANSWER

The Canonical POS expression is derived as:

(X + Y' + Z')(X + Y' + Z)(X' + Y + Z)(X' + Y + Z')

6. (d) Reduce the following Boolean Expression to its simplest form using K-Map: G(U, V, W, Z) = Σ(3, 5, 6, 7, 11, 12, 13, 15)

SHOW ANSWER

After constructing the K-Map and grouping the ones, the simplified expression is:

G(U, V, W, Z) = U'W + VZ'

7. (a) Differentiate between Bus Topology and Star Topology of Networks. What are the advantages and disadvantages of Star Topology over Bus Topology?

SHOW ANSWER

Bus Topology: All devices share a single communication line. If the main cable fails, the whole network goes down.

Star Topology: All devices are connected to a central hub. If one device fails, others are unaffected, but if the hub fails, the entire network goes down.

Advantages of Star Topology: Easier to manage and troubleshoot. More reliable as failure in one device does not affect the network.

7. (b) Classify each of the following Web Scripting languages as Client-Side Scripting or Server-Side Scripting:

      • JavaScript

 

      • ASP

 

      • VBScript

 

      • JSP
SHOW ANSWER
      • JavaScript – Client-Side Scripting

 

      • ASP – Server-Side Scripting

 

      • VBScript – Client-Side Scripting

 

      • JSP – Server-Side Scripting

7. (c) Write the expanded names for the following abbreviated terms used in Networking and Communications:

      • SMTP

 

      • VoIP

 

      • GSM

 

      • WLL
SHOW ANSWER
      • SMTP – Simple Mail Transfer Protocol

 

      • VoIP – Voice over Internet Protocol

 

      • GSM – Global System for Mobile Communications

 

      • WLL – Wireless Local Loop

7. (d) Case Study Based Question:
Ayurveda Training Educational Institute is setting up its center in Hyderabad with four specialized departments for Orthopedics, Neurology, Pediatrics, and an Administrative Office in separate buildings. The physical distances between these department buildings and the number of computers to be installed in these departments and administrative office are given below. You, as a network expert, have to answer the queries as raised by them in (i) to (iv).

Shortest distances between various locations in meters:

Locations Distance (m)
Administrative Office to Orthopedics Unit 55
Neurology Unit to Administrative Office 30
Orthopedics Unit to Neurology Unit 70
Pediatrics Unit to Neurology Unit 50
Pediatrics Unit to Administrative Office 40
Pediatrics Unit to Orthopedics Unit 110

Number of Computers installed at various locations:

Locations Number of Computers
Pediatrics Unit 40
Administrative Office 140
Neurology Unit 50
Orthopedics Unit 80

As a network expert, answer the following:

(i)

      1. Suggest the most suitable location to install the main server of this institution to get efficient connectivity.

(ii)

      1. Suggest the best cable layout for effective network connectivity of the building having the server with all the other buildings.

(iii)

      1. Suggest the devices to be installed in each of these buildings for connecting computers installed within the building out of the following: Gateway, Modem, Switch.

(iv)

      1. Suggest the topology of the network and network cable for efficiently connecting each computer installed in each of the buildings out of the following:

(a)

        • Topologies: Bus Topology, Star Topology

(b)

        • Network Cable: Single Pair Telephone Cable, Coaxial Cable, Ethernet Cable
SHOW ANSWER

(i) The most suitable location to install the main server would be the Administrative Office since it has the highest number of computers and is centrally located with respect to other departments.

(ii) The best cable layout would be a Star Topology with the server at the Administrative Office. Ethernet cables would connect the Administrative Office to each department building individually.

(iii) The appropriate device to be installed in each building for connecting computers is a Switch, as it efficiently connects multiple computers within the same building.

(iv) The recommended network topology for this scenario is the Star Topology using Ethernet Cable for faster and more reliable connectivity.

Disclaimer

The question bank provided on this website is meant to be a supplementary resource for final term exam preparation. While we strive to offer accurate and relevant content, students should not rely solely on these answers. It is essential to conduct further research and consult teachers, school authorities, or subject experts to ensure thorough understanding and preparation. The solutions here are based on general interpretations and may not reflect the exact responses expected by examination boards. We are not responsible for any discrepancies or outcomes in exams resulting from the use of this material. By using this resource, you acknowledge that your academic success depends on comprehensive preparation, including active engagement with school materials and guidance from educators.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More