computer - Kendriya Vidyalaya Barrackpore(Army)

advertisement
Page 1 of 99
KENDRIYA VIDYALAYA SANGATHAN (KOLKATA REGION)
CLASS-XII
SUBJECT: COMPUTER SCIENCE (083)
TOPIC: DATA STRUCTURES, ARRAY, STACK, QUEUE (Important Questions)
SUBMITTED BY: MRS. RANJITA SARKAR (MONDAL),
PGT (COMP.SCI.),
K. V. GARDEN REACH.
UNIT 2: DATA STRUCTURES
CHAPTER 1: ARRAYS
SINGLE DIMENSION ARRAY
1.
Write the definition of a function Change (int P [ ], int N) in C++, which should change all [2]
the multiples of 10 in the array to 10 and rest of the elements as 1. For example, if an array
of 10 integers is as follows :
[2015]
After executing the function, the array content should be changed as follows : P[0]
2.
Write code for a function void EvenOdd ( int T[ ], int C ) in C++, to add 1 in all the odd
values and 2 in all the even values of the array T.
Example : If the original content of the array T is
[3]
[2014]
[3]
[2013]
The modified content will be :
3.
Write the definition for a function void Transfer (int A [6], int B [6] ) in C++, which takes
two integer arrays, each containing 6 elements as parameters. The function should
exchange all odd places (1st, 3rd and 5th ) of the two arrays, for example
If the array A contains
and if the array B contains
Page 2 of 99
Then the function should make the contents of the array A as
And the contents of array B as
4.
Write a function SWAP2BEST (int ARR [ ], int Size) in C++ to modify the content of the [3]
array in such a way that the elements, which are multiples of 10 swap with the value
present in the very next position in the array.
For example :
If the content of array ARR is
90, 56, 45, 20, 34, 54
The content of array ARR should become
56, 90, 45, 34, 20, 54
[2012]
5.
Write a Get1From2 ( ) function in C++ to transfer the content from two arrays FIRST [ ] [3]
and SECOND [ ] to array ALL [ ]. The even places (0, 2, 4 ...) of array ALL [ ] should get
the content from the array FIRST [ ] and odd places (1, 3, 5,) of the array ALL [ ] should
get the content from the array SECOND [ ].
Example:
If the FIRST [ ] array contains
30, 60, 90
And the SECOND[ ] array contains
10, 50, 80
The ALL [ ] array should contain
30, 10, 60, 50, 90, 80
[2011]
6.
Write a function CHANGE( ) in C++, which accepts an array of integer and its size as [3]
parameters and divide all those array elements by 7 which are divisible by 7 and multiply
other-array elements by 3.
Sample Input Data of the array
[2010]
Content of the array after Calling CHANGE() function
7.
Given two arrays A and B. Array A contains all the elements of „B‟ but one more element
extra. Write a C++ function which accepts array A and B and its size as arguments /
parameters and find out the extra element in Array A. (Restriction: array elements are not
in order)
[3]
[2009]
Page 3 of 99
Example:
If Array A is {14, 21, 5, 19, 8, 4, 23, 11}
and Array B is {23, 8, 19, 4, 14, 11, 5 }
Then output will be 5 (extra element in Array A)
8.
Write a function in C++ which accepts a integer array and its size as an arguments and
prints the output (using nested loops) in following format :
Example : if the array is having
12459
Then the output should be
1
22
4444
55555
999999
[4]
[2008]
9.
Write a function in C++ which accepts an integer array and its size.as arguments and [4]
replaces elements having even values with its half and elements having odd values with
twice its value.
Example : if an array of five elements initially contains the elements as
3, 4, 5, 16, 9
then the function should rearrange the content of the array as
6, 2, 10, 8, 18
[2007]
10.
Write a function in C++ which accepts an integer array and its size as arguments / [4]
parameters and then assigns the elements into a two dimensional array of integers in the
following format:
If the array is 1, 2, 3, 4, 5, 6
The resultant 2 D array is given below
0 0 0 0 0 1
0 0 0 0 2 1
0 0 0 3 2 1
0 0 4 3 2 1
0 5 4 3 2 1
6 5 4 3 2 1
If the array is 1, 2, 3
The resultant 2 D array is given below
0 0 1
0 2 1
3 2 1
[2006]
11.
Write a function bubble sort to sort the passed array of 10 integers in descending order
using bubble sort.
[2006]
[2]
Page 4 of 99
TWO DIMENSIONAL ARRAY
1.
Write a function REVROW (int P [ ] [5], int N, int M) in C++ to display the content of a [3]
two dimensional array, with each row content in reverse order.
For example, if the content of array is as follows :
15 12 56 45 51
13 91 92 87 63
11 23 61 46 81
The function should display output as:
51 45 56 12 15
63 87 92 91 13
81 46 61 23 81
[2015]
2.
Write a user-defined function AddEnd2 (int A [ ] [4], int N, int M) in C++ to find and [2]
display the sum of all the values, which are ending with 2 (i.e., units place is 2).
For example if the content of array is :
22 16 12
19 5 2
The output should be 36.
[2014]
3.
Write a user-defined function int SumSingle ( int A [4] [4] ) in C++, which finds and [2]
returns the sum of all numbers present in the first row of the array, for example, if the array
contains
[2013]
Then the function should return 33.
4.
Write a function ALTERNATE ( int A [ ] [ 3 ], int N, int M ) in C++ to display all alternate
elements from two-dimensional array A (starting from A [ 0 ] [ 0 ] ).
For example : If the array is containing :
23 54 76
37 19 28
62 13 19
The output will be
23 76 19 62 19
[2]
[2012]
5.
Write a COLSUM ( ) function in C++ to find sum of each column of a N x M Matrix.
[2]
[2011]
Page 5 of 99
6.
Write a function int SKIPSUM (int A [ ] [3], int N,int M) in C++ to find and return the sum
of elements from all alternate elements of a two-dimensional array starting from A[0][0].
Hint:
If the following is the content of the array
[2]
[2010]
Write a function in C++ which accepts an integer array and its size as arguments / [3]
parameters and assigns the elements into a two dimensional array of integers in the
following format.
if the array is 9,8,7,6,5,4 The resultant 2D array is given below
[2009]
The function SKIPSUM() should add elements A[0][0], A[0][2], A[1][l],
A[2][0] and A[2][2].
25.
if the array is 1, 2, 3
The resultant 2D array is given below
31.
Write a function in C++ which accepts a 2D array of integers and its size as arguments and
displays the elements of middle row and the elements of middle column.
[Assuming the 2D Array to be a square matrix with odd dimension i.e. 3×3, 5×5, 7×7 etc...]
Example, if the array content is
354
769
218
Output through the function should be :
Middle Row : 7 6 9
Middle Column : 5 6 1
[2]
[2007]
Page 6 of 99
MEMORY ADDRESS CALCULATION
2.
A two dimensional array ARR [50] [20] is stored in the memory along the row with each of [3]
its elements occupying 4 bytes. Find the address of the element ARR [30] [10], if the
element ARR [10] [5] is stored at the memory location 15000.
[2015]
6.
An array A[20][30] is stored along the row in the memory with each element requiring 4 [3]
bytes of storage. If the base address of array A is 32000, find out the location of A[15][10].
Also, find the total number of elements present in this array.
[2014]
10.
An array S [10] [15] is stored in the memory with each element requiring 2 bytes of [3]
storage. If the base address of array S is 25000, determine the location of S [5] [10] if the
array S is stored along the column.
[2013]
14.
An array T [20] [10] is stored in the memory along the column with each of the elements
occupying 2 bytes. Find out the memory the memory location of T [10] [5], if the element
T [2] [9] is stored at the location 7600.
[3]
[2012]
18.
An array P[20] [50] is stored in the memory along the column with each of its
element occupying 4 bytes, find out the 1ocation of P[15][10], if P[0][0] is
stored at 5200.
[2]
[2011]
22.
An array P[50][60] is stored in the memory along the column with each of the
element occupying 2 bytes, find out the memory location for the element P[10]
[20], if the Base Address of the array is 6800.
[3]
[2010]
26.
Each element of an array DATA[10][10] requires 8 bytes of storage. If base address of
array DATA is 2000, determine the location of DATA[4][5], when array is stored
(i)
Row-wise.
(ii)
Column-wise
[4]
[2009]
28.
An array A[10][20] is stored in the memory with each element occupying 2 bytes of
storage. If the Base address of array in the memory is 800 , determine the location of
A[9][10] when the array is stored as (i) Row Major (ii) column major.
[3]
[2008]
30.
An array Arr[15][20] is stored in the memory along the row with each element
occupying 4 bytes. Find out the Base Address and address of the element Arr[3][2],
if the element Arr[5][2] is stored at the address 1500.
[4]
[2007]
33.
An array MAT [15] [7] is stored in the memory along the column with each element [4]
occupying 2 bytes of memory. Find out the base address and the address of element MAT
[2] [5], if the location of MAT [5] [4] is stored at the address 100.
[2006]
Page 7 of 99
CHAPTER 2: STACK
1.
Write the definition of a member function PUSH( ) in C++, to add a new book in a [4] [2015]
dynamic stack of BOOKS considering the following code is already included in the
program :
struct BOOKS
{ char ISBN[20], TITLE[80];
BOOKS *Link;
};
class STACK
{ BOOKS *Top;
public:
STACK(){Top=NULL;}
void PUSH();
void POP();
~STACK();
};
2.
Convert the following Infix expression to its equivalent Postfix expression, showing the [2] [2015]
stack contents for each step of conversion : U * V + R / ( S – T )
3.
Evaluate the following postfix expression. Show the status of stack after execution of each [2] [2014]
operation separately : T, F, NOT, AND, T, OR, F, AND
4.
Write a function PUSHBOOK ( ) in C++ to perform insert operation on a Dynamic Stack, [4] [2014]
which contains Book_no and Book_Title. Consider the following definition of NODE,
while writing your C++ code.
struct NODE
{ int Book_No;
char Book_Title[20];
NODE *Next;
};
5.
Evaluate the following postfix expression using a stack and show the contents of stack
after execution of each operation: 5, 3, 2, *, 4, 2, /, -, *
[2] [2013]
6.
Write a function in C++ to perform Insert operation in a static circular Queue containing
Book’s information (represented with the help of an array of structure BOOK).
struct BOOK
{ long Accno;
// Book Accession Number
Char Title [20]; // Book Title
};
[4] [2012]
Page 8 of 99
7.
Evaluate the following POSTFIX notation. Show status of Stack after every step of
evaluation (i.e. after each operator): True, False, NOT, AND, False, True, OR, AND
[2] [2012]
8.
Evaluate the following postfix notation of expression:
[2] [2011]
9.
Write a complete program in C++ to implement dynamically allocated Stack containing
names of Countries.
50, 60, + , 20, 10, -, *
[4] [2010]
10. Evaluate the following postfix notation of expression: (Show status of Stack after each
operation) False, True, NOT, OR, True, False, AND, OR
[2] [2010]
11. Write the function to perform push and pop operation on a dynamically allocated stack of
customers implemented with the help of the following structure:
struct employee
{ int eno;
char ename[20];
employee *link;
};
[4] [2009]
12. Evaluate the following postfix notation of expression: 5, 11, , 6, 8, +, 12, *, /
[2] [2009]
13. Consider the following portion of a program , which implements a linked stack for [3] [2008]
Library. Write the definition of function PUSH(),to insert a new node in the stack with
required information.
struct Library
{
int id;
char names[20];
};
class stack
{
Library *top;
public :
stack() {
top=NULL; }
void PUSH();
void POP();
};
14. Convert the following infix expression into postfix. show the stack status after execution
of each operation: TRUE OR FALSE AND NOT FALSE OR FALSE
[2] [2008]
15. Evaluate the following postfix notation of expression :
15 3 2 + / 7 + 2 *
[2] [2007]
Page 9 of 99
16. Evaluate the following postfix expression using a stack and show the contents of the stack
after execution of each operation. 5, 10, *, 20, 2, /, +
[2] [2006]
CHAPTER 3: QUEUE
1. Give the necessary declaration of linked implemented Queue containing players information [4] [2013]
(as defined in the following definition of Node). Also write a user defined function in C++ to
delete one Player’s information from the Queue.
struct Node
{ int PlayerNo;
char PlayerName[20];
Node *Link;
}
2. Write a function in C++ to perform Insert: operation on a dynamically allocated Queue [4] [2011]
containing Passenger details as given in the following definition of NODE.
struct NODE
{ long Pno;
//passenger Number
char Pname[20] ; //passenger Name
NODE *Link.;
};
3. Write a function in C++ to delete a node containing names of student , from a dynamically [3] [2008]
allocated Queue of names implemented with the help of following structure :
struct student
{
char name[20];
student *next;
} *front , *rear;
4. Write a function in C++ to delete a node containing customer’s information, from a [4] [2007]
dynamically allocated Queue of Customers implemented with the help of the following
structure :
struct Customer
{ int CNo;
char CName[20];
Customer *Link;
};
5. What is circular queue? How is it different from simple queue? Write a function in C++ to [4] [2006]
perform Delete operation in dynamically allocated Queue containing names of students.
Page 10 of 99
QUESTION BANK OF COMPUTER SCIENCE
BOOLEAN ALGEBRA (Chapter -13)
1.
[CBSE-2015]
[2]
a. Verify the following using Boolean Laws :
U’+V = U’V’+ U’.V + U.V
b. Draw the Logic Circuit for the following Boolean Expression :
(X’+Y).W’Z
c. Derive a Canonical POS expression for a Boolean function F,
Represented by the following truth table :
P
Q
R
F(P,Q,R)
0
0
0
1
0
0
1
0
0
1
0
0
0
1
1
1
1
0
0
1
1
0
1
0
1
1
0
0
1
1
1
1
[2]
[1]
d. Reduce the following Boolean Expression to its simplest form
using K-Map :
[3]
F(X,Y,Z,W)=∑ (0,1,4,5,6,7,8,9,11,15)
2.
[CBSE-2014]
a.
b.
Name the law shown below and verify it using a truth table.
X+X’.Y=X+Y
Obtain the Boolean Expression for the logic circuit shown below :
[2]
[2]
Page 11 of 99
c. Write the Product of Sum form of the function F(X, Y, Z) for the following truth table representation of
F:
[1]
X
0
0
0
0
1
1
1
Y
0
0
1
1
0
0
1
Z
0
1
0
1
0
1
0
F
1
0
0
1
0
0
1
1
1
1
1
d. Obtain the minimal form for the following Boolean expression using Karnaugh’s
Map :
[3]
F(A,B,C,D)= ∑ (1,3,4,5,6,7,12,13)
3.
a. Verify the following using Boolean laws
[CBSE 2013] [2]
A+C=A=A+A’.C+B.C
b. Obtain the Boolean expression for the logic circuit shown below –
[2]
c. Write the product of sum form of the function G(U,V,W) for the following truth table
representation of G
[1]
U
V
W
G
0
0
0
1
0
0
1
0
0
1
0
1
0
1
1
0
1
0
0
1
1
0
1
0
1
1
0
0
1
1
1
1
d. Obtain the minimal form for the following Boolean expression using
Karnaugh’s Map :
[3]
Page 12 of 99
H(P,Q,R,S)= ∑ (0,1,2,3,5,7,8,9,10,14,15)
4.
[ CBSE -2012]
[2]
a. Verify the following using truth table –
1.
X.X’=0
2.
X+1=1
b. Write the equivalent Boolean expression for the following logic circuit
[2]
c. Write the product of sum form of the function F , which is represented in truth table as follows[1]
d.
X
Y
Z
F
0
0
0
1
0
0
1
0
0
1
0
1
0
1
1
0
1
0
0
1
1
0
1
0
1
1
0
0
1
1
1
1
e. Reduce the following Boolean expression using K MapF(A,B,C,D)= ∑ (2,3,4,5,6,7,8,10,11)
5.
[3]
[CBSE-2011]
[2]
a. Verify the following using Truth Table
X+Y.Z=(X+Y).(X+Z)
b. Write the equivalent Boolean Expression for the following Logic Circuit.
& 2009
[2] CBSE 2011, 2010
c. Write the SOP form of a Boolean function F, which is represented in a truth as follows [1]
U
0
0
0
0
1
V
0
0
1
1
0
W
0
1
0
1
0
F
1
0
0
1
0
Page 13 of 99
1
0
1
0
1
1
0
1
1
1
1
1
d. Reduce the following Boolean Expression using K-Map :
F(A,B,C,D) = ∑ (0, 1, 2, 4, 5, 6, 8, 10)
6.
[3]
[CBSE-2010]
a. Verify the following algebraically.
(A’+B’).(A+B) = A’.B’+A.B’
[2]
b.Write the POS form of Boolean function H, which is represented in a truth table
as follows :
X
0
0
0
0
1
1
1
1
Y
0
0
1
1
0
0
1
1
Z
0
1
0
1
0
1
0
1
[1]
H
1
0
1
1
1
0
0
1
b. Reduce the following Boolean expression using K-map :
F (U,V,W,Z)= ∑ (3,5,7,10,11,13,15,)
7.
[3]
[CBSE-2009]
a. State and verify absorption using truth table
[2]
b. Write the POS form of Boolean function G, which is represented in a truth table
as follows
[1]
U
V
W
G
0
0
0
1
0
0
1
1
0
1
0
0
0
1
1
0
1
0
0
1
1
0
1
1
1
1
0
0
1
1
1
1
c. Reduce the following Boolean expression using K-map :
[3]
Page 14 of 99
H(U,V,W,Z)= ∑ (0,1,4,5,6,7,11,12,13,14,15)
8.
a.
b.
c.
d.
9.
a.
b.
c.
[CBSE-2008]
State and verify De Morgan’s law in Boolean Algebra
[2]
Draw a Logical Circuit Diagram for the following Boolean Expression
[1]
X’. (Y’ + Z)
Convert the following Boolean expression into its equivalent Canonical Sum of Product Form(SOP)
[2]
(X’ + Y + Z’) . (X’ + Y + Z) . (X’ + Y’ + Z) . (X’ + Y’ + Z’)
Reduce the following Boolean expression using K - Map
[3]
F (A,B,C,D) = ∑(0,2,3,4,6,7,8,10,12)
[ CBSE-2007]
State Distributive law and verify the same using truth table
[2]
Write the equivalent Canonical Sum of Product expression for the following Product of Sum
Expression[2]
F(X,Y,Z) = 𝞹(1 ,3,6, 7)
Write the equivalent Boolean Expression for the following Logic Circuit
[1]
d. Reduce the following Boolean expression using K-Map
10.
F(U,V,W,Z) = Σ (0, 1, 2, 3, 4, 10, 11)
State and verify associative law [2]
[3]
[CBSE-2006]
a. Write the equivalent expression for the following logic circuit
[2]
b. Express P+Q’R in POS form.
c. Reduce the following Boolean expression using K Map:
F(P,Q,R,S)= 𝞹(0,3,5,6,7,11,12,15)
[1]
[3]
Page 15 of 99
Questions that have been repeated at least three or more times
Topic of Questions are :
Question no 5 (a)
Key , Primary Key , Candidate Key ,Alternate Key
Question no 5 (b)
SELECT * FROM <TABLENAME>
ASC, DESC order command
BETWEEN Keyword
DISTINCT keyword
COUNT( ), COUNT(*) , COUNT(DISTINCT <FIELDNAME>)
MAX( )
MIN( )
Two table query
Questions that have been repeated one or two times.
Topic of Questions are :
Question no 5 (a)
Cartesian Product , Selection & Projection , DDL and DML commands
Question no 5 (b)
INSERT COMMAND
SUM( )
LAST 10 YEAR QUESTIONS
COMPUTER SCIENCE (083)
[AISSCE 2015 ]
Q. Observe the following table carefully and write the names of the most appropriate columns, which can be
considered as (i) Candidate keys and (ii) Primary key:
[2]
[AISSCE 2015 ]
Code
Item
Qty Price
1001
1004
1005
1009
Plastic Folder 14”
Pen Stand Standard
Stapler Mini
Punching Machine
Small
Stapler Big
100
200
250
200
3400
4500
1200
1400
Transaction
Date
2014-12-14
2015-01-31
2015-02-28
2015-03-12
100
1500
2015-02-02
1003
Page 16 of 99
Q. Consider the following DEPT and EMPLOYEE tables. Write SQL queries for (i) to (iv) and find outputs for
SQL queries(v) and (VIII):
[6] [AISSCE 2015 ]
Table : DEPT
DCODE DEPARTMENT
D01
INFRASTRUCTURE
D02
MARKETING
D03
MEDIA
D05
FINANCE
D04
HUMAN REOURCE
Table :EMPLOYEE
LOCATION
DELHI
DELHI
MUMBAI
KOLKATA
MUMBAI
WNO
1001
1002
1003
1007
1004
NAME
DOJ
DOB
GENDER
DCODE
Gorge K
2013-09-02
1991-09-01
MALE
D01
RymaSen
2012-12-11
1990-12-15
FEMALE
D03
Mohitesh
2013-02-03
1987-09-04
MALE
D05
Anil Jha
2014-01-17
1984-10-19
MALE
D04
Manila
2012-12-09
1986-11-14
FEMALE
D01
Sahai
1005 R Sahay
2013-11-18
1987-03-31
MALE
D02
1006 Jaya Priya
2014-06-09
1985-06-23
FEMALE
D05
(i) To display Eno, Name,Gender from the table EMPLOYEE in ascending order of Eno.
(ii) To display the Name of all the MALE employees from the table EMPLOYEE.
(iii) To display the Eno and Name of those worker from the table EMPLOYEE who are born between ‘1987-0101’ and ‘1991-12-01’.
(iv) To count and display FEMALE employees who have joined after ‘1986-01-01’.
(v) SELECT COUNT(*), DCODE FROM EMPLOYEE GROUP BY DCODE HAVING COUNT(*)>1 ;
(vi) SELECT DISTINCT DEPARTMENT FROM DEPT;
(vii)SELECT NAME, DEPARTMENT FROM EMPLOYEE E , DEPT D WHERE E.DCODE = D.DCODE
AND ENO<1003 ;
(viii) SELECT MAX(DOJ), MIN(DOB) FROM EMPLOYEE;
Q. Explain the concept of Cartesian Product between two tables, with the help of appropriate example.
[2] [AISSCE 2014 ]
Note. Answer the questions (b) and (c) on the basis of the following tables SHOPPE and ACCESSORIES.
Table: SHOPPE
ID
SNAME
Area
Page 17 of 99
S01
S02
S03
S04
S05
ABC Computronics
All Infotech Media
Tech Shoppe
Geeks Techno Soft
Hitech Tech Store
CP
GK II
CP
Nehru Place
Nehru Place
Table: ACCESSORIES
No
A01
A02
A03
A04
A05
A06
A07
A08
A09
A10
Name
Mother Board
Hard Disk
Keyboard
Mouse
Mother Board
Keyboard
LCD
LCD
Mouse
Hard Disk
Price
12000
5000
500
300
13000
400
6000
350
350
4500
Id
S01
S01
S02
S01
S02
S03
S04
S05
S05
S03
Que. Write SQL queries:
[4] [AISSCE 2014 ]
(i) To display IName and Price of all the Accessories in ascending order of their price.
(ii) To display Id and SName of all Shoppe located in Nehru Place.
(iii) To display Minimum and Maximum Price of each Name of Accessories.
(iv) To display Name,Price of all Accessories and their respective SName where they are available.
Que. Write the output of the following SQL commands:
[2] [AISSCE 2014 ]
(i) SELECT DISTINCT NAME FROM ACCESSORIES WHERE PRICE>=5000;
(ii) SELECT AREA, COUNT(*) FROM SHOPPE GROUP BY AREA ;
(iii) SELECT COUNT (DISTINCT AREA) FROM STORE;
(iv) SELECT NAME , PRICE*0.05 DISCOUNT FROM ACCESSORIES WHERE SNO IN
(‘SO2’,’S03’) ;
Q 5(a) Explain the concept of candidate key with the help of an example.[2] [AISSCE 2013 ]
Note: Write SQL queries for (b) to (g) and write the outputs for the SQL queries mentioned shown in (h1) to
(h4) parts on the basis of tables PRODUCTS and SUPPLIERS[4] [AISSCE 2013]
Table : PRODUCTS
Pin
Pname
Qty
Price
Company
Supcode
Page 18 of 99
101
Digital camera 14X
102
Digital pad 11i
104
Pen Drive 16 GB
106
Led screen 32
105
Car GPS system
Table : SUPPLIERS
Supcode
S01
S03
S02
120
100
500
70
60
Sname
Get all inc
Easy market corp
Digi busy group
12000
22000
1100
28000
12000
Renix
Digi pop
Storeking
Dispexperts
Moveon
S01
S02
S01
S02
S03
City
Kolkata
Delhi
Chennai
(b) To display the details of all the products in ascending order of product names (i.e. Pname)
(c) To display product name and price of all those products, whose price is in the range of 10000 and 15000 (
both values inclusive).
(d) To display the number of products, which are supplied by each supplier i.e. the expected output should be :
S01
S03
S02
2
2
1
(e) To display the price ,product name and quantity( i.e. qty) of those products which have quantity more than
100.
(f) To display the names of those suppliers, who are either from DELHI or from CHENNAI.
(g) To display the names of the companies and the name of the products in descending order of company
names.
(h) Obtain the outputs of the following SQL queries based on the data given in tables PRODUCTS and
SUPPLIERS above.
[2] [AISSCE 2013 ]
(h1) SELECT DISTINCT SUPCODE FROM PRODUCTS;
(h2) SELECT MAX(PRICE) , MIN(PRICE) FROM PRODUCTS;
(h3) SELECT PRICE*QTY AMOUNT FROM PRODUCTS WHERE PID=104;
(h4) SELECT PNAME, SNAME FROM PRODUCTS P , SUPPLIERS S
WHERE P.SUPCODE = S.SUPCODE AND QTY>100 ;
[AISSCE 2012 ]
5. (b) Give a suitable example of a table with a sample data and illustrate Primary and Alternate keys in it.
[2] [AISSCE 2012 ]
Page 19 of 99
Consider the following tables CARDEN and CUSTOMER and answer (b) and (c) parts of this question:
Table: CARDEN
Ccode
501
503
502
509
510
CarName
A-Star
Indigo
Innova
SX4
C Class
Make
Suzuki
Tata
Toyota
Suzuki
Mercedes
Color
RED
SILVER
WHITE
SILVER
RED
Capacity
3
3
7
4
4
Charges
14
12
15
14
35
Table: CUSTOMER
Ccode
1001
1002
1003
1004
Cname
Hemant Sahu
Raj Lal
Feroza Shah
Ketan Dhal
Ccode
501
509
503
502
(b) Write SQL commands for the following statements :
[4] [AISSCE 2012 ]
(i) To display the names of all the silver colored Cars.
(ii) To display name of car, make and capacity of cars in descending order of their seating capacity.
(iii) To display the highest charges at which a vehicle can be hired from CARDEN.
(iv) To display the customer name and corresponding name of the cars hired by them.
(c) Give the output of the following SQL queries :
[2] [AISSCE 2012 ]
(i) SELECT COUNT (DISTINCT Make) FROM CARDEN;
(ii) SELECT MAX(Charges), MIN(Charges) FROM CARDEN;
(iii) SELECT COUNT(*), Make FROM CARDEN;
(iv) SELECT CarName FROM CARDEN WHERE Capacity = 4;
[AISSCE 2011 ]
Q 5. (a) What do you understand by Selection & Projection operations in relational algebra ?
[2] [AISSCE 2011 ]
Page 20 of 99
Consider the following tables EMPLOYEE and SALGRADE and answer (b) and (c) parts of this question:
Table: EMPLOYEE
ECODE
101
102
103
105
105
NAME
Abdul Ahmad
Ravi Chander
John Ken
Nazar Ameen
Priyam Sen
DESIG
EXECUTIVE
HEAD-IT
RECEPTIONIST
GM
CEO
SGRADE
S03
S02
S03
S02
S01
DOJ
23-Mar-2003
12-Feb-2010
24-Jun-2009
11-Aug-2006
29-Dec-2004
DOB
12-Jan-1980
22-Jul-1987
24-Feb-1983
03-Mar-1984
19-Jan-1982
Table: SALGRADE
SGRADE
S01
S02
S03
SALARY
56000
32000
24000
HRA
18000
12000
8000
(b) Write SQL commands for the following statements:
[4] [AISSCE 2011 ]
(i) To display the details of all EMPLOYEEs in descending order of DOJ.
(ii) To display NAME and DESIG of those EMPLOYEEs, whose SALGRADE is either S02 or S03.
(iii) To display the content of all the EMPLOYEEs table, whose DOJ is in between ’09-Feb-2006’ and ’08Aug-2009’.
(iv) To add a new row with the following :
109,’Harish roy’,’HEAD-IT’,’09-Sep-2007’,’21-Apr-1983’
(c) Give the output of the following SQL queries :
[2] [AISSCE 2011 ]
(i) SELECT COUNT(SGRADE),SGRADE FROM EMPLOYEE GROUP BY SGRADE;
(ii) SELECT MIN(DOB),MAX(DOJ) from EMPLOYEE;
(iii) SELECT NAME,SALARY FROM EMPLOYEE E,SALGRADE S WHERE
E.SGRADE=S.SGRADE AND E.ECODE<103;
(iv) SELECT SGRADE , SALARY+HRA FROM SALGRADE WHERE SGRADE=’S02’;
Page 21 of 99
[AISSCE 2010 ]
Q5 (a) What do you understand by Primary Key ?Give a suitable example of Primary Key from table containing
some meaningful data.
[2] [AISSCE 2010 ]
(b) Consider the following table STOCK and DEALERS and answer (b1) and (b2) parts of this question.
Table : STOCK
Item No
5005
5003
5002
5006
5001
5004
5009
Item
Ball Pen 0.5
Ball Pen 0.25
Gel Pen Premium
Gel Pen Classic
Eraser Small
Eraser Big
Sharpner Classic
Dcode
102
102
101
101
102
102
103
Qty
100
150
125
200
210
60
160
UnitPrice
16
20
14
22
5
10
8
StockDate
31-Mar-10
01-Jan-10
14-Feb-10
01-Jan-09
19-Mar-09
12-Dec-09
23-Jan-09
Table: DEALERS
Dcode
101
103
102
Dname
Reliable Stationers
Class Plastics
Clear Deals
(b1) Write SQL commands for the following statements:
[4] [AISSCE 2010 ]
(i) To display details of all the Items in the Stock table in ascending order of Stock Date.
(ii) To display ItemNo and Item name of those items from stock table whose UnitPrice is more than Rupees 10.
(iii)To display the details of those items whose dealer code (Dcode) is 102 or Quantity in Stock (Qty) is more
than 100 from the table Stock.
(iv) To display Minimum UnitPrice of items for each dealer individually as per Dcode from the table Stock.
(b1) Give the output of the following SQL queries :
[2] [AISSCE 2010 ]
(i) SELECT COUNT(DITINCT DCODE) FROM STOCK ;
(ii) SELECT QTY*UNITPRICE FROM STOCK WHERE ITEMNO=5600;
Page 22 of 99
(iii) SELECT ITEM,DNAME FROM STOCK S,DEALER D WHERE S.DCODE = D.DCODE
AND ITEMNO = 5004 ;
(iv) SELECT MIN(STOCKDATE) FROM STOCK;
[AISSCE 2009 ]
Q 5 (a) What is the purpose of a key in a table? Give a suitable example of a key in a table.
[2] [AISSCE 2009 ]
Q5 (b) Consider the following tables DRESS and MATERIAL. Write SQL commands for the statements (i) to
(iv) and give outputs for SQL queries (v) and (VIII):
Table
:DRESS
DCODE
DESCRIPTION
10001
FORMAL SHIRT
10020
FROCK
10012
INFORMAL SHIRT
10019
EVENING GOWN
10090
TULIP SKIRT
10023
PENCIL SKIRT
10089
SLACKS
10007
FORMAL PANT
10009
INFORMAL PANT
10024
BABY TOP
Table : MATERIAL
MCODE
M001
M002
M004
M003
PRICE
1250
750
1450
850
850
1250
850
1450
1400
650
MCODE
M001
M004
M002
M003
M002
M003
M003
M001
M002
M003
LAUNCHDATE
12-JAN-08
09-SEP-07
06-JUN-08
06-JUN-08
31-MAR-07
19-DEC-08
20-OCT-08
09-MAR-08
20-OCT-08
07-APR-07
TYPE
TERELENE
COTTON
POLYESTER
SILK
[4] [AISSCE 2009 ]
(i) To display DCODE and DESCRIPTION of each dress in descending order of DCODE.
(ii) To display the details of all the dresses which have LAUNCHDATE in between 05-DEC-07 and 20-JUN08(inclusive of both dates)
(iii) To display the average PRICE of all the dresses which are made up of material with MCODE as M003.
(iv) To display material wise highest and lowest price from DRESS table. ( Display MCODE of each dress
along with highest and lowest price ).
[2] [AISSCE 2009 ]
Page 23 of 99
(v) SELECT SUM(PRICE) FROM DRESS WHERE MCODE= ‘M001’;
(vi) SELECT DESCRIPTION,TYPE FROM DRESS , MATERIAL WHERE DRESS.DCODE=
MATERIAL.MCODE AND DRESS.PRICE>=1250 ;
(vii) SELECT MAX(MCODE) FROM MATERIAL ;
(viii) SELECT COUNT(DISTINCT PRICE) FROM DRESS ;
[AISSCE 2008 ]
Q 5 (a) Differentiate between Candidate Key and Alternate Key in context of RDBM .
[2] [AISSCE 2008 ]
Q5 (b) Consider the following tables Item and Customer. Write SQL commands for the statements
(i) to (iv) and give outputs for SQL queries (v) and (viii):
[6] [AISSCE 2008]
TABLE: ITEM
I_ID
PC01
LC05
PC03
PC06
ItemName
Personal Computer
Laptop
Personal Computer
Personal Computer
LC03
Laptop
TABLE : CUSTOMER
Manufacturer
ABC
ABC
XYZ
COMP
Price
35000
55000
32000
37000
PQR
57000
C_ID
CustomerName
City
01
N Roy
Delhi
06
H Singh
Mumbai
12
R Pandey
Delhi
15
C Sharma
Delhi
16
K Agrawal
Bangalore
(i) To display the details of those Customer whose City is Delhi.
I_ID
LC03
PC03
PC06
LC03
PC01
(ii) To display the details of Items whose Price is in the range of 35000 to 55000 ( Both values included)
(iii) To display the CustomerName,City from table Customer and ItemName and Price from table Item, With
their corresponding matching I_ID.
(iv) To increase the Price of all Items by 1000 in the table Item.
(v) SELECT DISTINCT CITY FROM CUSTOMER;
(vi) SELECT ITEMNAME, MAX(PRICE) , COUNT(*) FROM ITEM GROUP BY ITEMNAME;
(vii) SELECT CUSTOMERNAME, MANUFACTURER FROM ITEM, CUTOMER WHERE ITEM.ITEM_ID
= CUTOMER.ITEM.I_ID.
Page 24 of 99
(VIII) SELECT ITEMNAME, PRICE* 100 FROM ITEM WHERE MANUFACTURER = ‘ABC’. [AISSCE
2007 ]
Q5 (a) What is the importance of a Primary Key in a table? Explain with a example.[2] [AISSCE 2007 ]
Q5 (b). Consider the following tables Consignor and Consignee. Write SQL commands for the statements (i) to
(iv) and give outputs for SQL queries (v) to (viii).
[2] [AISSCE 2007 ]
TABLE: CONSIGNOR
CnorID
ND01
NDO2
MU15
MU50
CneeID
MU05
ND08
KO19
MU32
ND48
CnorName
R Singhal
Amit Kumar
R kohli
S Kaur
CnorID
ND01
ND02
MU15
ND02
MU50
CnorAddress
24,ABC Enclave
123,Palm Avenue
5/A, South Streat
27-K, Westend
City
New Delhi
New Delhi
Mumbai
Mumbai
TABLE: CONSIGNEE
CneeName
Cnee Address
Rahul Kishore
5, Park Avenue
P Dhingra
16/J, Moore Enclave
A P Roy
2A, Central Avenue
S Mittal
P245,AB Colony
B P Jain
13, Block D,A Vihar
CneeCity
Mumbai
New Delhi
Kolkata
Mumbai
New Delhi
(i) To display the names of all Consignors from Mumbai.
(ii) To display the CneeID,CnorName, CnorAddress,CneeName, CneeAddress for every Consignee.
(iii) To display consignee details in ascending order of CneeName.
(iv) To display number of consignors from each city.
(v) SELECT DISTINCT CITY FROM CONIGNOR ;
(vi) SELECT A.CnorName, B.CneeName from Consignor A, Consignee B
where A.CnorID = B.CnorID and B.CneeCity=’Mumbai’;
(vii) SELECT CneeName, CneeAddress from Consignee
where CneeCity NOT IN( ‘Mumbai’,’Kolkata’) ;
(viii) SELECT CneeID ,CneeName from Consignee
where CnorID =’MU15’ OR CnorID = ’ND01’ ;
Page 25 of 99
[AISSCE 2006 ]
Q5 (a) What are DDL and DML commands ?
[2] [AISSCE 2006]
(b) Study the following tables FLIGHTS and FARES and write SQL commands for the questions (i) to (iv)
and give outputs for SQL queries (v) to (viii).
[6] [AISSCE 2006]
T ABLE: FLIGHT
FL_NO
IC301
IC799
MC101
IC302
AM812
IC899
AM501
MU499
IC701
STARTING
MUMBAI
BANGALORE
INDORE
DELHI
KANPUR
MUMBAI
DELHI
MUMBAI
DELHI
ENDING
DELHI
DELHI
MUMBAI
MUMBAI
BANGALORE
KOCHI
TRIVENDRUM
MADRAS
AHEMDABAD
NO_FLIGHT
8
2
3
3
3
1
1
3
4
NO STOPS
0
1
0
0
1
4
5
3
0
T ABLE: FARES
FL_NO
IC701
MU499
AM501
IC899
IC302
IC799
MC101
AIRLINES
Indian Airlines
Sahara
Jet Airways
Indian Airlines
Indian Airlines
Indian Airlines
Deccan Airlines
FARE
6500
9400
13450
8300
4300
10500
3500
TAX%
10
5
8
4
10
10
4
[6] [AISSCE 2006]
(i) Display FL_NO and NO_FLIGHT from “KANPUR” to “BANGALORE” from the table FLIGHTS.
(ii) Arrange the contents of the table FLIGHTS in the ascending order of FL_NO.
(iii) Display the FL_NO and fare to be paid for the flights from DELHI to MUMBAI using the tables FLIGHTS
and FARES , where the fare to be paid = FARE +FARE * TAX%/100.
(iv) Display the minimum fare “Indian Airlines” is offering from the table FARES.
(v) SELECT FL_NO, NO_FLIGHTS,AIRLINES from FLIGHTS,FARES where STARTING =”DELHI” and
FLIGHTS_FL_NO=FARES.FL.NO.
(vi) SELECT count( distinct ENDING) FROM FLIGHTS.
KENDRIYA VIDYALAYA SANGATHAN, KOLKATA REGION
Computer Science Question Bank
Unit – 2
Page 26 of 99
Unit / Chapter
VSA
(1 Mark)
SA I
(2 Marks)
SA II
(3 Marks)
LA
(4 Marks)
_
_
1
1
1
1
_
_
1
1
1
_
1
-
Total
Object Oriented Programming in C++
a)
b)
c)
d)
e)
Introduction to OOP using C++
Constructor& Destructor
Inheritance
Pointers
Data File Handling
Total
(2) 6
(1) 2
(1) 4
1(3)
(3) 6
IMPORTANT QUESTIONS (1 OR 2 TIMES)
Chapter – Introduction to OOP using C++
2005 Define the term Data Hiding in the context of Object Oriented Programming. Give a
Suitable example using a C++ code to illustrate the same.
Define a class TravelPlan in C++ with the following descriptions :
Private Members:
PlanCode of type long
Place of type character array (string)
Number_of_travellers of type integer
Number_of_buses of type integer
Public Members:
A constructor to assign initial values of Plan Code as 1001, Place as “Agra”,
Number_of_travellers as 5, Number_of_buses as 1
A function NewPlan( ) which allows user to enter PlanCode, Place and
Number_of_travellers. Also, assign the value of Number_of_buses as per the
following conditions :
Number_of_travellersNumber_of_buses
Less than 20
Equal to or more than 20 and less than 40
Equal to 40 or more than 40 3
A function ShowPlan( ) to display the content of all the data members on screen.
2006 Define Multilevel and Multiple inheritance in context of Object Oriented Programming. Give
suitable example to illustrate the same.
2
4
2
Page 27 of 99
Define a class named ADMISSION in C++ with the following descriptions:
Private members:
AD_NO integer (Ranges 10 - 2000)
NAME Array of characters (String)
CLASS Character
FEES Float
Public Members:
Function Read_Data ( ) to read an object of ADMISSION type
Function Display() to display the details of an object
Function Draw-Nos ( ) to choose 2 students randomly.
And display the details. Use random function to generate admission nos. to match with
AD_NO.
2007 What do
you
understand . by Data
an example in C++ to illustrate both.
Encapsulation and Data · Hiding ? Also, give
Define a class STOCK in C++ with following description :
(4)
2
4
Private Members
•
!Code of type integer (Item Code)
•
Item of type string (Item Name)
•
. Price of type float (Price of each item)
•
Qty of type. integer (Quantity in stock)
•
Discount of type float (Discount percentage on the itedJ.)
•
A member function FindDisc() to calculate discount s
per the following rule :
If Qty<=50
Discount is 0
If 50<Qty<=l00 . Discount is 5
If Qty> lOO
Discount is 10
Public Members
• A function Buy() to allow user to enter values for Code, Item, Price,. Qty and call function FindDisc() to
calcula& the Discount.
•
A • function ShowAll() to allow user to view the content of all the data members.
2008 Differentiate between members, which are present within the private visibility
mode with those which are present within the public visibility modes.
Define a class Candidate in C++ with following description :
Private Members
•
A data member RNo (Registration Number) of type long
2
4
Page 28 of 99
•
A data member Name of type string
•
A data member Score of type float
•
A data member Remarks of type string
•
A member function AssignRem( ) to assign Remarks as per the Score obtained by a
candidate. Score range and the respective Remarks are shown as follows :
Score
Remarks
>=50
Selected
less than 50
Not selected
Public Members
 A function ENTER( ) to allow user to enter values for RNo, Name, Score
& call function AssignRem( ) to assign the remarks.
 A function DISPLAY( ) to allow user to view the content of all the data
members.
2009
What is copy constructor? Give an example in C++ to illustrate copy constructor.
2
Define a class Applicant in C++ with following description :
Private Members
•
A data member ANo (Admission Number) of type long
•
A data member Name of type string
•
A data member Agg (Aggregate Marks) of type 'float
•
A data member Grade of type char
•
A member function GradeMe() to find the Grade as per the Aggregate Marks obtained by a student.
Equivalent Aggregate Marks range and the respective Grades are shown
as follows :
Aggregate Marks
Grade
>=80 A
less than 80 and >=65 B
less than 65 and >=50 c
less than 50
D
:,
Public Members
•
A function ENTER() to allow user to enter values for ANo, Name, Agg & call function GradeMe() to
find the Grade.
•
A function RESULT() to allow user to view the content of all the data members.
4
2010 What do
you
understand . by Data
in C++ to illustrate both.
Encapsulation and Data • Hiding ? Also, give an example
Define a class STOCK in C++ with following description :
Private Members
•
!Code of type integer (Item Code)
•
Item of type string (Item Name)
•
. Price of type float (Price of each item)
Page 29 of 99
•
Qty of type. integer (Quantity in stock)
•
Discount of type float (Discount percentage on the itedJ.)
•
A member function FindDisc() to calculate discount s
per the following rule :
If Qty<=50
If Qty> lOO
Discount is 0 If 50<Qty<=l00
Discount is 10
. Discount is 5
Public Members
• A function Buy() to allow user to enter values for Code, Item, Price,. Qty and call function FindDisc() to
calcula& the Discount.
•
A • function ShowAll() to allow user to view the content of all the data members.
2011 Differentiate between Constructor and Destructor function with respect to Object Oriented
Programming.
(c)
Define a class Applicant in C++ with following description :
Private Members
•
A data member ANo (Admission Number) of type long
•
A data member Name of type string
•
A data member Agg (Aggregate Marks) of type 'float
•
A data member Grade of type char
•
A member function GradeMe() to find the Grade as per the Aggregate Marks obtained by a student.
Equivalent Aggregate Marks range and the respective Grades are shown
as follows :
Aggregate Marks
Grade
>=80 A
less than 80 and >=65 B
less than 65 and >=50 c
less than 50
D
:,
Public Members
•
A function ENTER() to allow user to enter values for ANo, Name, Agg & call function GradeMe() to
find the Grade.
•
A function RESULT() to allow user to view the content of all the data members.
2012 What is the difference between the members in private visibility mode and the members in protected
visibility mode inside a class? Also, give a suitable C++ code to illustrate both.
2
4
2
Page 30 of 99
Define a class RESTRA in C++ with following description:
Private Members
 FoodCode of type int
 Food of type String
 FType of type string
 Sticker of type string
 A member function GetSticker() to assign the following values for Sticker as per the given FType:
FType
Sticker
Vegetarian
GREEN
Contains Egg
YELLOW
Non-Vegetarian
RED
Public Members
 A function GetFood() to allow user to enter values for FoodCode,Food,FType and call function
GetSticker() to assign Sticker.
 A function ShowFood() to allow user to view the content of all data members.
2013 Write any two differences between Constructor and Destructor. Write the function headers for constructor
and destructor of a class Member.
Define a class Tourist in C++ with the following specification:
Data Members
 carno – to store Bus No
 Origin – to store Place name
 Destination – to store Place name
 Type – to store Car Type such as ‘E’ for Economy
 Distance – to store the Distance in Kilometers
 Charge – to store the car fare
Member Functions
 A contructor function to initialize Type as ‘E’ and Freight as 250
 A function CalcCharge() to calculate Fare as per the following citeria:
Type
Charge
‘E’
16 * Distance
‘A’
22 * Distance
‘L’
30 * Distance
 A function Enter() to alow user to enter values for carno,origin,destination,type and distance. Also this
function should call CalcCharge() to calculate Fare.
 A function Show () to display the content of all the data members on screen.
2014
Write any two differences between Constructor and Destructor. Write function headers for
constructor and destructor of a class Member.
(c) Define a class Tourist in C++ with the following specification :
Data Members
•
Camo - to store Bus No
•
Origin - to store Place name
•
Destination - to store Place name
•
Type - to store Car Type such as 'E' for Economy
•
Distance - to store the Distance in Kilometers
•
Charge - to store the Car Fare Member Functions
•
A constructor function to initialize Type as 'E' and Freight as 250
•
A function CalcCharge() to calculate Fare as per the following criteria :
4
2
4
2
4
Page 31 of 99
Type Charge
' E ' 16*Distance
'A ' 22*Distance
' L ' 30*Distance
•
A function Enter() to allow user to enter values for Carno, Origin, Destination, Type and
Distance. Also, this function should call CalcCharge() to calculate Fare.
•
A function Show() to display the content of all the data members on screen.
Chapter - Constructor & Destructor
2005 Answer the questions (i) and (ii) after going through the following class:
class Test
{
char Paper[20];
int Marks;
public:
Test () // Function 1
{
strcpy (Paper, “Computer”)
Marks = 0;
}
Test (char P [] ) // Function 2
{
strcpy(Paper,P);
Marks = 0;
}
Test (int M) // Function 3
{
strcpy(Paper,”Computer”);
Marks = M;
}
Test (char P[], int M) // Function 4
{
strcpy (Paper, P);
Marks = M;
}
};
2
(i) Which feature of Object Oriented Programming is demonstrated using
Function 1, Function 2, Function 3 and Function 4 in the above class Test?
(ii) Write statements in C++ that would execute Function 2 and Function 4 of
class Test.
2006 Answer the questions (i) and (ii) after going through the following class:
class Interview
{ int month;
public:
Interview (int y) {month=y ;} //Constructor 1
Interview (Interview&t); //Constructor 2
};
i. Create an object, such that it invokes Constructor 1.
ii. Write complete definition for Constructor 2.
2
Page 32 of 99
2007
Answer the questions (i) and (ii) after going through the following
2
class :
class Exam
int Rno,MaxMarks,MinMarks,Marks;
public:
Exam ()
I /Module 1
Rno=l01;MaxMarks=l O O;MinMarks=40;Marks=75;
Exam (int Prno,int Pmarks)
I /Module 2
Rno=Prno;MaxMarks=lO O;MinMarks=40;Marks=Pmarks;
-Exam ()
I /Module 3
cout<< Exam Over <<endl;
void Show ()
I /Module 4
11
11
cout<<Rno<<" :"<<MaxMarks<<" :"<<MinMarks<<endl; cout<<"
[Marks Got]" <<Marks<<endl;
};
(i)
As per Object Oriented Programming, which concept is
illustrated by Module 1 and Module 2 together ?
(ii)
What is Module 3 referred as ? When do you think,
Module 3 will be invoked/called ?
2008 Write the output of the following C++ code. Also, write the name of feature of Object Oriented
' jointly illustrated'
Programming used in the following program
by the functions [I] to [IV].
# include <iostream.h>
void Print ( )
// Function [I]
{
for (int K=l · K<=60 ·K++) cout<< "-" ·
'
cout<<endl ;
,
}
11 Function [II]
void Print (int N)
{
for (int K=l ·,K<=N ·, L++) cout<< "*" '·
cout<<endl ;
}
void Print (char T, int N)
{
11 Function [IV]
2
Page 33 of 99
for (int K= l ;K<=N ;K++) cout<<T ;
cout<<endl ;
}
void main ( )
{
int U=9, V=4, W=3;
char C= '("a.)' ,·
Print (C, V) ;
Print (U, W) ;
}
2009 Write the output of the following C++ code. Also, write the name of feature of Object Oriented
programming used in the following program jointly illustrated by the functions (i) to (iv) :
#include<iostream.h>
void Line()
// Function 1
{
for(int L=1; L<= 80; L++) cout<<”-“;
cout<<endl;
}
void Line(int N)
// Function 2
{
for(int L=1; L<=N; L++) cout<<”*”;
cout<<endl;
}
void Line(char C,A,int N)
{
for(int L=1; L<=N; L++) cout<<C;
cout<<endl;
}
void Line(intM,int N)
{
for(int L=1; L<=N; L++) cout<<M*L;
cout<<endl;
}
void main()
{
int A=9,B=4,C=3;
char K=’#’;
Line(K,B);
Line(A,C);
}
2
// Function 3
// Function 4
2010 Answer the questions (i) and (ii) after going through the following
class :
class Exam
2
Page 34 of 99
int Rno,MaxMarks,MinMarks,Marks; public:
Exam () I /Module 1
Rno=l01;MaxMarks=l O O;MinMarks=40;Marks=75; Exam (int Prno,int Pmarks) I /Module 2
Rno=Prno;MaxMarks=lO O;MinMarks=40;Marks=Pmarks;
-Exam ()
I /Module 3
cout<< 11 Exam Over 11 <<endl;
void
Show () I /Module 4
cout<<Rno<<" :"<<MaxMarks<<" :"<<MinMarks<<endl; cout<<" [Marks Got]" <<Marks<<endl;
};
i)
As per Object Oriented Programming, which concept is
illustrated by Module 1 and Module 2 together ?
ii) What is Module 3 referred as ? When do you think,
Module 3 will be invoked/called ?
2011 Write the output of the following C++ code. Also, write the name of feature of Object Oriented
Programming used in the following ' program jointly illustrated by the functions [I] to [IV] :
*include
< iost ream .h>
void
Line ( ) / / Funct ion
[I]
{
f or
( int
L= l ; L<=8 0 ; L++ )
cout<<"-"; cout<<endl ;
1',
void
Line ( int
N)
{
f or
( int
L= l ; L<=N ;L+ + )
void
Line ( cha r
{
f or
( int
void
Line ( int
{
f or
( int
C , int N )
/ / Funct ion
[ II ]
cout<<"*"; cout<<endl ;
/ / Funct ion
[III]
L= l ;L<=N ;L++) cout<<C ; cout<<endl ;
M , int N )
/ / Funct ion
[IV]
L= l ; L<=N ;L++ ) cout<<M*L ; cout<<endl ;
void
ma in ( )
{
int
A= 9 , B= 4 , C=3;
char K='#'; Line ( K , B) ;
Line ( A , C ) ;
}
2012 Answer the questions(i) and (ii) after going through the following class :
class Travel
2
Page 35 of 99
{
intPlaceCode; char Place[20]; float Charges;
public:
Travel()
// Function 1
{
PlaceCode =1; strcpy(Place,”DELHI”); Charges=1000;
}
Travel(float C)
// Function 2
{
Cout<<PlaceCode<<”:”<<Place<<”:”<<Charges<<endl;
}
~Travel()
// Function 3
{
Cout<<”Travel Plan Cancelled”<<endl;
}
Travel(intPC,char P[],float C)
// Function 4
{
PlaceCode = PC; strcpy(Place,P); Charges = C;
} };
i)
In Object Oriented Programming, what are Function 1 and Function 4 combined together
referred as ?
ii)
In Object Oriented Programming, which concept is illustrate by Function 3? When is this
function called/invoked?
2013 Answer the question (i) and (ii) after going through the following class :
Class Motor
{
Int MotorNo,Track;
Public:
Motor();
// Function 1
Motor (int MN);
// Function 2
Moto (Motor & M);
// Function 3
Void Allocate();
// Function 4
Void Move();
// Function 5
};
Void main()
{
Motor M;
:
:
}
(i)
Out of the following, which of the option is correct foe calling function 2?
Option 1 – Moto N(M);
Option 2 – Motor P(10);
(ii)
Name the feature of Object Oriented Programming, which is illustrated by Function1,Function 2
and Function 3 combined together.
2014
Answer the questions (i) and (ii) after going through the following class :
class Motor
{
int MotorNo, Track; public:
Motor();
//Function 1
2
Page 36 of 99
Motor (int MN) ; //Function 2 Motor(Motor &M) ; //Function 3 void Allocate {); //Function 4 void
Move();
//Function 5
};
void main ()
{
Motor M;
}
(i) Out of the following, which of the option is correct for calling Function 2 ?
Option 1 - Motor N(M ); Option 2 - Motor P(lO );
(ii)
Name the feature of Object Oriented Programming, which is illustrated by Function 1, Function 2
and Function 3 combined together.
Chapter - Inheritance
2005 Answer the questions (i) to (iv) based on the following code: 4
class Medicines
{
char Category[lO];
char Date_of_manufacture[lO];
char Company[20];
public:
Medicines();
void entermedicinedetails();
void showmedicinedetails();
} ;
class Capsules: public Medicines
{
protected:
char capsule_name[30];
char Volume_label[20];
public:
float Price;
Capsules();
void entercapsuledetails();
void showcapsuledetails();
};
class Antibiotics: public Capsule
{
intDosage_units;
char Side_effects[20];
intUse_within_days;
public:
Antibiotics() ;
void enterdetails();
void showdetails();
};
(i) How many bytes will be required by an object of class Medicines and an object
of class Antibiotics respectively?
(ii) Write names of all the member functions accessible from the object of class
Antibiotics.
(iii) Write names of all the members accessible from member functions of class
Capsules.
4
Page 37 of 99
(iv) Write names of all the data members, which are accessible from objects of class
Antibiotics.
2006 Answer the questions (i) to (iii) based on the following code
class stationary
{
char Type;
char Manufacturer [10];
public:
stationary();
void Read_sta_details( );
void Disp_sta_details( );
};
class office: public stationary
{
intno_of_types;
float cost_of_sta;
public:
void Read_off_details( );
void Disp_off_details( );
};
class printer: private office
{
intno_of_users;
char delivery_date[10];
public:
void Read_pri_details( );
void Disp_pri_details( );
};
void main ( )
{ printer MyPrinter; }
i. Mention the member names which are accessible by MyPrinter declared in main() function
ii. What is the size of MyPrinter in bytes?
iii. Mention the names of functions accessible from the member function
Read_pri_details () of class printer.
2007 Answer the questions (i) to (iv) based on the following
Class ·Director
{
long
DID;
char Name[20];
protected:
char Description[40];
void Allocate();
public:
Director(); void Assign(); void
Show();
};
class Factory:public
Directer
4
4
Page 38 of 99
{
int FID;
char Address[20];
I /Factory
protected:
int NOE;
ID
I
I /No. of Employees
public:
Factory(); voidInput();
Void Output ();
};
class ShowRoom:private Factory
{
int SID;
I/Showroo:nID char City[20];
public:
ShowRoom ();
void Enter();
voidDisplay ();
};
(I)WHICH TYPE OF ·INHERI TANCE·, OUT OF THE . FOLLOWING IS ILLUSTRATED IN THE ABOVE C++ ?
(a) Single level Inheritance
(b) MULTI LEVEL INHERITANCE
(c) Multiple Inheritance
(iii)
(iv)
(v)
Write the names of members which are accessible by the object of class showroom.
Write the names of member function which are accessible by the object of class showroom.
Write the names of members which are accessible by the object of class Factory.
2008 Answer the questions (i) to (iv) based ·on the following :
class Student
{
int Rno ;
char Name[20] ; float Marks ;
protected :
void Result ( ) ; public :
Student ( ) ;
void Register ( ) ; void Display ( ) ;
};
class Faculty
{
long FCode ;
char FName [20] ;
protected :
float Pay ; public :
Faculty ( ) ; void Enter ( ) ; void Show ( ) ;
};
class Course : public Student, private Faculty
4
Page 39 of 99
{
long CCode [IO]; char CourseName [50]; char StartDate [8J, EndDate [8] ;
public :
Course ( ) ;
void Commence ( ) ; void CDetail ( ) ;
};
(i)
Which type of inheritance is illustrated in the above C++ code ?
(ii)
Write the names of all the data members, which is/are accessible from member function Commence
of class Course.
(iii)
Write the names of member functions, which are accessible from objects of class Course.
(iv)
Write the names of all the members, which are accessible from objects of class Faculty.
2009 Answer the questions (i) to (iv) based ·on the following :
Class student
{
int Rollno;
char SName [20]; float Marksl
protected:
void Result (); public:
Student();
void Enroll( );void Display( );
};
Class teacher
{
long TCode;
char TName [20]; protected:
float Salary; public:
Teacher(); void Enter (); void
Show ();
};
class Course: public Student , private Teacher
{
long CCode[lO];char CourseName[ SO]; char StartDate[8],EndDate[8];
public:
Course( );
void Commence (); void CDetail ();
};
(i)
Write the names of member functions, which are accessible from objects of class Course.
(ii)
Write the names of all the data members, which is/are accessible from member function Commence
of class Course.
(iii)
Write the names of all .the members, which are accessible from objects of class Teacher.
(iv)
Which type of Inheritance 1s illustrated in the above C++ code ?
2010 Answer the questions (i) to (iv) based on the following
Class ·Director
{
long
DID;
char Name[20];
protected:
char Description[40];
void Allocate();
Page 40 of 99
public:
Director(); void Assign(); void
Show();
};
class Factory:public
{
int FID;
char Address[20];
Directer
I /Factory
protected:
int NOE;
ID
I
I /No. of Employees
public:
Factory(); voidInput();
Void Output ();
};
class ShowRoom:private Factory
{
int SID;
I/Showroo:nID char City[20];
public:
ShowRoom ();
void Enter();
voidDisplay ();
};
(I)WHICH TYPE OF ·INHERI TANCE·, OUT OF THE . FOLLOWING IS ILLUSTRATED IN THE ABOVE C++ -'
(d) Single level Inheritance
(e) MULTI LEVEL INHERITANCE
(f) Multiple Inheritance
(vi)
Write the names of members which are accessible by the object of class showroom.
(vii)
Write the names of member function which are accessible by the object of class showroom.
Write the names of members which are accessible by the object of class Factory.
2011 Answer the questions (i) to (iv) based ·on the following :
Class Student
{
Int Rollno;
Char SName[20];
Float Marks1;
Protected :
Void Result();
Public:
?·
Page 41 of 99
Student();
Void Enroll(); void display();
};
Class Teacher
{
Long TCode;
Char TName[20];
Protected:
Float salary;
Public:
Teacher();
Void Enter();
Void show();
};
Class Course : public Student , private Teacher
{
Long CCode[10]; char CourseName[50];
Char StartDate[8],EndDate[8];
Public:
Course();
Void Commerce();
Void CDetails();
};
(i)
Write the names of member functions, which are accessible from objects of
class Course.
(ii)Write the names of all the data members, which is/are accessible from
member function Commence of class Course.
(iii)Write the names of all .the members, which are accessible from objects of
class Teacher.
(iv)Which type of Inheritance 1s illustrated in the above C++ code ?
2012 Answer the questions (i) to (iv) based on the following :
class COMPANY
char Loca tion [20 ] ;
double Budget , Incorne; pr otected :
void
Accou n ts ( ) ; public :
COMPANY ( ) ;
void
Register ( ) ; void
Show ( ) ;
};
cla ss FACTORY :public COMPANY
char
Location ( 2 0 ) ; int
Wor kers;
protected :
double Salar y; void
Computer ( ) ;
public :
FACTORY () ;
void Enter ( ) ; void
Show ( ) ;
Page 42 of 99
};
class
SHOP : pr ivate COMPANY
cha r Loca t ion [ 2 0 ] ; f loat
double Sale ; public :
SHOP ( ) ;
void
Inpu t ( ) ; void Outpu t ( ) ;
};
Area ;
(i)
Name the type of inheritance illustrated m the above C++ code.
(ii)
Write the name of data members, which arc accessible from m ember
functions of class SHOP.
(iii)
Write the names of all the member fonction s, which are accessible
from objects belonging to class FACTORY.
(iv)
Write the names of all the mem bers, which arc accessible from
objects of class SHOP.
2013 Consider the following C++ code and answer the questions from (i) to (iv):
Class Student
{
Int Class,Rno;
Char Section;
Protected:
Char SName[20];
Public:
Student();
Void Stentry();
Void Stddisplay();
};
Class Score : private Student
{ Float Marks[5];
Protected:
Char Grade[5];
Public:
Score();
Void Sentry();
Void Sdisplay();
};
Class Report : public Score
{
Float Total, Avg;
Public:
Char OverallGrade,Remarks[20];
Report();
Void Revaluate();
Void RPrint();
};
(i)
Which type of Inheritance is shown in the above example ?
Page 43 of 99
(ii)
Write the names of those data members, which can be directly accessed from the objects of
class Report.
(iii)
Write the names of those members functions , which can be directly accessed from the objects
of class Report.
(iv)
Write the names of those data members, which can be directly accressed from the Sentry()
function of class Score.
2014
(d)
Consider the following C++ code and answer the questions from (i) to (iv) :
class Student
{
int Class,Rno; char Section;
protected :
char SNarne[20]; public :
Student();
void Stentry(); void Stdisplay();
};
class Score: private Student
{
float Marks[S]; protected:
char Grade[S]; public:
Score ();
void Sentry(); void Sdisplay();
};
class Report: public Score
{
float Total, Avg; public:
char OverallGrade, Remarks [20];
Report();
void REvaluate( ); void RPrint();
}i
(i)
Which type of Inheritance is shown in the above example ?
4
(ii)
Write the names of those data members, which can be directly accessed from the objects of class
Report.
(iii)
Write the names of those member functions, which can be directly accessed from the objects
of class Report.
(iv)
Write the names of those data members, which can be directly accessed from the Sentry() function
of class Score.
Chapter – Pointers
2005
Find the output of the following program :
#include <iostream.h> void main ()
{
int *Queen,Moves[ ]={ll,22,33,44}; Queen=Moves;
Moves[ 2]+=22;
cout<<"Queen @"<<*Queen<<endl;
3
2
Page 44 of 99
*Queen-=11; Queen+=2;
cout<<"Now @"<<*Queen<< ndl; Queen++;
cout<<"Finally @"<<*Queen<<endl;
cout<<"New Origin @"<<Moves[O]<<endl;
2006 Find the output of the following program
2
# include<iostream.h>
#include<string.h> class
state
{
char *
state_name;
int size;
public;
state( ); { size=0; state_name=new char[size+1]; }
state(char *s)
{
size = strlen(s) ; state_name = new
char[size+1];} strcpy(state_name,s);
}
void display() {cout<<state
name<<endl; } void Replace (state &a,
state &b)
{
size = a.size +
b.size; delete
state_name;
state_name = new char[size+1] ;
strcpy(state_name, a.state_name);
strcat(state_name, b.state_name);
}
};
void main( )
{
char *temp = “Delhi”;
state state1(temp), state2(”Mumbai”), state3(”Nagpur”), SI,
S2; SI .Replace(state1, state2);
S2.Replace(S1, state3);
S1.display( );
S2.display( );
}
2007
(c) Find the output of the following program :
2
# inclu de <iostream.h>
void main ( )
{
int Track [ ] = {I 0, 20, 30, 40}, *Striker ;
Striker=Track ;
Track [1] + = 30 ;
Page 45 of 99
cout<<"Striker>"<<* Striker<<endl ;
* Striker -= 10 ;
Striker++ ;
cout<< "Next @" <<* Striker<<endl ;
Striker+=2 ;
cout<< "Last @" <<*Striker<<endl;
cout << "Reset To" <<Track [O] <<endl ;
}
2008 Find the output of the following program :
2
# inclu de <iostream.h> void main ( )
{
int Track [ ] = {I 0, 20, 30, 40}, *Striker ; Striker=Track
;
Track [1] + = 30 ; cout<<"Striker>"<<*
Striker<<endl ;
* Striker -= 10 ; Striker++ ;
cout<< "Next @" <<* Striker<<endl ; Striker+=2 ;
cout<< "Last @" <<*Striker<<endl;
cout << "Reset To" <<Track [O] <<endl ;
}
2009
Find the output of the following program :
2
#include <iostream.h> void main ()
{
int *Queen,Moves[ ]={ll,22,33,44}; Queen=Moves;
Moves[ 2]+=22;
cout<<"Queen @"<<*Queen<<endl;
*Queen-=11; Queen+=2;
cout<<"Now @"<<*Queen<< ndl; Queen++;
cout<<"Finally @"<<*Queen<<endl;
cout<<"New Origin @"<<Moves[O]<<endl;
2010 Find the output of the following program :
2
#include
<iostrearn.h>
#include
<ctype.h>
void
MyCode(char Msg[],char
CH)
for(int Cnt=O;Msg[Cnt] !=' \0' ;Cnt++)
if
(Msg[Cnt]>='B' & &
Msg[Cnt]<=' G' ) Msg[Cnt]=tolower(Msg[Cnt]);
2
2
Page 46 of 99
else
if
(Msg[Cnt]=='A' 1 1
Msg[Cnt]==' a' ) Msg[Cnt]=CH;
else
if
(Cnt%2==0) Msg[Cnt]=toupper(Msg[ Cnt]);
else
Msg[Cnt]=Msg[Cnt-1];
void
main ()
{
char MyText []="ApEACeDri VE" ; MyCode(MyText, '@' );
cout<< "NEW TEXT: "<<MyText<<endl;
2011
Find the output of the following program :
#include <iostream.h> void main ()
{
int *Queen,Moves[ ]={ll,22,33,44}; Queen=Moves;
Moves[ 2]+=22;
cout<<"Queen @"<<*Queen<<endl;
*Queen-=11; Queen+=2;
cout<<"Now @"<<*Queen<< ndl; Queen++;
cout<<"Finally @"<<*Queen<<endl;
cout<<"New Origin @"<<Moves[O]<<endl;
2012
Find the output of the following program
#include
<iostrearn .h>
#include <ctype .h>
typedef char Str80 f 80];
void main()
{
char
*Notes;
Str80 SLr'-""vR2GooO" ;
int L=6; Notes=Str ;
while
(L>=3 )
Str [L]= (isupper (Str!
T.l )?to.L owcr.( SL r f r,]): toupper (Str [L]));
cout<<Notes<<endl ;
L-- ;
Notes++;
}
2
Page 47 of 99
2014 Observe the following C++ code carefully and obtain the output, which will appear on the screen after
execution of it.
Important Note :
All the desired header files are already included in the code, which are required to run the code.
void main ( )
{
2
char *String="SHAKTI" ;
int
*Point,Value[]={l0,15,70,19}; Point=Value ; coutcc*PointccStringccendl; String++;
Point++ ; coutcc*PointccStringccendl ;
}
Chapter –Data File Handling
2006 void main( )
1
{
char=’A’;
fstream fileout(”data.dat”,ios::out); fileout<<ch;
int p = fileout.tellg( ); cout<<p;
}
What is the output if the file content before the execution of the program is the string “ABC”
(Note that” “are not part of the file)
Write a function to count the number of words present in a text file named “PARA.TXT”. Assume that each
word is separated by a single blank/space character and no blanks/spaces in the beginning and end of the file.
c.
Following is the structure of each record in a data file named “COLONY.DAT”.
struct COLONY
{
char Colony
Code[10];
char Colony
Name[10]; int
No of People;
};
Write a function in C++ to update the file with a new value of No _of_People.
The value of Colony_Code and No_of_People are read during the execution of
the program.
2007 Observe the program segment given below carefully and fill the blanks marked as
Statement 1 and Statement 2 using tellg() and seekp() functions for performing the
required task.
#include <fstream.h>
class Customer
{
long Cno;char Name[20], Mobile[12]; public:
//Function to allow user to enter the Cno, Name, Mobile
void Enter();
//Function to allow user to enter (modify) mobile number
2
3
Page 48 of 99
void Modify();
//Fnction to return value of Cno long
GetCno() {return Cno;}
};
void ChangeMobile()
{
Customer C;
fstream
F;
F.open (11 CONTACT. DAT 11 , i.os: :binary I ios: :in I
ios:out) ;
long Cnoc; //Customer no. whose mobile number needs to be
c:;hanC,ed•. cin>>Cnoc;
while (F.read((char*)&C,sizeof(C)))
if (Cnoc==C.GetCno())
C.Modify ();
//Statement 1
int Pos=I /To finq the curret position of file pointer \';•
//Statement 2
//To move the file pointer to write the
.}
//modified record back onto the file
//for the des.ired Cnoc • F.write( (char*)&C,sizeof(C));
}
'
F.close();
2008 Observe the program segment given below carefully and fill the blanks marked as Statement
1 and Statement 2 using seekg( ), seekp( ), tellp( ) and tellg( ) functions for performing the
required task.
# include <fstream.h>
class PRODUCT
{
int Pno ;char Pname [20] ; int Qty ;
public :
void ModifyQty ( )II The function is to modify quantity of a PRODUCT
};
void PRODUCT : : ModifyQty ( )
1
Page 49 of 99
{
fstream File ;
Fil.open ("PRODUCT.DAT", ios : : binary
I ios
: : in
I ios
: : out) ; int MPno;
cout << "Product No to modify quantity :" ;cin>> MPno ;
while (Fil.read ((char*) this, sizeof (PRODUCT) ) )
{
if (MPno= =Pno)
{
cout<< "Present Quantity:" <<Qty<<endl ; cout<< "Changed
Quantity:" ;cin>>Qty ;
int Position =
//Statement 1
//Statement 2
Fil.write ( (char*) this, sizeof (PRODUCT) ) ; I I Re-writing the record
}
}
Fil.cFil.close( ) ;
}
Write a function in C++ to count the no. of "Me" or "My" words present text file "DIARY.TXT".
If the file "DIARY.TXT" content is as follows :
My first book was Me and My family. It gave me chance to be known to the world.
The output of the function should be Count of Me/My in file : 4
Write a function in C++ to search for a laptop from a binary file
"LAPTOP.DAT" containing the objects of class LAPTOP (as defined below).
The user should enter the Model No and the function should search and display
the details of the laptop.
class LAPTOP
{
long ModelNo ;
float RAM, HDD ;
char Details [120] ;
public :
void StockEnter ( ) {cin>>ModelNo>>RAM>>HbD ; gets (Details) ; }
void StockDisplay ( ) {cout<<ModelNo<<RAM<<HDD<<Details<<endl
;} long ReturnModelNo ( ) {return ModelNo ;}
};
2009 Observe the program segment given below carefully and fill the blanks marked as Statement1 and Statement
2 using seekg() , seekp(), tellp() and tellg() functions for performing the required task.
#include<fstream.h>
2
3
Page 50 of 99
Class ITEM
{
Int Ino;
Char Iname[20]; float Price;
Public:
Void ModifyPrice(); // The function is to modify price of a particular ITEM
}:
Void ITEM :: ModifyPrice()
{
Fstream File;
File.Open(“ITEM.DAT”,ios::binary | ios::in | ios::out);
Int CIno;
Cout<<”Item No to modify price :”; cin>>Cino;
While(File.read((char *)this,sizeof(ITEM))
{
If(Cino == Ino)
{
Cout<<”Present Price: ”<<Price<<endl;
Cout<<”Changed Price:”; cin>>Price;
Int FilePos = ___________; // statement 1
_____________________; Statement 2
File.write ((char *) this, sizeof(ITEM)); // Re-writing the record
}
}
File.close();
}
Write a function in C++ to count the no. of “He” or “She” words present in a text file
“STORY.TXT”.
If the file “STORY.TXT” content is as follows :
He is playing in the ground. She is
playing with her dolls.
The output of the function should be
Count of He/She in file :2
2
Write a function in C++ to search for a camera from a binary file "CAMERA.DAT" containing the
objects of class CAMERA (as defined below). The user should enter the Model No and the
function should search and display the details of the camera.
Class CAMERA
{
Long ModelNo;
Float MegaPixel;
Int Zoom;
Char Details[120];
Public:
Void Enter() {cin>>ModelNo>>MegaPixel>>Zoom; gets(Details);}
Void Display() {
Cout<<ModelNo<<MegaPixel<<Zoom<<Details<<endl;}
Long GEtModelNo() { return ModelNo;}
3
};
Page 51 of 99
2010 Observe the program segment given below carefully and fill the blanks marked as
1
---- 2 using tellg() and seekp() functions for performing the
Statement 1 and Statement
required task.
#include <fstream.h> class
Customer
long Cno;char Name[20], Mobile[12]; public:
//Function to allow user to enter the Cno, Name, Mobile
void Enter();
//Function to allow user to enter (modify) mobile number
void Modify();
//Fnction to return value of Cno long
GetCno() {return Cno;}
};
void ChangeMobile()
{
Customer C;
fstream
F;
F.open (11 CONTACT. DAT 11 , i.os: :binary I ios: :in I ios: :out) ;
long Cnoc; //Customer no. whose mobile number needs to
be c:;hanC,ed·. cin>>Cnoc;
while
(F.read( (char*)&C,sizeof(C)))
if (Cnoc==C.GetCno())
C.Modify();
Int Pos = _______________ // To find the current
position of file pointer
//To move the file pointer to write the .}
//modified record back onto the file
//for the des.ired Cnoc
·F.write((char*)&C,sizeof(C));
Page 52 of 99
}
'
F.close();
}
2011 Observe the program segment given below carefully and fill the blanks marked as Statement1 and Statement
2 using seekg() , seekp(), tellp() and tellg() functions for performing the required task.
#include<fstream.h>
Class ITEM
{
Int Ino;
Char Iname[20]; float Price;
Public:
Void ModifyPrice(); // The function is to modify price of a particular ITEM
}:
Void ITEM :: ModifyPrice()
{
Fstream File;
File.Open(“ITEM.DAT”,ios::binary | ios::in | ios::out);
Int CIno;
Cout<<”Item No to modify price :”; cin>>Cino;
While(File.read((char *)this,sizeof(ITEM))
{
If(Cino == Ino)
{
Cout<<”Present Price: ”<<Price<<endl;
Cout<<”Changed Price:”; cin>>Price;
Int FilePos = ___________; // statement 1
_____________________; Statement 2
File.write ((char *) this, sizeof(ITEM)); // Re-writing the record
1
}
}
File.close();
}
Write a function in C++ to count the no. of "He" or "She" words· present in a
text file "STORY.TXT".
If the file "STORY.TXT" content is as follows :
He is playing in the ground. She
is playing with her dolls.
2
The output of the f unction should be
Count of He/She in file: 2
.
Write a function in C++ to search for a camera from a binary file "CAMERA.DAT" containing the
objects of class CAMERA (as defined below). The user should enter the Model No and the
function should search and display the details of the camera.
Class CAMERA
{
Long ModelNo;
3
Page 53 of 99
Float MegaPixel;
Int Zoom;
Char Details[120];
Public:
Void Enter() {cin>>ModelNo>>MegaPixel>>Zoom; gets(Details);}
Void Display() {
Cout<<ModelNo<<MegaPixel<<Zoom<<Details<<endl;}
Long GEtModelNo() { return ModelNo;}
};
2012
Observe the program
that follow :
class
{
segment given below carefully and the questions
Stock
int Ino , Qty ; char
Item [ 2 0 ] ;
public :
void Enter() cin>>Ino; gets(Item); cin>>Qty;}
void Issue(int Q) {Qty -= Q;}
void Purchase(int Q) {Qty + = Q; }
int Getino() { return Ino;}
};
Void PurchaeItem(int Pino, int PQty)
{
f stream Fi le ;
File .open ( " STOCK .DAT " , ios : :binary l ios : :in l ios : :'ou t ) ; Stock
S;
Int Su ccess= O ;
}
while
( Success== O
&&
Fi le . read ( ( cha.r *) & S, sizeof ( S) ) )
if ( Pino==S .Get Ino () )
S .Purchase ( PQty) ;
_________________ // Statement 1
_________________ / / Statement 2
Success++;
if( Su ccess== l }
cout<< "Pu rcha se Updated " < <endl ; else
cout<< "W rong
(i)
Item No" <<endl ; Fi le . close ( ) ;
Write statement 1 to position the file pointer to the appropriate
place, so that the data updation is done for the required item.
1
Page 54 of 99
(ii)Write statement 2 to perform the write operation so that the updation is
done in the binary file.
Write a function in C++ to read the content of a text file
"DELHI.TXT" and display all those lines on screen, which are either
starting with 'D' or starting with 'M'.
Write a function in C++ to search for the details (Phoneno and calls) of those Phones,
which have more than 800 calls from a binary file “Phones.dat”. Assuming that this
binary file contains records objects of class Phone, which is defined below .
2
3
Class Phone
{
char Phoneno[lO];int Calls;
public :
void Get (){gets(Phoneno); cin>>Calls;}
void Billing(){cout<<Phoneno<<"#"<<Cal ls<<endl;}
int GetCalls (){return Calls;}
};
2014
Fill in the blanks marked as Statement 1 and Statement 2, in the program segment given below 1
with appropriate functions for the required task.
class Customer
{
long int CNo; // Customer Number
char CNmae [20]; // customer Name
char Email[30]; // Email of customer
public:
void Allocate(); // Function to allocate a member
void show(); // Function to show customer data
void ModifyEmail() // Function to modify Email
{ cout<<””Enter Modified Email :”;
Gets(Email);
}
long int GetCno() {return CNo; }
};
void ChangeData()
{
fstream File;
Page 55 of 99
File .open (11 CUST.DAT 11 , ios: :binary I ios::in I ios::out) ; int Change=O ,Location;
long int ChangeCno;
cout<<"Cno - whose email required to be modified:"; cin>>ChangeCno;
Customer CU;
while(!Modify && File.read((char*)&CU,sizeof (CU)))
{
if (CU.GetCno()==ChangeCno)
{
CU .ModifyEmail() ; Location=File.tellg()- sizeof (CU);
//Statement l :To place file
pointer to
the required position
//Statement 2:To write
the
object CU on to
the binary file
Change++;
}
}
if (Change)
cout< <"Email Modified ... 11 <<endl; else
cout<< "Customer not found ... 11 <<endl; File .close();
}
Write a function CountHisHer ( ) in C++ which reads the contents of a text file
diary.txt and counts the words His and Her (not case sensitive). For example, if the file contains :
Pinaky has gone to his friend's house. His friend's
name is Ravya. Her house is 12 KM from here.
The function should display the output as
Count for His:2
Count for Her:l
Assuming the class VINTAGE as declared below, write a function in C++ to read the objects of
VINTAGE from binary file VINTAGE.DAT an. d display
those vintage vehicles, which are priced between 200000 and 250000.
class VINTAGE
{
int VNO;
//Vehicle Number
char VDesc[lO] ; //Vehicle Description float Price;
.public :
void GET() {c.in>>VNO;gets {VDesc) ;cin>>Price;} void VIEW {)
2
3
Page 56 of 99
Topics
a
b
c.
d.
e.
Introduction to Networking
Media, Devices, Topologies & Protocol
Security
Web Servers
Open Source Terminologies
{
cout<<VNO<<endl ; cout<<VDesc<<endl; cout<<Price<<endl ;
}
float ReturnPrice {) {return Price;}
};
Chapter: Network and open source software
Group I : Questions that have been repeated at least three or more times : NIL
Group 2 : Questions that have been repeated one or two times
(a)
Topic: Introduction to Networking
1. Differentiate between packet switching over message switching?
1 [2015]
2. Out of the following, which all comes under cyber crime?
1 [2015]
(i)
Stealing away a brand new hard disk from a showroom.
(ii)
Getting in someone’s social networking account without his consent and posting on his behalf.
(iii) Secretly copying data from server of an organization and selling it to other organization.
(iv)
Looking at online activities of a friend’s blog.
3. Which type of network (out of LAN, PAN and MAN) is formed, when you connect two mobiles using
Bluetooth to transfer a video?
1 [2014]
4. In networking, what is WAN ? How is it different from LAN ?
1 [2011]
5. What was the role of ARPANET in the Computer Network?
1 [2010]
6. Which of the following is not a unit for data transfer rate?
1 [2010]
i) mbps
ii) kbps
iii) sbps
Page 57 of 99
iv) gbps
7. What is the difference between LAN and WAN?
8. Expand the following abbreviations:
(i) HTTP
(ii) ARPANET
1 [2009]
1 [2009]
9. Name two switching techniques used to transfer data between two terminals (computers).
1
[2009]
10. Which of the following units measures the speed with which data can be transmitted from one node to
another node of a network? Also, give the expansion of the suggested unit.
1 [2007]
 KMph
 Mbps
 MGps
(b)
Topic: Media, Devices, Topologies & Protocol
1. Illustrate the layout for connecting 5 computers in a bus and a star topology of networks. 1 [2015]
2. Out of the following , which is the fastest (i)wired and (ii)wireless medium of communication ?1 [2015]
Infrared, Coaxial Cable, Ethernet Cable, Microwave, Optical Fiber
3. Write two characteristics of Wi-Fi.
1
[2014]
4. Expand the following:
1
[2014]
a. GSM
b. GPRS
5. Write two advantages of using an optical fiber cable over an Ethernet cable to connect two service
stations, which are 200 m from each other?
1
[2013]
6. What is the difference between HTTP and FTP?
1 [2013]
7. Write one advantage of Bus Topology of the network. Also, illustrate how 4 computers can be connected
with each other using star topology of network.
1 [2012]
8. What is protocol? Which protocol is used to copy a file from/to a remotely located server? 1 [2009]
9. What is a Modem?
1 [2008]
10. Expand the following terms with respect to Networking:
2 [2008]
(i) PPP (ii) GSM (iii) XML (iv) HTTP
11. Expand the following terms with respect to networking :
2 [2007]
i.XML
ii.WWW
iii.WLL
iv.TCP/IP
12. Xclencia Edu Services Ltd. Is an educational organization. It is planning to set up its India campus at
Hyderabad with its head office at Delhi. The Hyderabad campus has 4 main buildings – ADMIN,
SCIENCE, BUSINESS and ARTS. You as a network expert have to suggest network related solutions for
their problems raised in (i) to (iv), keeping in mind the distances between the buildings and other given
parameters.
4 [2015]
HYDERABAD
DELHI
Page 58 of 99
SCIENCE
ADMIN
DELHI HEAD OFFICE
BUSINESS
SS
ARTS
ADMIN to SCIENCE
ADMIN to BUSINESS
ADMIN to ARTS
SCIENCE to BUSINESS
SCIENCE to ARTS
BUSINESS to ARTS
DELHI head Office to HYDERABAD Campus
65m
100m
60m
75m
60m
50m
1600km
ADMIN
100
SCIENCE
85
BUSINESS
40
ARTS
12
DELHI Head Office
20
(i) Suggest the most appropriate location of the server inside the HYDERABAD campus (out of the 4
buildings), to get the best connectivity for maximum number of computers. Justify your answer.
(ii) Suggest and draw the cable layout to efficiently connect various buildings within the HYDERABAD
campus for connecting the computers.
(iii) Which hardware device will you suggest to be procured by the company to be installed to protect
and control the internet uses within the campus?
(iv) Which of the following will you suggest to establish the online face-to-face communication between
the people in the Admin Office of HYDERABAD campus and DELHI Head Office?
(i)
E- Mail
(ii)
Text Chat
(iii) Video Conferencing
(iv)
Cable TV
13. Tech Up Corporation (TUC) is a professional consultancy company. The company is planning to set up
their new offices in India with its hub at Hyderabad. As a network adviser, you have to understand their
requirement and suggest to them the best available solutions. Their queries are mentioned as (i) to (iv)
below.
4
[2014]
Physical Locations of the blocks of TUC:
Page 59 of 99
Block to Block distances (in meters.):
Block (From)
Human Resource
Human Resource
Conference
Block (To)
Conference
Finance
Finance
Distance
60
120
80
Expected Number of Computers to be installed in each block:
Block
Computers
Human Resource
125
Finance
25
Conference
60
i. What will the most appropriate block, where TUC should plan to install their server?
ii. Draw a block to block cable layout to connect all the buildings in the most appropriate
manner for efficient communication.
iii. Which of the following devices will be suggested by you to connect each computer in each
of the buildings?
1. Gateway
2. Switch
3. Modem
iv. What will be the best possible connectivity out of the following, you will suggest to
connect the new setup of offices in Bangalore with its London based office?
 Infrared
 Satellite Link
 Ethernet Cable
14. Rovenza communications international (RCI) is an online corporate training provider company for IT
related courses. The company is setting up their new campus in Kolkata. You as a network expert have to
study the physical locations of various blocks and the number of computers installed. In the planning
phase, provide the best possible answers to the queries(i) to(iv) raised by them.
4 [2013]
Administrative
block
Finance block
Page 60 of 99
Faculty recording block
BLOCK TO BLOCK DISTANCE (IN METRES)
From
To
Administrative Block
Finance Block
Administrative Block
Faculty Recording Block
Finance Block
Faculty Recording Block
Expected computers to be installed in each block
Distance
60
120
70
Block
Computers
Administrative Block
30
Finance Block
20
Faculty Recording Block
100
(i)Suggest the most appropriate block,where RCI should plan to install the server.
(ii)Suggest the most appropriate block to block cable layout to connect all three blocks for efficient
communication.
(iii)Which type of network out of the following is formed by connecting the computers of these three blocks?
a)LAN
b)MAN
c)WAN
(iv)Which wireless channel out of the following should be opted by RCI to connect to students from all over the
world?
a)Infrared
b)Microwave
c)satellite
15.
Workalot Consultants are setting up a secured network for their office campus at Gurgaon for their dayto-day office and web-based activities. They are planning to have connectivity between 3 buildings and
the head office situated in Mumbai. Answer the questions (i) to (iv) after going through the buildings
positions in the campus and the other details, which are given below:
4 [2012]
Head Office
“MUMBAI”
Gurgaon Campus
Page 61 of 99
Building “GREEN”
Building “RED”
Building “BLUE”
Distance between various buildings
Building “GREEN” to Building “RED”
Building “GREEN” to Building “BLUE”
Building “BLUE” to Building “RED”
Gurgaon Campus to Head Campus
110 m
45 m
65 m
1760 KM
Number of Computers
Building “GREEN”
Building “RED”
Building “BLUE”
Head Office
32
150
45
10
(i)
Suggest the most suitable place (i.e. building) to house the server of this organization. Also give
a reason to justify your suggested location.
(ii)
Suggest a cable layout of connections between the buildings inside the campus.
(iii)
Suggest the placement of the following devices with justification:
(1) Switch
(2) Repeater
(iv)
The organization is planning to provide a high speed link with its head office situated in
MUMBAI using a wired connection. Which of the following cables will be most suitable for this
job?
(1) Optical fibre
(2) Co-axial fibre
(3) Ethernet cable
16. Great Sudies University is setting up its Academic schools at Sunder Nagar and planning to set up
Network. The university has 3 academic schools and one administration centre s shown in the diagram
below:
4 [2011]
Business
School
Technology
Page 62 of 99
Centre to centre distances between various buildings is as follows:
Law School to Business School
Law School to Technology School
Law School to Admin School
Business School to Technology School
Business School to Admin School
Technology School to Admin School
Number of computers in each of the Schools/Centre is follows:
Law school
Technology School
Admin school
Business School
60 m
90 m
115 m
40 m
45 m
25 m
25
50
125
35
(i)
Suggest the most suitable most suitable place (i.e. School/Centre) to install the server of this
university with a suitable reason.
(ii)
Suggest an ideal layout for connecting these schools/center for a wired connectivity.
(iii) Which device will you suggest to be placed/installed in each of these schools/center to
efficiently connect all the computers within these schools/centre ?
(iv)
The university is planning to connect its admission office in the closest big city, which is more
than 350 km from the university. Which type of network out of LAN, MAN or WAN will be
formed ? Justify your answer.
17. “Vidhya for All” is an educational NGO. It is setting up its new campus at Jaipur for its web- based
activities. The campus has four buildings as shown in the diagram below:
4 [2010]
MAIN
BUILDING
TRANING
BUILDING
RESOURCE
BUILDING
ACCOUNTS
BUILDING
Center to the center distances between various buildings as per architectural
drawings (in meters) is as followings:
Page 63 of 99
MAIN BUILDING TO RESOURCE BUILDING
120m
MAIN BUILDING TO TRAINING BUILDING
40m
MAIN BUILDING TO ACCOUNTS BUILDING
135m
RESOURCE BUILDING TO TRANING
BUILDING
RESOURCE BUILDING TO ACCOUNTS
BUILDING
TRANING BUILDING TO ACCOUNTS
BUILDING
125m
45m
110m
Expected number of computers in each building is as follows:
MAIN BUILDING
RESOURCE
BUILDING
15
25
TRAINING BUILDING
250
ACCOUNTS BUILDING
10
E1) Suggest a cable layout of connections between the buildings.
E2) Suggest the most suitable place (i.e. building) to house the server for this
NGO. Also, provide a suitable reason for your suggestion.
E3) Suggest the placement of the following devices with justification:
i)
ii)
Repeater
Hub/switch
E4) The NGO is planning to connect its International office situated in Delhi. Which out of the
following wired communication links, will you suggest for a very high speed connectivity?
i)
Telephone analog line
ii)
Optical fibre
iii)
Ethernet cable
18. Eduminds University of India is starting its first campus in a small town Parampur of Central
India with its center admission office in Delhi. The university has 3 major buildings comprising of Admin
Building, Academic Building and Research Building in the 5 KM area Campus.
Page 64 of 99
As the network expert, you need to suggest the network plan as per (E1) to (E4) to the authorities keeping in
mind the distances and other given parameters.
4 [2009]
Eduminds University
Delhi
Parampur Campus
Admission
Research
Building
Academic
Block
Building
Admin
Building
Expected Wire distances between various locations:
Research Building to Admin Building
Research Building to Academic Building
Academic Building to admin Building
Delhi Admission Office to Parampur Campus
90 m
80 m
15 m
1450 m
Expected numbers of Computers to be installed at various locations in the University are as follows:
Research Building
Academic Building
Admin Building
Delhi Admission Office
20
150
35
5
(E1) Suggest the authorities, the cable layout amongst various buildings inside the university campus for
connecting the buildings.
(E2) suggest the most suitable place(i.e., building) to house the server of this organization, with a suitable
reason.
(E3) Suggest an efficient device from the following to be installed in each of the buildings to connect all the
computers:
(i)
(ii)
(iii)
GATEWAY
MODEM
SWITCH
(E4) suggest the most suitable (very high speed) service to provide data connectivity between Admission Building
located in Delhi and the campus located in Parampur from the following options.
Page 65 of 99
(i)
Telephone line
(ii)
Fixed Line dial up connection
(iii) Co axial cable network
(iv)
GSM
(v)
Leased Line
(vi)
Satellite connection
19. “China Middleton Fashion” is planning to expand their network in India, starting with two cities in India
to provide infrastructure for distribution of their product. The company has planned to setup their main
office in Chennai at three different locations and have named their offices as “Production Unit”, “Finance
Unit” and “Media Unit”. The company has its corporate unit in Delhi. A rough layout of the same is as
follows:
4 [2008]
India
Chennai
Corporate
Unit (Delhi)
Production
Unit
Media
Unit
Finance Unit
Approximate distance between these Units is as follows:
From
To
Distance
Production Unit
Finance Unit
70 mtr
Production Unit
Media Unit
15 Km
Production Unit
Corporate Unit
2112Km
Finance Unit
Media Unit
15Km
In continuation of the above, the company experts have planned to install the following number of computers in
each of their offices:
Production Unit
Finance Unit
Media Unit
Corporate Unit
i.
150
35
10
30
Suggest the kind of network required (out of LAN, MAN , WAN )for connecting each of the following
office units :
 Production Unit and Media Unit
 Production Unit and Finance Unit
Page 66 of 99
ii.
Which one of the following devices will you suggest for connecting all the computers within each of
their office units?
 Switch/Hub
 Modem
 Telephone
iii.
Which of the following communication media, you will suggest to be procured by the company for
connecting their local office units in Chennai for very effective (High Speed) communication?
 Telephone Cable
 Optical Fibre
 Ethernet Cable
iv.
Suggest a cable/wiring layout for connecting the company’s local offices units located in Chennai.
Also, suggest an effective method/technology for connecting the company’s office unit located in Delhi.
20. “Hindustan Connecting World Association” is planning to start their offices in four major cities in India
to provide regional IT infrastructure support in the field of education and culture. The company has
planned to set up their head office in New Delhi in three locations and have named their New Delhi
offices as “ Sales office”, “Head office” and ”Tech office”. The company’s regional offices are located at
“Coimbatore”, “Kolkata” and “Ahmadabad”.
4 [2007]
The rough layout of the same is follows:
INDIA
New Delhi
Sales
Office
Tech
Office
Head Office
Ahmedabad
office
Coimbatore
office
Kolkata office
Approximate distances between these offices as per network survey team is as follows:
Place From
Head Office
Head Office
Head Office
Head Office
Head Office
Place To
Sales Office
Tech Office
Kolkata Office
Ahmedabad Office
Coimbatore Office
Distance
10 Km
70 mtr
1291 Km
790 Km
1952 Km
In continuation of the above, the company experts have planned to install the
Page 67 of 99
following number of computers in each of their offices:
Head Office
Sales Office
Tech Office
Kolkata Office
Ahmedabad Office
Coimbatore Office
100
20
50
50
50
50
i. Suggest network type(out of LAN,MAN,WAN) for connecting each of the following set of their offices :


Head office and Tech office
Head office and Coimbatore office
ii. Which device will you suggest to be procured by the company connecting all the computers within each of
their offices out of the following devices?



Modem
Telephone
Switch/Hub
iii. Which of the following communication media, will you suggest to procured by the company for connecting
their local offices in New Delhi for very effective and fast communication?



Ethernet Cable
Optical Fiber
Telephone Cable
iv. Suggest a cable/wiring layout for connecting the company’s local offices located in New Delhi. Also,
suggest an effective method/technology for connecting the company’s regional offices at “Kolkata’,
“Coimbatore” and “Ahmadabad”.
(c)
Topic: Network Security
1. What kind of data gets stored in cookies and how it is useful?
1 [2015]
2. What is Trojan Horse?
1 [2015]
3. Which of the following crime(s) does not come under cybercrime?
1 [2013]
i)
Copying some important data from a computer without taking permission from the owner of the
data.
ii)
Stealing keyboard and mouse from a shop.
iii)
Getting into unknown persons social networking account
4. Which out of the following comes under Cyber Crime?
(i)
Operating someone’s Internet banking account, without his knowledge.
(ii)
Stealing a keyboard from someone’s computer.
1 [2012]
Page 68 of 99
(iii)
5.
6.
7.
8.
Working on someone’s computer with his/her permission.
What are cookies?
What is the difference between Virus & Worms in the computers?
How is a Hacker different from a Cracker?
What is the significance of Cyber law?
(d)
1 [2011]
1 [2010]
1 [2008]
1 [2007]
Topic:Web Servers
1. What is the difference between E-mail and Chat?
1
[2014]
2. Write any two important characteristics of Cloud Computing.
1
[2014]
3. What out of the following, will you use to have an audio-visual chat with an expert sitting in a far-away
place to fix-up a technical issue?
1 [2012]
(i)
VoIP
(ii)
Email
(iii) FTP
4. Name one server side scripting language and one client side scripting language? 1 [2012]
5. Give one suitable example of each URL and domain name.
1 [2012]
6. Differentiate between XML and HTML.
1 [2011]
7. What is WEB 2.0 ?
1 [2011]
8. Out of the following, identify client side script(s) and server side script(s).
1 [2011]
(i) javascript
(ii) ASP
(iii) vbscript
(iv) JSP
9. Name any two common Web browers.
1 [2010]
(e)
Topic: Open Source Terminologies
1. Write the names of any two popular Open Source softwares, which are used as Operating Systems.
1[2014]
2. Write two advantages of using open source software over proprietary software? 1 [2013]
3. Name two Proprietary softwares along with their application.
1 [2012]
4. Compare Open Source Software and Proprietary Software.
1 [2011]
5. Write the full forms of: FTP, FSF.
1 [2010]
QUESTION BANK OF COMPUTER SCIENCE
COMPUTER SCIENCE (THEORY) – 083
CBSE QUESTIONS OF LAST 10 YEARS
Page 69 of 99
Note: In Computer Science CBSE Exam, the pattern of Questions is same, but all questions are distinct.
Chapter : 1 Review of C++ covered in class XI
ONE (01) Marks Questions:
1.Observe the following program very carefully and write the names of those header file(s), which are
essentially needed to compile and execute the following program successfully :
[2015, outside delhi]
typedef char STRING[80];
void main()
{
STRING Txt[] = “We love Peace”;
int Count=0;
while (Txt[Count]!=’\0’)
if (isalpha(Txt[Count]))
Txt[Count++]=’@’;
else
Txt[Count++]=’#’;
puts(Txt);
}
2. Observe the following program very carefully and write the names of those header
file(s), which are essentially needed to compile and execute the following program
successfully :
[2015, Delhi ]
typedef char TEXT[80];
void main()
{
TEXT Str[] = “Peace is supreme”;
int Index=0;
while (Str[Index]!=’\0’)
if (isupper(Str[Index]))
Str[Index++]=’#’;
else
Str[Index++]=’*’;
puts(Str);
}
3. Name the header files that shall be needed for successful compilation of the following C++ code :
[2014, outside Delhi]
void main()
{char str[20], str1[20];
gets(str);
strcpy(str1,str);
strrev(str);
puts(str);
puts(str1); }
Page 70 of 99
4. Observe the following C++ code and write the name(s) of the header file(s), which will be essentially
required to run it in a C++ compiler :
[2014, outside Delhi]
void main()
{
char CH, STR[20];
cin>>STR;
CH=toupper(STR[0]);
cout<<STR<< “starts with” <<CH<<endl;
}
5. Observe the following C++ code and write the name(s) of the header fiIe(s), which will be essentially
required to run it in a C++ compiler :
[2014, Delhi]
void main ( )
{
char Text[20] , C;
cin>>Text;
C = tolower (Text [0]);
cout<<C<<" is the first char of " <<Text<<end1;
}
6. Observe the following C++ code and write the name(s) of the header file(s), which will be essentially
required to run it in a C++ compiler:
[CBSE,2013]
void main ( )
{
int number;
cin >> number;
if (abs (number) = = number);
cout << “Positive” <<endl;
}
7. Write the names of the header files, which is/are essentially required to run/execute the following C++ code:
[CBSE, 2011]
void main ( )
{
char C, String [ ] = "Excellence Overload";
for (int I=0; String [ I ] ! = '\ 0'; I ++ )
if (String [I] ==' ')
cout<<end1;
else
{
C=toupper(String[I]);
cout<<C ;
}
}
8. Which C++ header file(s) will be essentially required to be included to run/execute the following C++ code?
[CBSE, 2010]
void main( )
Page 71 of 99
{
int Eno=123, char Ename[ ]=”Rehan Swamp”;
cout<<setw(5)<<Eno<<setw(25)<<EName<<endl;
}
9. Name the header files that shall be needed for the following code:
void main ( )
[CBSE, 2008]
{
char word [ ]= “Exam”;
Cout << setw (20) << word ;
}
10. Name the header file(s) that shall be needed for successful compilation of the following C++ code :
[CBSE, 2007]
void main( )
{
char Text[40];
strcpy(Text,”AISSCE”);
puts(Text);
}
11. Name the header file(s) that shall be needed for successful compilation of the following C++ code:
[CBSE, 2006]
void main ( )
{
char String [20];
gets (String);
strcat (String, “CBSE”);
puts (String);
}
12. Name the header file to which the following belong:
i. pow ( )
ii. random ( )
[CBSE, 2006-SET1]
13. Name the header file to which the following belong
i. abs ( )
ii. isupper ( )
[CBSE, 2006-SET2]
TWO MARKS QUESTIONS: ( Correct identifiers and Error Detection and Correction)
Page 72 of 99
1.Find the correct identifiers out of the following, which can be used for naming Variable, Constants or
Functions in a C++ program :
[CBSE, outside delhi, 2015]
For, while, INT, NeW, delete, 1stName, Add+Subtract, name1
2. Find the correct identifiers out of the following, which can be used for naming variable, constants or
functions in a C++ program :
[CBSE, 2015, Delhi]
While, for, Float, new, 2ndName, A%B, Amount2, _Counter
3. Observe the following C++ code very carefully and rewrite it after removing any/all syntactical errors with
each correction underlined.
Note : Assume all required header files are already being included in the program.
[CBSE, 2014, Outside Delhi set-I]
#define float MaxSpeed=60.5;
void main()
{
int MySpeed
char Alert=’N’;
cin≫MySpeed;
if MySpeed>MaxSpeed
Alert=’Y’;
cout<<Alert<<endline;
}
Q4. Observe the following C++ code very carefully and rewrite it after removing
any/all syntactical errors with each correction underlined.
Note : Assume all required header files are already being included in the program.
[CBSE outside delhi, 2014]
#Define float Max=70.0;
Void main()
{
int Speed
char Stop=’N’;
cin>>Speed;
if Speed>Max
Stop=’Y’;
cout<<Stop<<end;
}
Q 5. Deepa has just started working as a programmer in STAR SOFTWARE company. In the company she has
got her first assignment to be done using a C++ function to find the smallest number out of a given set of
numbers stored in a one-dimensional array. But she has committed some logical mistakes while writing the
code and is not getting the desired result. Rewrite the correct code underlining the corrections done. Do not add
any additional statements in the corrected code.
[CBSE, 2013]
int find(int a[],int n)
Page 73 of 99
{ int s=a[0];
for(int x=1;x<n;x++)
if(a[x]>s)
a[x]=s;
return(s);
}
Q 6. Rewrite the following C++ code after removing all the syntax error(s), if present in the code. Make sure
that you underline each correction done by you in the code.
[CBSE 2012]
Important Note :
– Assume that all the required header files are already included, which are essential to run this code.
– The corrections made by you do not change the logic of the program.
typedef char[80] STR;
void main()
{
Txt STR;
gets(Txt);
cout<<Txt[0]<<’\t<<Txt[2];
cout<<Txt<<endline;
}
Q 7. Rewrite the following C++ code after removing all the syntax error(s), if present in the code. Make sure
that you underline each correction done by you in the code.
Important Note :
[CBSE, 2011]
- Assume that all the required header files are already included, which are essential to run this code.
- The corrections made by you do not change the logic of the program.
typedef char [50] STRTNG;
void main ( )
{
City STRING;
gets (City) ;
cout<<City [0] <<’ \t<<City [2] ;
cout << City << endline ;
}
Q 8. Rewrite the following program after removing the syntactical errors (if any).
Underline each correction.
[CBSE, 2010]
#include[iostream.h]
typedef char Text(80) ;
void main ( )
{
Text T= "Indian";
int Count=strlen(T) ;
cout<<T<<'has'<<Count<< 'characters' <<end1;
}
Page 74 of 99
Q 9. Rewrite the following c++ program code after removing the syntax error(s) (if any). Underline each
correction.
[CBSE, 2009]
include <iostream.h>
class TRAIN
{
long TrainNo;
char Description[25];
public
void Entry ( )
{
cin >>TrainNo; gets(Description);
}
Void Display ( )
{
cout<<TrainNo<<“:”<<Description<<endl;
}
};
void main( )
{
TRAIN T;
Entry. T( ); Display. T( );
}
Q 10. Rewrite the following C++ program code after removing the syntax error(s) (if any). Underline each
correction.
[CBSE, 2008]
include <iostream.h>
class FLIGHT
{
long FlightCode;
char Description [25];
public
void AddInfo ( )
{
cin >> FlightCode;
}
gets(Description);
void ShowInfo ( )
{
cout << FlightCode << “:” << Description << endl;
}
};
void main ( )
{
Page 75 of 99
FLIGHT F;
AddInfo. F ( );
ShowInfo ( );
}
Q 11. Rewrite the following c++ program code after removing the syntax error(s) (if any). Underline each
correction.
[CBSE, 2007]
include <iostream.h>
class TRAIN
{
long TrainNo;
char Description[25];
public
void Entry ( )
{
cin >>TrainNo; gets(Description);
}
Void Display ( )
{
cout<<TrainNo<<“:”<<Description<<endl;
}
};
void main( )
{
TRAIN T;
Entry. T( ); Display. T( );
}
Q 12. Rewrite the following program after removing the syntax error(s), if any. Underline each correction.
[CBSE, 2006, SET-III]
# include <iostream.h>
void main ( )
{
One=10, Two = 20;
Callme (One; Two);
Callme (Two);
}
void Callme ( int Arg1, int Arg2 = 20)
{
Arg1 = Arg1 + Arg2;
cout << Arg1 >> Arg2;
}
Q 13. Rewrite the following program after removing the syntactical error(s), if any. [CBSE, 2006, SET-II]
Underline each correction.
#include <iostream.h>
const int Size 5;
void main()
Page 76 of 99
{
int Array[Size];
Array = {50,40,30,20,10};
for(Ctr=0; Ctr<Size; Ctr++)
cout>>Array[Ctr];
}
Q 14. Rewrite the following program after removing the syntactical error(s) if any.
[CBSE, 2006, SET-I]
Underline each correction.
# include <iostream.h>
const int Max 10;
void main ( )
{
int Numbers [Max];
Numbers = { 20, 50,10, 30,40 } ;
for (Loc= Max-1 ; Loc > = 0 ; Loc - -)
cout>>Numbers [Loc];
}
Q 15. Rewrite the following program after removing the syntactical error(s), if any Underline each correction,
#include <iostream.h>
void main( )
{ struct TV
{ char Manu_name[20];
char Tv_Type;
int Price = 17000;
} New Tv;
gets(Manu_name);
gets(Tv_Type);
}
Q 16. Rewrite the following program after removing the syntactical error(s), if any. Underline each correction.
#include <iostream.h>
void main( )
{ struct movie
{ char movie_name [20];
char movie type;
int ticket cost = 100;
}MOVIE;
gets(movie_name);
gets(movie_type);
}
Q 17. Rewrite the following program after removing the syntactical error(s), if any. Underline each correction.
[CBSE, 2006]
# include <iostream.h>
void main()
{ struct STUDENT
{ char stu_name [20];
char stu_sex;
Page 77 of 99
int stu_age=17;
} student;
gets(stu_name);
gets(stu_sex);
}
CHAPTER-2 :Object Oriented Programming in C++:
Output Questions 02 Marks each (Combination of chapter 1 and chapter 2)
Q 1. Write the output of the following C++ program code :
Note : Assume all required header files are already being included in the program.
[CBSE, 2015, Outside Delhi]
void Location(int &X, int Y=4)
{
Y+=2;
X+=Y;
}
void main()
{
int PX=10,PY=2;
Location(PY);
cout<<PX<<”,”≪PY<<endl;
Location(PX,PY);
cout<<PX<<”,”≪PY<<endl;
}
Q 2. Write the output of the following C++ program code :
Note : Assume all required header files are already being included in the program. [CBSE, 2015, Delhi]
void Position(int &C1,int C2=3)
{
C1+=2;
C2+=Y;
}
void main()
{
int P1=20, P2=4;
Position(P1);
cout<<P1<<”,”<<P2<<end1;
Position(P2,P1);
cout<<P1<<”,”<<P2<<end1;
}
Q 3. Find output of the following program segment :
[CBSE, 2014, Outside Delhi-I]
#include<iostream.h>
#include<ctype.h>
void Mycode(char Msg[],char CH)
{
Page 78 of 99
for(int cnt=0;Msg[cnt]!=‘\0’;cnt++)
{ if(Msg[cnt]>=‘B’&& Msg[cnt]<=‘G’)
Msg[cnt]=tolower(Msg[cnt]);
else
if(Msg[cnt]==‘N’||Msg[cnt]==‘n’ || Msg[cnt]==‘’)
Msg[cnt]=CH;
else
if(cnt%2==0)
Msg[cnt]=toupper(Msg[cnt]);
else
Msg[cnt]=Msg[cnt–1];
}}
void main( )
{ char MyText[]="Input Raw";
Mycode(MyText,‘@’);
cout<<"NEW TEXT:"<<MyText<<endl; }
Q 4. Obtain the output from the following C++ program as expected to appear on the screen after its execution.
[CBSE, 2014, Outside Delhi]
Important Note :
- All the desired header files are already included in the code, which are required to run the code.
void main()
{
char *Text= “AJANTA”;
int *P, Num[ ]={1,5,7,9};
P=Num;
cout<<*P<<Text<<endl;
Text++;
P++;
cout<<*P<<Text<<endl;
}
Q 5. Obtain the output from the following c++ program as expected to appear on the screen after its execution.
Important Note :
- All the desired header files are already included in the code, which are required to run the code.
void main ( )
[CBSE, 2014, Delhi]
{
char *String = “SARGAM” ;
int *ptr, A [ ] = { 1,5,7,9 };
Ptr = A;
cout << * ptr << String<< end1 ;
String++;
Ptr+=3;
cout<< * Ptr << String<<endI;
}
Q 6. Find the output of the following program:
[CBSE, 2013]
#include<iostream.h>
Page 79 of 99
void main ( )
{
int Track [ ] = {10, 20, 30, 40}, *Striker ;
Stxiker=Track :
Track [1] += 30 ;
cout<<"Striker>"<<*Striker<<end1 ;
Striker – =10 ;
Striker++ ;
cout<<"Next@"<<*Striker<<end1 ;
Striker+=2 ;
cout<<"Last@"<<*Striker<<end1 ;
cout<< "Reset To" <<Track[0] <<end1 ;
}
Q 7. Find the output of the following program :
#include <iostream.h>
#include <ctype.h>
void ChangeIt(char Text[ ], char C)
{
for (int K=0;Text[K]!='\0';K++)
{
if (Text[K]>=’F’ && Text[K]<=’L’)
Text[K]=tolower(Text[K]);
else
if (Text[K]=’E’ || Text[K]==’e’)
Text[K]= =C;
else
if (K%2==O)
Text[K]=toupper(Text[K]);
else
Text[K]=Text[K-l];
}
}
void main ( )
{
char OldText[ ]=”pOwERALone”;
ChangeIt(OldText,’%’);
cout<<“New TEXT:”<<OldText<<endl;
}
[CBSE, 2011]
Q 8. Find the output of the following program :
[CBSE, 2010]
# include <iostream.h>
void main ( )
{
int A=5, B=10;
for (int I= 1; I <= 2; I+ +)
{
cout << “Line1=” <<A++ << “&” << B-2 <<endl;
Page 80 of 99
cout << “Line2=” << ++B << “&” <<A+3 <<endl;
}
}
Q 9. Find the output of the following program :
#include<iostream.h>
void main()
{
int Numbers[] = {2,4,8,10};
int *ptr = Numbers;
for (int C = 0; C<3; C++)
{
cout<< *ptr << “@”;
ptr++;
}
cout<<endl;
for(C = 0; C<4; C++)
{
(*ptr)*=2;
--ptr;
}
for(C = 0; C<4; C++)
cout<< Numbers [C]<< “#”;
cout<<endl;
}
[CBSE,2010-setI]
Q 10. Find the output of the following program :
# include < iostream.h>
void main ( )
{
intArray[] = {4,6,10,12};
int *pointer = Array ;
for (int I=1 ; I<=3 ; I++)
{
cout<<*pointer<<#”;
pointer ++;
}
cout<<endl;
for (I=1 ; I<=4 ; I++)
{
(*pointer)*=3 ;
-- pointer;
}
for(I=l; I<5; I + + )
cout << Array [I-1] << “@”;
cout << endl;
}
[CBSE,2008]
Q 11. Find the output of the following program:
#include < iostream.h>
[CBSE, 2007-II]
Page 81 of 99
void main( )
{ int *Pointer Array [10];
int marks [ ]= {75, 68, 90, 34, 0, 10, 90, 65};
for (int I = 0; marks [ I]!=0; I++)
{
PointerArray [I]=&marks[I];
* (PointerArray [I] ) += 5;
}
int index = 0;
while(index < I )
{
int p=*(PointerArray[index] );
if(p >=60) cout <<p<<’,’;
index ++;
}
}
Q 12. Find the output of the following program:
#include<iostream.h>
void main()
{ long Number = 7583241;
int First=0, Second=0;
do
{
int R=Number%10;
if (R%2==0)
First+=R;
else
Second+=R;
Number /=10;
} while (Number>O);
cout<<First-Second;
}
[CBSE, 2007]
Q 13. Find the output of the following program:
#include<iostream.h>
[CBSE, 2006]
void main( )
{ long NUM = 1234543;
int F = 0, S = 0;
do
{ int Rem = NUM% 10;
if (Rem % 2 !=0)
F+ =R;
else
S+ = R;
NUM/=10;
} while(NUM>0);
cout<<F-S;
}
OUTPUT QUESTIONS OF (03 Marks each):
Q 1. Write the output of the following C++ program code :
Page 82 of 99
Note : Assume all required header files are already being included in the program.
[CBSE, 2015, Outside Delhi]
class Eval
{
char Level;
int Point;
public:
Eval(){Level=’E’;Point=0;}
void Sink(int L)
{
Level-=L;
}
void Float(int L)
{
Level+=L;
Point++;
}
void Show()
{
cout<<Level<<”#”<<Point<<endl;
}
};
void main()
{
Eval E;
E.Sink(3);
E.Show();
E.Float(7);
E.Show();
E.Sink(2);
E.Show();
}
Q 2. Write the output of the following C++ program code :
Note : Assume all required header files are already being included in the program.
[CBSE, 2015, Delhi]
class Calc
{
char Grade;
int Bonus;
public:
Calc() {Grade=’E’;Bonus=0;}
void Down(int G)
{
Grade–=G;
}
Void Up(int G)
Page 83 of 99
{
Grade+=G;
Bonus++;
}
void Show()
{
cout<<Grade<<”#”<<Bonus<<end1;
}
};
void main()
{
Calc c;
C.Down(2);
C.Show();
C.Up(7);
C.Show();
C.Down(2);
C.Show();
}
Q 3. Find the output of the following program :
[CBSE, 2014,Outside Delhi-I]
#include<iostream.h>
void in(int x,int y, int &z)
{
x+=y;
y– –;
z*=(x–y);
}
void out(int z,int y, int &x)
{
x*=y;
y++;
z/=(x+y);
}
void main()
{
int a=20, b=30, c=10;
out(a,c,b);
cout<<a<<"#"<<b<<"#"<<c<<"#"<<endl;
in(b,c,a);
cout<<a<<"@"<<b<<"@"<<c<<"@"<<endl;
out(a,b,c);
cout<<a<<"$"<<b<<"$"<<c<<"$"<<endl;
}
Q 4. Obtain the output of the following C++ program, which will appear on the screen after its execution.
Important Note :
[CBSE, 2014,Outside Delhi]
● All the desired header files are already included in the code, which are required to run the code.
class Game
{
int Level, Score;
Page 84 of 99
char Type;
public:
Game(char GType=’P’)
{Level=1;Score=0;Type=GType;}
void Play(int GS);
void Change();
void Show()
{
cout<<Type<<”@”<<Level<<endl;
cout<<Score<<endl;
}
};
void main()
{
Game A(‘G’),B;
B.Show();
A.Play(11);
A.Change();
B.Play(25);
A.Show();
B.Show();
}
void Game::Change()
{
Type=(Type==’P’)?’G’:’P’;
}
void Game::Play(int GS)
{
Score+=GS;
if(Score>=30)
Level=3;
else if(Score>=20)
Level=2;
else
Level=1;
}
Q 5. Observe the following C++ code carefully and obtain the output, which will appear on the screen after
execution of it.
[cbse, 2014, delhi]
# include <iostream.h>
class Aroundus
{
int Place, Humidity, Temp;
public :
Aroundus (int p=2) { Place=P; Humidity = 60; Temp = 20;}
void Hot (int T) { Temp += T;}
void Humid (int H) { Humidity + = H;}
void JustSee ( )
Page 85 of 99
{
cout << Place << “:” <<Temp << “&” << Humidity
<< “%” <<endl;
}
};
void main ( )
{
Aroundus A, B(5);
A. Hot (10);
A.JustSee( );
B.Humid (15);
B.Hot (2);
B.JustSee ( );
A.Humid (5);
A.justSee( );
}
Q 6. Find the output of the following program:
#include<iostream.h>
[cbse, 2013]
void ChangeArray(int Number, int ARR[ ], int Size)
{
for (int L =0; L<Size; L++)
if (L<Number)
ARR [L] +=L;
e1se
ARR [L] *=L;
}
void Show (int ARR [ ], int Size)
{
for (int L=0; L<Size; L++)
(L%2!=0) ?cout<<ARR[L] <<"#": cout<<ARR[L]<<end1 ;
}
void main ( )
{
int Array [ ] = {30, 20, 40, 10, 60, 50};
ChangeArray (3, Array, 6) ;
Show (Array, 6) ;
}
Q 7. Find the output of the following program :
#inc1ude <iostream.h>
struct POINT
{int X, Y, Z;};
void StepIn(POINT & P, int Step=1)
{
P.X+=Step;
P.Y -=Step;
P.Z+=Step;
}
[cbse, 2011]
Page 86 of 99
void StepOut(POINT & P, int Step=1)
{
P.X-=Step;
P.Y+=Step;
P.Z–=Step;
}
void main ( )
{
POINT P1={15, 25, 5}, P2={10, 30, 20};
StepIn(P1);
StepOut(P2,4);
cout<<P1.X<<“,”<<P1.Y<<“,”<<P1.Z<<endl;
cout<<P2.X<<“,”<<P2.Y<<“,”<<P2.Z<<endl;
StepIn(P2,12);
cout<<P2.X<<“,”<<P2.Y<<“,”<<P2.Z<<endl;
}
Q 8. Find the output of the following program:
[CBSE, 2008]
#include<iostream.h>
#include <ctype.h>
void main ()
{
Char Mystring[] = “What@OUTPUT!”;
for (int I = 0; Mystring [ I ] = ‘\0’ ; I++)
{
if ( isalpha (Mystring [ I ] ) )
Mystring [ I ] = ‘ * ’;
else
if
( isupper (Mystring [ I ]) )
Mystring [ I ] = Mystring [ I ] + 1;
else
Mystring [ I ] = Mystring [ I + 1];
}
cout<< Mystring;
}
Page 87 of 99
Q 9. Find the output of the following program :
[CBSE-2007-II]
#include<iostream.h>
void Indirect(int Temp=20)
{
for (int I=10; I<=Temp; I+=5)
cout << I <<”, “;
cout << endl ;
}
void Direct (int &Num)
{
Num + = 10;
Indirect (Num) ;
}
void main()
{
int Number=20;
Direct(Number);
Indirect();
cout<< “ Number=” <<Number<<endl ;
}
Q 10. Find the output of the following program :
# include < iostream.h>
void Withdef (int HisNum = 30)
{
for (int 1=20 ; I<*= HisNum; I+=5)
cout<<I<<””;
cout<<endl;
}
void Control (int &MyNum)
{
MyNum+=10;
Withdef(MyNum);
}
void main ()
{
int YourNum=20;
Control (YourNum);
Withdef();
cout<<”Number=”<<YourNum<<endl;
}
Q 11. Find the output of the following program
# include<iostream.h>
#include<string.h>
class state
{
char * state_name;
int size;
public;
[CBSE, 2007-I]
[CBSE, 2006]
Page 88 of 99
state( ); { size=0; state_name=new char[size+1]; }
state(char *s)
{ size = strlen(s) ; state_name = new char[size+1];}
strcpy(state_name,s);
}
void display() {cout<<state name<<endl; }
void Replace (state &a, state &b)
{ size = a.size + b.size;
delete state_name;
state_name = new char[size+1] ;
strcpy(state_name, a.state_name);
strcat(state_name, b.state_name);
}
};
void main( )
{ char *temp = “Delhi”;
state state1(temp), state2(”Mumbai”), state3(”Nagpur”), SI, S2;
SI .Replace(state1, state2);
S2.Replace(S1, state3);
S1.display( );
S2.display( );
}
RANDOMIZE ( ) FUNCTIONS: 02 Marks each
Q 1. Study the following program and select the possible output(s) from the options (i) to (iv) following it. Also,
write the maximum and the minimum values that can be assigned to the variable VAL.
[CBSE, 2015, Outside Delhi]
Note :
– Assume all required header files are already being included in the program.
– random(n) function generates an integer between 0 and n-1.
void main()
{
randomize();
int VAL;
VAL=random(3)+2;
char GUESS[]=”ABCDEFGHIJK”;
for (int I=1;I<=VAL; I++)
{
for(int J=VAL; J<=7;J++)
cout≪GUESS[J];
cout<<endl;
}
Page 89 of 99
}
(i)
BCDEFGH
BCDEFGH
(ii)
CDEFGH
CDEFGH
(iii)
EFGH
EFGH
EFGH
EFGH
(iv)
FGHI
FGHI
FGHI
FGHI
Q 2. Study the following program and select the possible output(s) from the options (i)
to (iv) following it. Also, write the maximum and the minimum values that can be
assigned to the variable NUM.
Note :
[CBSE, 2015, DELHI]
– Assume all required header files are already being included in the program.
– random(n) function generates an integer between 0 and n – 1.
void main()
{
randomize();
int NUM;
NUM=random(3)+2;
char TEXT[]=”ABCDEFGHIJK”;
for (int I=1;I<=NUM; I++)
{
for(int J=NUM; J<=7;J++)
cout<<TEXT[J];
cout<<end1;
}
}
(i) FGHI
(ii) BCDEFGH
FGHI
BCDEFGH
FGHI
FGHI
(iii) EFGH
EFGH
EFGH
EFGH
(iv) CDEFGH
CDEFGH
Q 3. Read the following C++ code carefully and find out, which out of
the given options (i) to (iv) are the expected correct output(s) of it.
Also, write the maximum and minimum value that can be assigned to the variable Taker used in the code :
[CBSE, 2014, Outside Delhi]
void main( )
{
int GuessMe[4]={100,50,200,20};
int Taker=random(2)+2;
for (int Chance=0;Chance<Taker;Chance++)
}
(i) 100#
(ii) 50# 200#
(iii) 100# 50# 200#
(iv) 100# 50
Page 90 of 99
Q 4. Based on the following C++ code, find out the expected correct output(s) from the option (i) to (iv). Also,
find out the minimum and the maximum value that can be assigned to the variable Trick used in the code at the
time when value of Count is 3:
[cbse, 2013]
void main ( )
char Status [ ]
[10] = { “EXCEL”, “ GOOD”, “OK” };
int Turn = 10, Trick;
for (int
Count = 1; Count < 4; Count ++ )
{
Trick = random ( Count ) ;
cout << Turn –Trick << Status [ Trick ] << “ #” ;
}
}
(i)
(ii)
10 EXCEL # 10 EXCEL # 80 K #
10 EXCEL # 80 K # 9GOOD#
(iii)
10 EXCEL # 9GOOD # 10 EXCEL #
(iv)
10 EXCEL# 10 GOOD # 80 K #
Q 5. Go through the C++ code shown below, and find out the possible output or
outputs from the suggested Output Options (i) to (iv). Also, write the least
value and highest value, which can be assigned to the variable Guess.
#include <iostream.h>
[CBSE 2011]
#include <stdlib.h>
void main ( )
{
randomize ( ) ;
int Guess, High=4;
Guess=random{High)+ 50 ;
for{int C=Guess ; C<=55 ; C++)
cout<<C<<"#" ;
}
(i) 50 # 51 # 52 # 53 # 54 # 55 #
(ii) 52 # 53 # 54 # 55
(iii) 53 # 54 #
(iv) 51 # 52 # 53 # 54 # 55
Q 6. The following code is from a game, which generates a set of 4 random numbers. Yallav is playing this
game, help him to identify the correct option(s) out of the four choices given below as the possible set of such
Page 91 of 99
numbers generated from the program code so that he wins the game. Justify your answer.
2010]
#include <iostream.h>
#include <stdlib.h>
const int LOW=15;
void main ( )
{
randomize( ) ;
int POINT=5, Number;
for (int 1=1;I<=4;I++)
{
Number=LOW+random(POINT) ;
cout<<Number<<“:” ;
POINT--;
}
}
(i) 19:16:15:18:
(ii) 14:18:15:16:
(iii) 19:16:14:18:
(iv) 19:16:15:16:
Q 7. In the following program, find the correct possible output(s) from the options:[CBSE 2008]
#include <stdlib.h>
#include <iostream.h>
void main ( )
{
randomize ( );
char Area [ ] [ 10 ] = { “ NORTH” , “SOUTH” , “ EAST”, “WEST”);
int ToGo;
for ( int I = 0 ; I<3; I++ )
{
To Go = random (2) + 1;
[CBSE
Page 92 of 99
cout<< Area [ToGo ]<< “:”;
}
}
Outputs:
(i)
SOUTH:EAST:SOUTH:
(ii)
NORTH: SOUTH: EAST:
(iii)
SOUTH: EAST: WEST:
(iv)
SOUTH: EAST: EAST:
Q 8. In the following C++ program what is the expected value of MyMarks from Options (i) to (iv) given
below. Justify answer.
[CBSE, 2007]
#include<stdlib.h >
# include<iostream.h>
void main ()
{
randomize ();
int Marks [ ]= {99, 92, 94, 96, 93, 95}, MyMarks;
MyMarks = Marks [1 + random (2) ];
cout<<MyMarks<<endl;
}
(i) 99
(ii) 94
(iii) 96
(iv) None of the above
Q 9. In the following C++ program what is the expected value of Myscore from Options (i) to (iv) given below.
Justify your answer.
#include<stdlib.h>
#include<iostream.h>
void main( )
{
randomize();
int Score[] = {25,20,34,56, 72, 63}, Myscore;
Myscore = Score[2 + random(2)];
cout<<Myscore<<endl; }
(i) 25
(ii) 34
(iii) 20
(iv) None of the above
Implementation of OOP Concepts:
Page 93 of 99
CHAPTER (01, 02, 03, 04)
OOP CONCEPTS (02 MARKS EACH)
Q1.Explain in brief the purpose of function prototype with the help of a suitable example.
[CBSE, 2014, Outside Delhi]
Q2. Explain data hiding with an example.
[CBSE, 2014, Outside Delhi]
Q3. What is the difference between call by reference and call by value
with respect to memory allocation ? Give a suitable example to
illustrate using C++ code.
[CBSE, 2014, Outside Delhi set -II]
[CBSE, 2010]
Q4. What is the difference between actual and formal parameter ? Give a suitable example to illustrate using a
C++ code.
[CBSE, 2014, Delhi]
Q5. What is the difference between Local Variable and Global Variable? Also, give a suitable C++ code to
illustrate both.
[CBSE, 2011]
Q6. Differentiate between members, which are present within the private visibility mode with those which are
present within the public visibility modes.
[CBSE, 2011]
Q7. What is the purpose of using a typedef command in C++. Explain with suitable example.
[CBSE, 2008]
Q8. Differentiate between private and public visibility modes in context of Object Oriented Programming
giving a suitable example illustrating each.
[CBSE, 2008]
Q9. Differentiate between a Run Time Error and Syntax Error. Also give suitable examples of each in C++.
[CBSE, 2007]
Q 10. Illustrate the use of inline function in C++ with the help of an example.
[CBSE, 2006, SET-II]
Q. 11. Illustrate the use of #define in C++ to define a macro.
[CBSE, 2006, SET-I]
Q12. What are Nested Structures? Give an example.
[CBSE, 2006, SET-I]
CHAPTER -04
CLASSES AND OBJECTS (04 MARKS EACH)
Q 1.Write the definition of a class Photo in C++ with following description:
[CBSE, 2015, Outside Delhi]
Page 94 of 99
Private Members
– Pno
//Data member for Photo Number (an integer)
– Category
//Data member for Photo Category (a string)
– Exhibit
//Data member for Exhibition Gallery (a string)
– FixExhibit //A member function to assign
//Exhibition Gallery as per Category
//as shown in the following table
Category
Exhibit
Antique
Zaveri
Modern
Johnsen
Classic
Terenida
Public Members
– Register()
– ViewAll()
//A function to allow user to enter values
//Pno, Category and call FixExhibit() function
//A function to display all the data members
Q 2. Write the definition of a class PIC in C++ with following description :
[CBSE, 2015, DELHI]
Private Members
– Pno
//Data member for Picture Number (an integer)
– Category
//Data member for Picture Category (a string)
– Location
//Data member for Exhibition Location (a string)
– FixLocation //A member function to assign
//Exhibition Location as per category
//as shown in the following table
Category
Location
Classic
Amina
Modern
Jim Plaq
Antique
Ustad Khan
Public Members
– Enter()
– SeeAll()
//A function to allow user to enter values
//Pno, category and call FixLocation() function
//A function to display all the data members
Page 95 of 99
Q 3. Define a class CONTEST in C++ with the following description :
Private Data Members
[CBSE, 2014, Outside Delhi]
Eventno
integer
Description
char(30)
Score
integer
qualified
char
Public Member functions
● A constructor to assign initial values Eventno as 11, Description as ‘‘School level’’, Score as 100, qualified as
‘N’.
● Input() – To take the input for Eventno, description and score.
● Award (int cutoffscore) – To assign qualified as ‘Y’, if score is more than the cutoffscore that is passed as
argument to the function, else assign qualified as ‘N’.
● Displaydata() – to display all data members.
Q 4. Define a class Tourist in C++ with the following specification :
[CBSE, 2014, Delhi]
Data Members
● CNo - to store Cab No
● CType - to store a character ‘A’, ‘B’, or ‘C’ as City Type
● PerKM - to store per Kilo Meter charges
● Distance - to store Distance travelled (in KM) Member Functions
● A constructor function to initialize CType as ‘A’ and CNo as 0000’
● A function CityCharges( ) to assign PerKM as per the following table :
CType
PerKM
A
B
C
20
18
15
● A function RegisterCab() to allow administrator to enter the values for CNo and CType. Also, this function
should call CityCharges() to assign PerKM Charges.
● A function Display() to allow user to enter the value of Distance and display CNo, CType, PerKM,
PerKM*Distance (as Amount) on screen.
Q 5. Define a class Tourist in C++ with the following specification.
[ CBSE 2013]
Page 96 of 99
Data Members :






Carno - To store Bus No
Origin - To store Place Name
Destination - To store Place Name
Type - To store Car Type such as “E” for Economy
Distance - To store Distance as Kilometers
Charge - To store the Car Fare.
Member Functions :


A constructor function to initialize Type as ‘E’ and Freight as 250
A function CalcCharge ( ) to calculate the fare as per the following criteria :
Type


Charge
‘E’
16* Distance
‘A’
22 * Distance
‘ L’
30 * Distance
A function Enter ( ) to allow the user to enter the values of Carno, Origin, Destination, Type and
Distance. Also, this function should call CalcCharge ( ) to calculate Fare.
A function Show ( ) to display the content of all the data members on screen.
Q 6. Define a class Candidate in C++ with following description:
[CBSE, 2011]
Private Members
_ A data member RNo (Registration Number) of type long
_ A data member Name of type string
_ A data member Score of type float
_ A data member Remarks of type string
_ A member function AssignRem( ) to assign Remarks as per the Score obtained by a candidate. Score range
and the respective Remarks are shown as follows:
Score
Remarks
>=50
Selected
less than 50
Not selected
Public Members
_ A function ENTER ( ) to allow user to enter values for RNo, Name, Score & call function AssignRem( ) to
assign the remarks.
_ A function DISPLAY ( ) to allow user to view the content of all the data members.
Q 7. Define a class ITEM in C++ with following description:
Private Members
[CBSE, 2010]
Page 97 of 99






Code of type integer (Item Code)
Iname of type string (Item Name)
Price of type float (Price of each item)
Qty of type integer (Quantity of item in stock)
Offer of type float (Offer percentage on the item)
A member function GetOffer() to calculate Offer percentage as per the following rule:
If Qty<=50
If 50<Qty<=100
If Qty>100
Offer is 0
Offer is 5
Offer is 10
Public Members
 A function GetStock() to allow user to enter values for Code, Iname, Price, Qty and call function
GetOffer() to calculate the offer
 A function ShowItem() to allow user to view the content of all the data members.
Q 8. Define a class Clothing in C++ with the following descriptions :
Private Members :
Code
of type string
Type
of type string
Size
of type integer
Material
of type string
Price
of type float
A function Calc_Price ( ) which calculates and assigns the value of Price as follows :
For the value of Material as “COTTON” :
TYPE
Price (Rs)
TROUSER
1500
SHIRT
1200
For Material other than “COTTON” the above mentioned Price gets reduced by 25%.
Public Members :

A constructor to assign initial value of Code, Type and Material with the words “ NOT ASSIGNED”
and Size and Price with 0.
Page 98 of 99

A function Enter ( ) to input the values of data members Code, Type, Size and Material and invoke the
Calc_Price ( ) function.

A function Show ( ) which displays the content of all the members for a Clothing.
Q 9. Define a class Tour in C++ with the description given below :
[CBSE, 2007]
Private Members :
TCode of type string
NoofAdults of type integer
NoofKids of type integer
Kilometres of type integer
TotalFare of type float
Public Members :
• A constructor to assign initial values as follows :
TCode with the word “NULL”
NoofAdults as 0
NoofKids as 0
Kilometres as 0
TotalFare as 0
• A function AssignFare ( ) which calculates and assigns the value of
the data member TotalFare as follows
For each Adult
Fare(Rs)
For Kilometres
500
>=1000
300
< 1000 & > =500
200
< 500
For each Kid the above Fare will be 50% of the Fare mentioned in
the above table
For example :
If Kilometres is 850, NoofAdults = 2 and NoofKids = 3
Then TotalFare should be calculated as
NumofAdults * 300 + NoofKids * 150
i.e. 2*300 + 3*150=1050
• A function EnterTour( ) to input the values of the data members TCode, NoofAdults, NoofKids and
Kilometres; and invoke the Assign Fare( ) function.
• A function ShowTour( ) which displays the content of all the data members for a Tour.
Page 99 of 99
Q 10. Define a class named ADMISSION in C++ with the following descriptions:
[CBSE, 2006]
Private members:
AD_NO integer (Ranges 10 - 2000)
NAME Array of characters (String)
CLASS Character
FEES Float
Public Members:
 Function Read_Data ( ) to read an object of ADMISSION type
 Function Display() to display the details of an object
 Function Draw-Nos ( ) to choose 2 students randomly. And display the details. Use random function to
generate admission nos. to match with AD_NO.
Q 11. Define a class named HOUSING in C++ with the following descriptions:
[CBSE, 2006, SET-II]
Private members
REG_NO integer(Ranges 10 — 1000)
NAME Array of characters(String)
TYPE Character
COST Float
Public Members
· Function Read_Data( ) to read an object of HOUSING type
· Function Display() to display the details of an object
· Function Draw Nos( ) to choose and display the details of 2 houses selected randomly from an array of
10 objects of type HOUSING Use random function to generate the registration nos. to match with
REGNO from the array.
Download