By QB365 on 31 Dec, 2022
QB365 provides a detailed and simple solution for every Possible Questions in Class 12 Computer Science Subject - Revision Model Question Paper, English Medium. It will help Students to get more practice questions, Students can Practice these question papers in addition to score best marks.
12th Standard
Computer Science
PART-I
Note : i) All Questions Are Compulsory.
ii) Choose The Most Suitable Answer From The Given Four Correct Alternatives.
Which of the following is a distinct syntactic block?
Subroutines
Function
Definition
Modules
The data type whose representation is unknown are called
Built in datatype
Derived datatype
Concrete datatype
Abstract datatype
Two main measures for the efficiency of an algorithm are
Processor and memory
Complexity and capacity
Time and space
Data and space
The condition in the if statement should be in the form of
Arithmetic or Relational expression
Arithmetic or Logical expression
Relational or Logical expression
Arithmetic
Which of the following keyword is used to define the function testpython(): ?
define
pass
def
while
Pick odd one in connection with collection data type
List
Tuple
Dictionary
Loop
Which of the following method is automatically executed when an object is created?
__object__( )
__del__( )
__func__( )
__init__( )
Who developed ER model?
Chen
EF Codd
Chend
Chand
Which of the following module is provided by Python to do several operations on the CSV files?
py
xls
csv
os
getopt() will return an empty array if there is no error in splitting strings to
argv variable
opt variable
args variable
ifile variable
Which is a python package used for 2D graphics?
matplotlib.pyplot
matplotlib.pip
matplotlib.numpy
matplotlib.plt
The function definition is introduced by the keyword
def
rec
let
infer
Which of the following gives an implementation independent view?
Abstract
Concrete
Datatype
Behavior of an object
Which of the following is not a variable scope?
Global
Enclosed
List
Built-in
Which of the following is not an example of data structures?
Control statement
Structure
List
Dictionary
PART-II
Note : i ) Answer Any Six Questions and Question.no: 24 is compulsory.
Differentiate constructors and selectors.
How Python represents the private and protected Access specifiers?
What is Sorting?
What will be the output of the following python code?
str1 = “School”
print(str1*3)
How will you sort more than one column from a csv file?Give an example statement.
Define Arguments.
What is meant by list literal?
Write the output of the following program
a:=10
Disp():
a:=7
print a
Disp 1():
print a
What is pair? Give an example.
PART-III
Note : i ) Answer Any Six Questions and Question.no: 33 is compulsory.
Identify Which of the following are constructors and selectors?
(a) N1:=number()
(b) accetnum (n1)
(c) displaynum (n1)
(d) eval (a/b)
(e) x,y:= make slope (m), make slope (n)
(f) display()
Write a program to display
A
A B
A B C
A B C D
A B C D E
What will be the output of the following code?
list = [2**x for x in range(5)]
print (list)
What is sys.argv? What does it contain?
Write the plot for the following pie chart output.
What are called access modifiers and give some details about it.
Write a Python programme to get the following output.
Output:
Enter Number 1: 50
Enter Number 2: 50
X = 50 Y = 50
How will you invoke the function after, the parameters are recognized by their parameter names? Explain with an example.
With an example program explain about membership operators?
PART-IV
Note : i ) Write all the following questions.
What are called Parameters and write a note on
(i) Parameter without Type
(ii) Parameter with Type
Explain the concept of Dynamic programming with suitable example.
Explain the different operators in Relational algebra with suitable examples.
Differentiate Excel file and CSV file.
Write the Python script to display all the records of the following table using fetchmany()
Icode | ItemName | Rate |
1003 | Scanner | 10500 |
1004 | Speaker | 3000 |
1005 | Printer | 8000 |
1008 | Monitor | 15000 |
1010 | Mouse | 700 |
Explain the sorting algorithm that uses n-1 number passes to get the final sorted list.
Write the output for the following python code..
x=10
x+=20
print ("The x + = 20 is =",x)
x-=5
print ("The x -= 5 is = ",x)
x*=5
print ("The x *= 5 is = ",x)
x/=2
print ("The x/ = 2 is = ",x)
x%=3
print ("The x %= 3 is = ",x)
x**=2
print ("The x **= 2 is = ",X)
x//=3
print ("The x//= 3 is = ",x)
Create a program to specify global variable and local variable in same code and also with same name.
Differentiate between clear( ) and del Statement.
Write a python program to execute the following C++ program.
/*. To check whether the number is palindrome or not using while Ioop.*/
// Now select File →New in Notepad and type the C++ program
#include < iostream >
using namespace std;
intmain ( )
{
int n, num, digit, rev = 0;
cout<< "Enter a positive number: ";
cin >>num;
n= num;
while(num)
{digit = num % 10;
rev = (rev * 10) + digit;
num = num / 10; }
cout<< "The reverse of the number is: " << rev <<endl;
if(n == rev)
cout< < "The number is a palindrome";
else
cout << "The number is not a palindrome";
return 0;
}
// Save this file as pali_cpp.cpp
Answers
Definition
Abstract datatype
Time and space
Relational or Logical expression
def
Loop
__init__( )
Chen
csv
argv variable
matplotlib.pyplot
let
Abstract
List
Control statement
S.No | Constructors | Selectors |
(i) |
Constructors are functions that build the abstract data type. |
Selectors are functions that retrieve information from the data type. |
(ii) | Constructors create an object, bundling together different pieces of information. | Selectors extract individual pieces of information from the object |
Python prescribes a convention of prefixing the name of the variable or method with single or double underscore to emulate the behavior of protected and private access specifiers.
Example: self_n2 = n2
Sorting is a method of arranging group of items in ascending or descending order. Various sorting techniques in algorithms are Bubble sort, Quick sort, Heap sort, Selection sort, Insertion sort.
Output : School School School
To sort by more than one column you can use itemgetter with multiple indices:
operator.itemgetter
Example:
sortedlist = sorted (data, key = operator. itemgetter(1))
Arguments are the values which are passed to a function definition.
List is constructed by placing an expression within square brackets separated by commas. Such an expression is called a list literal.
The output of the program
7
10
The duration for which a variable is alive is called life time.
(a) Constructors
(b) Selectors
(c) Selectors
(d) Selectors
(e) Constructors
(f) Selectors
for i in range (1, 6) :
for j in range (65, 65 + i)
a = chr(j)
print a
print
Output: [1,2,4,8,16]
sys.argv is the list of command-line arguments passed to the Python program. argv contains all the items that come along via the command-line input, it's basically an array holding the command-line arguments of the program.
To use syss.argv, we will first have to import sys. The first argument, sys.argv [0], is always the name of the program as it was invoked and sys.argv [1] is the first argument we pass to the program.
Example:
main (sys.argv [1]) - Accepts the program file and the input file as a list. argv[0] contains the python program which is need not to be passed because by default _main_contains source code reference and argv[1] contains the name of the C++ file which is to be processed.
Plot:
import matplotlib.pyplot as plt
sizes = [105, 30, 30, 195]
label= ["sleeping", "eating", "working", "playing"]
plt.pie (sizes, labels = labels, autopct = "%.2f")
plt, axes ( ). set_aspect ("equal")
plt.show ( )
The access modifiers are private, public and protected members.
Private members of a class are denied access from the outside the class. They can be handled only within the class.
Public members are accessible from outside the class. The object of the same class is required to invoke a public method. This arrangement of private instance variables and public methods ensures the principle of data encapsulation.
Protected members of a class are accessible from within the class and are also available to its sub-classes. No other process is permitted access to it. This enables specific resources of the parent class to be inherited by the child class.
x, y = int (input("Enter Number 1:")),
int (input ("Enter Number 2:" ))
print ("X =,x", " Y =, y" )
Output:
Enter Number 1 : 30
Enter Number 2 : 50
X= 30 Y = 50
(i) Keyword arguments will invoke the function after the parameters are recognized by their parameter names.
(ii) The value of the keyword argument is matched with the parameter name and so, one can also put arguments in improper order.
(iii) Example:
def printdata (name):
print ("Example-1 Keyword arguments")
print ("Name :",name)
return
# Now you can call printdatat() function
printdata(name = "Gshan")
When the above code is executed, it produces the following output:
Output:
Example-1 Keyword arguments
Name: Gshan
Membership Operators:
(i) The 'in' and 'not in' operators can be used with strings to determine whether a string is present in another string. Therefore, these operators are called as Membership Operators.
(ii) Example:
str1=input ("Enter a string:")
str2="chennai"
if str2 in str1:
print ("Found")
else:
print ("Not Found")
(iii) Output:1
Enter a string: Chennai GHSS, Saidapet
Found
(iv) Output:2
Enter a string: Govt GHSS, Ashok Nagar Not Found
Parameters and arguments:
Parameters are the variable in a function definition and arguments are the values which are passed to a function definition
(i) Parameter without Type: Let us see an example of a function,definition :
(requires: b >=0 )
(returns: a to the power of b)
let rec pow a b:=
if b=0 then 1
else a*powa(b-1)
(i) In the above function definition variable 'b' is the parameter and the value which is passed to the variable 'b' is the argument. The precondition (requires) and postcondition (returns) of the function is given.
(ii) Note we have not mentioned any types (data types). Some language computer solves this type (data type) inference problem algorithmically, but some require the type to be mentioned.
(iii) In, the above function deinition if expression can return 1 in the then branch, shows that as per the typing rule the entire if expression has type int
(iv) Since the if expression is of type 'int', the function's return type also be int. 'b' is compared to 0 with the equality operator. so 'b' is also a type of int: Since 'a' is multiplied with another expression using the operator, 'a' must be an int.
(ii) Parameter with Type: Now let us write the same function definition with types for some reasons:
(requires: b > 0 )
(returns: a to the power of b )
let rec pow (a:int) (b:int): int :=
if b=0 then 1
n else a * pow b (a-1)
(i) When we write the type annotations for ‘a’ and ‘b’ the parentheses are mandatory. Generally, we can leave out these annotations, because it's simpler to let the compiler infer them.
(ii) There are times we may want to explicitly write down types. This is useful on times when you get a type error from the compiler that doesn't make sense. Explicitly annotating the types can help with debugging such an error message.
(iii) The syntax to define functions is close to the mathematical usage: the definition is introduced by the keyword let followed by the name of the function and its arguments; then the formula that computes the image of the argumentis written atter an := sign. If you want to define a recursive function: use "let rec" instead of "let"
Syntax:The syntax for function detinitions: let irec fn al a2 ... an := k
(iv) Here the 'fn' is used as a function name. The nanmes 'a1' to 'an'are variables used as parameters. The keyword 'rec' is required if 'fn' is to be a recursive function; otherwise it may be omitted.
(i) Dynamic programming is an algorithmic design method that can be used when the solution to a problem can be viewed as the result of a sequence of decisions.
(ii) Dynamic programming approach is similar to divide and conquer. The given problem is divided into smaller and yet smaller possible sub-problems.
(iii) Dynamic programming is used whenever problems can be divided into similar subproblems. so that their results can be reused to complete the process.
(iv) Dynamic programming approaches are used to find the solution in optimized way. For every inner subproblem, dynamic algorithm will try to check the results of the previously solved sub-problems.
(v) The solutions of overlapped sub-problems are combined in order to get a better solution.
Steps to doDynamic programming :
(i) The given problem will be divided into smaller overlapping sub-problems.
(ii) An optimum solution for the given problem can be achieved by using result of smaller sub-problem.
(iii) Dynamic algorithms uses Memoization
Fibonacci Series - An example :
(i) Fibonacci series generates the subsequent number by adding two previous numbers. Fibonacci series starts from two numbers -Fib 0 & Fib 1. The initial values of Fib 0 & Fib l can be taken as 0 and 1.
(ii) Fibonacci series satisfies the following conditions:
Fibn = Fiba-1 + Fiba-2
(iii) Hence, a Fibonacci series for the n value 8 can look like this
Fib8 = 0 1 1 2 3 5 8 13
Fibonaeci Iterative Algorithm with Dynamic programning approach : The following example shows a simple Dynamic programning approach for the generation ot Fibonacci series.
Initialize f0 = 0, f1 = 1.
Step- 1: Print the initial values of Fibonacci f0 and f1
Step- 2: Calculate Fibonacci fib \(\leftarrow \) f0+ f1
Step- 3: Assign f0 \(\leftarrow \) f1, f1 \(\leftarrow \) fib
Step- 4: Print the next consecutive value of Fibonacci fib
Step- 5: Go to step-2 and repeat until the specified number of terms generated
Example:
if we generate Fibonacci series up to 10 digits, the algorithm will generate the series as shown below:
The Fibonacci series is:
0 1 1 2 3 5 8 13 21 34 55.
Relational Algebra is divided into various groups
Unary Relational Operations.
(i) SELECT (symbol: σ)
(ii) PROJECT ( symbol: π)
Relational Algebra Operations from Set Theory:
(i) UNION (U)
(ii) INTERSECTION (∩)
(iii) DIFFERENCE (-)
(iv) CARTESIAN PRODUCT (X)
SELECT (symbol: σ)
(i) General from σ (R) with a relation R and a condition C on the attributes of R
(ii) The SELECT operation is used for selecting a subset with tuples according to a given condition.
(iii) Select filters out all tuples that do not satisfy C
STUDENT:
Studio | Name | Course | Year |
---|---|---|---|
CS1 | Kannan | Big Data | II |
CS2 | Gowri Shankar | R language | I |
CS3 | Lenin | Big Data | I |
CS4 | Padmaja | Python Programming | I |
σ course = "Big Data" (STUDENT)
Studio | Name | Course | Year |
---|---|---|---|
CS1 | Kannan | Big Data | II |
2 | Lenin | Big Data | I |
PROJECT (symbol: II)
(i) The projection eliminates all attributes of the input relation but those mentioned in the projection list.
(ii) The projection method defines a relation that contains a vertical subset of Relation.
Example: 1
IIcourse (STUDENT)
Result:
Course |
Big Data |
R language |
Python Programming |
Example 2
IIstudent,course (STUDENT)
Result:
Stud no | Course |
CS1 | Big Data |
CS2 | R language |
CS3 | Big Data |
CS4 | Python Programming |
UNION (Symbol: U)
(i) It includes all tuples that are in tables A or in B. It also eliminates duplicates. Set A Union Set B would be expressed as A U B
Example 3:
Table A | |
---|---|
Studio | Name |
CS1 | Kannan |
CS2 | Lenin |
CS3 | Padmaja |
Table A | |
---|---|
Studio | Name |
CS1 | Kannan |
CS2 | Gowrishakaran |
CS3 | Lenin |
Result:
Table A | |
---|---|
Studio | Name |
CS1 | Kannan |
CS2 | Gowri Shakaran |
CS3 | Lenin |
CS4 | Padmaja |
SET DIFFERENCE (Symbol: -)
(i) The result of A - B, is a relation which includes all tuples that are in A but not in B.
(ii) The attribute name of A has to match with the attribute name in B.
Example: 4
using Table B Example 3
Result:
Table A - B | |
---|---|
CS4 | Padmaja |
INTERSECTION (symbol: ∩) A ∩ B:
(i) Defines a relation consisting of a set of all tuple that are in both in A and B. However, A and.B must be union-compatible.
Example: 5
Using Table in Example 3
Result:
Table A - B | |
---|---|
CS1 | Kannan |
CS3 | Lenin |
PRODUCT OR CARTESIAN PRODUCT (Symbol: X)
(i) Cross product is a way of combining two relations. The resulting relation contains, both relations being combined.
(ii) A x B means A times B, where the relation A and B have different attributes.
(iii) This type of operation is helpful to merge columns from two relations.
Excel | CSV |
---|---|
Excel is a binary file that holds information about all the worksheets in a file, including both content and formatting | CSV format is a plain text format with a series of values separated by commas. |
XLS files can only be read by applications that have been especially written to read their format, and can only be written in the same way. | CSV can be opened with any text editor in Windows like notepad, MS Excel, Open Office, etc. |
Excel is a spreadsheet that saves files into its own proprietary format viz. xls or xlsx | CSV is a format for saving tabular information into a delimited text file with extension .csv |
Excel consumes-more memory while importing data | Importing CSV files can be much faster, and it also consumes less memory |
Creating database:
Sql_command = " "
CREATE TABLE Hardware (
lcode INTEGER PRIMARY KEY.
ltem_Name VARCHAR(20),
Rate DEClMAL(5,2));" "
Program: To display the records using fetchmany()
import sqlite3
connection = sqlite3.connect ("Material.db")
cursor = connection.cursor()
cursor. execute ("SELECT * FROM Hardware")
print("fetching first 5 records:")
result = cursor.fetchmany(5)
print(result)
Output:
fetching first 5 records:
[(1003, 'Scanner', "10500'), (1004, 'Speaker', '3000'), (1005, 'Printer', '8000'), (1008, 'Monitor', '15000'),
(1010, 'Mouse', '700')]
(i) Insertion sort is a simple sorting algorithm. It works by taking elements from the list one by one and inserting then in their correct position in to a new sorted list.
(ii) This algorithm builds the final sorted array at the end. This algorithm uses n-1 number of passes to get the final sorted list as per the pervious algorithm as we have discussed.
Pseudo for Insertion sort:
Step 1 - If it is the first element, it is already sorted.
Step 2 - Pick next element
Step 3 - Compare with all elements in the sorted sub-list
Step 4 - Shift all the elements in the sorted sublist that is greater than the value to be sorted Step 5 - Insert the value Step 6 - Repeat until list is sorted.
Type a Value for X : 10
The x + = 20 is = 30
The x - = 5 is = 25
The x * = 5 is = 125
The x / = 2 is = 62.5
The x % = 3 is = 2.5
The x ** = 2 is = 6.25
The x// = 3 is = 2.0
Using Global and Local variables in same code:
x = 8 #x is a global variable.
def loc( ):
global x
y = "local"
x = x * 2
print (x)
print (y)
loc( )
Output:
16
local
We declare x as global and y as a local variable in the function loc( )
After calling the function loc( ) , the value of x becomes 16 because we used, x = x*2.Print the value of local variable y i.e., local.
Example:
Global variable and Local variable with same name:
x = 5
def loc( ):
x = 10
print ("local x:",x)
loc( )
print ("local x:",x)
Output:
local x: 10
global x: 5
local x: 10, is called the local scope of the variable
global x: 5, is called the global scope of the variable.
Clear( ) | del statement |
Used to delete all the elements in list, it deletes only the elements and retains the list | del statement deletes entire list |
Syntax for i) remove () ii) Pop() iii) clear ()
i) remove()
Syntax:
List.remove(element) #to delete a particular element
ii) pop():
Syntax:
List.pop(index of an element)
iii) clear()
Syntax:
list.clear()
Example:
> Mylist = [12, 89, 34, 'Kannan', 'Gowri sankar', 'Lenin')
>print(Mylist)
[12, 89, 34, 'Kannan', 'Gowri sankar', 'Lenin']
>> Mylist. remove(89)
>>>print (Mylist)
[12,34, 'Kannan; 'Gowri sankar', Lenin']
In the above example, Mylist has been created with three integer and three string elements, the print statement shows all the elements available in the list. In the statement >>> Mylist. remove (89), deletes the element 89 from the list and the print statement shows the remaining elements.
Example:
>>> Mylist.pop(1)
34
> print (Mylist)
[12, 'Kannan', 'Gowrisankar', 'Lenin']
pop() function is used to delete a particular element using its index value, as soon as the element is deleted, the pop( ) function shows the element which is deleted. pop() function is used to delele only one element from a list
Example:
> MyList. clear()
>>>print(MyList)
[ ]
clear( ) function removes only the elements and retains the list. To print the list which is already cleared, an empty square bracket is displayed.
# Save the File as pali.py . Program that compiles and executes a .cpp file
# Python c:\pyprg\pali.py -i c:\pyprg\pali_cpp import sys, os, getopt
def main(argv):
cpp_file ="
exe_file = "
opts, args= getopt.getopt(argv, "i:",['ifile='])
for o, a in opts:
if o in ("-i", "--ifile"):
cpp_file = a + '.cpp'
exe_file = a + '.exe'
run(cpp_file, exe_file)
def run(cpp_file, exe_file):
print("Compiling" + cpp_file)
os.system('g++' + cpp_file + '-o' + exe_file)
print("Running" + exe_file)
print("-----------------")
print
os.system(exe_file)
print
if __name__ =='__main__': # program starts executing from here
main(sys.argv[ 1:])