Page 13 - C++
P. 13
Q3 (a) Write the definition of a function Reverse(X) in Python, to display the elements in 2
reverse order such that each displayed element is the twice of the original element
(element * 2) of the List X in the following manner:
Example:
If List X contains 7 integers is as follows:
X[0] X[1] X[2] X[3] X[4] X[5] X[6]
4 8 7 5 6 2 10
After executing the function, the array content should be displayed as follows:
20 4 12 10 14 16 8
(b) Consider the following unsorted list : 3
[22, 54, 12, 90, 55, 78]
rd
Write the passes of selection sort for sorting the list in ascending order till the 3
iteration.
(c) Consider the following class Order and do as directed: 4
Blank 1
:
:
i. Fill in the blank 1 with a statement to insert OID in the Queue maintained using List
L.
ii. Complete the definition of delorder() to delete OID from the Queue maintained using
List L, the function should return the OID being deleted or -1 in case the Queue is empty.
d) Write a generator function to generate odd numbers between a and b(including b).Note: a 3
and b are received as an argument by the function.
(e) Evaluate the following postfix expression using a stack. Show the contents of stack after 2
execution of each operation:
10,40,25,-,*,15,4,*,+
Q4. (a) Nancy intends to position the file pointer to the beginning of a text file. Write Python 1
statement for the same assuming F is the File object.
(b) Write a function countmy( )in Python to read the text file “DATA.TXT” and count the
number of times “my” occurs in the file.
For example if the file “DATA.TXT” contains: 2
“This is my website. I have displayed my preferences in the CHOICE section.”
The countmy( ) function should display the output as:
“my occurs 2 times”.
(c) Write a function in python to search and display details of all those students, whose 3
stream is “HUMANITIES” from pickled file “Student.dat”. Assuming the pickled file is
containing the objects of the following class:
Page No. 11