Class 12 Computer Science Practice Sheet: CBSE Class 12 Computer Science Revision Worksheet Set 01
Review targeted academic worksheets with the CBSE Class 12 Computer Science Revision Worksheet Set 01. Built according to official educational standards for the 2026-27 term, these downloadable Class 12 Computer Science resources support effective daily practice and detailed self-evaluation for All Chapters.
Download All Chapters Worksheet PDF with Answers
Navigate directly to the solved Computer Science worksheets using the digital viewer below. Each practice set includes detailed step-by-step solutions, allowing students to instantly cross-check their work and identify areas requiring further revision.
1. a) Write a Get1From2( ) function in C++ to transfer the content from two arrays FIRST[]
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 array SECOND[].
Example:
If the FIRST[] array contain
30,60,90
And the SECOND[] array contain
10,50,80
The ALL[] array should contain
30,10,60,50,90,80
b) An array T[50][20] is stored in the memory along the column with each of the element occupying 4 bytes, find out the base address and address of element T[30][15], if an element T[25][10] is stored at the memory location 9800.
c) Write a function QUEDEL() in C++ to display and delete an element in a dynamically allocated Queue containing nodes of the following given structure:
struct NODE
{ int Itmemo;
char Iteamname[20];
NODE *Link; };
d) Define a function SWAPARR() in C++ to swap (interchange) the first row elements with the last row elements, for a two dimensional integer array passed as the argument of the function.
Example: If the two dimensional array contains
1. Find the output of the following programs:
i) #include<iostream.h>
#include<string.h>
#include<ctype.h>
void main( )
{
char NAME = “admiNStrAtiOn”;
for( int x=0;x<strlen(NAME);x++)
if(islower(NAME[x])
NAME[x] = toupper(NAME[x]);
else
if(isupper (NAME[x]))
if(x%2==0)
NAME[x] = NAME[x -1];
else
NAME[x]--;
cout<<NAME <<endl;
}
ii) #include<iostream.h> #include<conio.h>
#include<ctype.h>
class Metro
{
int Mno,TripNo,PassengerCount;
public:
Metro(int Tmno=1)
{
Mno=Tmno;
TripNo=0;
PassengerCount=0;
}
void Trip(int PC=20)
{
TripNo++;
PassengerCount+=PC;
}
void StatusShow()
{
cout<<Mno<<":"<<TripNo<<":"<<PassengerCount<<endl;}
} ;
void main()
{
Metro M(5),T;
M.Trip();
T.Trip(50);
M.StatusShow();
M.Trip(30);
T.StatusShow();
M.StatusShow();
}
iii) #include<iostream.h>
#include<ctype.h>
typedef char Str80[80];
void main()
{
char *Notes;
Str80 Str="vR2GooD";
int L=6;
Notes=Str;
while(L>=3)
{
Str[L]=(isupper(Str[L])?tolower(Str[L]):toupper(Str[L])) ;
cout<<Notes<<endl;
L--;
cout<<L;
Notes++;
}
}
iv) #include<iostream.h>
void main()
{
char *Text=”AJANTA”;
int *p, Num[]={1,5,7,9};
p=Num;
cout<<*p<<Text<<endl;
Text++;
p++;
cout<<*p<<Text<<endl;
}
2. a) What would be the last value of A displayed out?
#include<iostream.h>
void main( )
{ int A = 10;
while(++ A < 10)
{
cout<<A++;
}
}
b) In the following program, if the value of Guess entered by the user is 65, what will be the expected output(s) from the following options (i), (ii), (iii) and (iv)?
#include <iostream.h>
#include <stdlib.h>
void main()
{
int Guess,New;
randomize();
cin>>Guess;
for (int I=1;I<=4;I++)
{
New=Guess+random(I);
cout<<(char)New;
}
}
(i) ABBC
(ii) ACBA
(iii)ABCC
(iv) CABD
c) Observe the following program and find out, which output(s) out of (i) to (iv) will be expected from the program? What will be the minimum and the maximum value assigned to the variable Guess used in the code at the time when value of Turn is 3?
#include<iostream.h>
#include<stdlib.h>
void main( )
{
randomize( );
char Result[][10]={“GOLD”, “SILVER”, “BRONZE”};
int Getit=9, Guess;
for(int Turn=1; Turn<4; Turn++)
{
Guess=random(Turn);
cout<<Getit-Guess<<Result[Guess]<<”*”;
}
}
i) 9GOLD*9GOLD*8SILVER*
ii) 9GOLD*7BRONZE*8GOLD*
iii) 9GOLD*8SILVER*9GOLD*
iv) 9GOLD*8SILVER*8GOLD*
3. a) Write the function headers for constructor and destructor of a class Race.
b) When the object is passed to the function the copy of the object is made. Does constructor and destructor are called for the object copy?
c) Answer the questions (i) and (ii) after going through the following program: class Basketball
{ int Time;
public:
Basketball() //Function 1
{
Time = 0;
cout<<”Match commences “<<endl;
}
void Details() //Function 2
{
cout<<”Inter Section Basketball Match”<<endl;
}
Basketball(int Duration) //Function 3
{
Time = Duration;
cout<<”Another match begins now”<<endl;
}
Basketball(Basketball &M) //Function 4
{
Time = M.Duration;
Cout<<”Like Previous Match”<<endl;
}
};
(i) Which category of constructor – Function 4 belongs to and what is the purpose of using it?
(ii) Write statements that would call the member Functions 1 and 3.
d) Define a class bank to represent the bank account of a customer with the following specifications:
private members:
- name of the depositor char (20)
- account no int
- type of account ( s for saving, c for current account) char(1)
- balance amount (float)
member functions:-
- ini( ) to initialize data members
- deposit( ) to deposit money
- withdraw( ) for withdraw of money. Mony can be withdraw if minimum balance > = 1000
- display( ) to display data members
e) 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.
f) Answer the questions (i) to (v) based on the following:
class PUBLISHER
{
char Pub[12];
double Turnover;
protected:
void Register();
public:
PUBLISHER();
void Enter();
void Display();
};
class BRANCH
{
char CITY[20];
protected:
float Employees;
public:
BRANCH();
void Haveit();
void Giveit();
};
class AUTHOR : private BRANCH , public PUBLISHER
{
int Acode;
char Aname[20];
float Amount;
public:
AUTHOR();
void Start();
void Show();
};
(i) Write the names of data members, which are accessible from objects belonging to class AUTHOR.
(ii) Write the names of all the member functions which are accessible from objects belonging to class BRANCH.
(iii) Write the names of all the members which are accessible from member functions of class AUTHOR.
(iv) How many bytes will be required by an object belonging to class AUTHOR?
(v) Name the type of inheritance illustrated in the above C++ code.
4. a) Observe the program segment given below carefully and answer the question that follows
class school
{private:
char name[25];
int numstu;
public:
void inschool( );
void outschool( );
int retnumstu( )
{return numstu; }
};
void modify(school A)
{ fstream INOUT;
INOUT.open(“school.dat”,ios::binary|ios::in|ios::ate);
school B;
int recread=0, found=0;
while(!found && INOUT.read((char*)&B,sizeof(B))
{ recread++;
if(A.retnumstu( )= = B.retnumstu( ))
{
__________________//missing statement
INOUT.write((char*)&A,sizeof(A));
Found=1;
}
else
INOUT.write((char*)&B,sizeof(B));
}
if(!found)
cout<<”\nRecord for modification does not exist”;
INOUT.close( );
}
If the function modify( ) is supposed to modify a record in file school.dat with the values of school A passed to its argument, write the appropriate statement for missing statement using seekp( ) or seekg( ), whichever needed, in the above code that would write the modified record at its proper place.
b) Write a function to count the number of blanks present in a text file named “PARA.TXT”.
c) Following is the structure of each record in a data file named “PRODUCT.DAT”. struct PRODUCT
{ char Prodact_Code[10];
char Product_Descriptionil[10];
int Stock;
};
Write a function in C++ to update the file with a new value of Stock. The Stock and the Product Code, whose Stock to be updated, are read during the execution of the program.
1. Answer the questions (i) and (ii) after going through the following class:
class Seminar
{
int Time;
public:
Seminar() //Function 1
{
Time=30;cout<<"Seminar starts now"<<end1;
}
void Lecture() //Function 2
{
cout<<"Lectures in the seminar on"<<end1;
}
Seminar(int Duration) //Function 3
{
Time=Duration;cout<<"Seminar starts now"<<end1;
}
~Seminar()
//Function 4
{
cout<<"Vote of thanks"<<end1;
}
};
i) In Object Oriented Programming, what is Function 4 referred as and when does it get
invoked/called?
ii) In Object Oriented Programming, which concept is illustrated by Function 1 and
Function 3 together? Write an example illustrating the calls for these functions.
2. Answer the questions (i) to (iv) based on the following:
class PUBLISHER
{
char Pub[12];
double Turnover;
protected:
void Register();
public:
PUBLISHER();
void Enter();
void Display();
};
class BRANCH
{
char CITY[20];
protected:
float Employees;
public:
BRANCH();
void Haveit();
void Giveit();
};
class AUTHOR : private BRANCH , public PUBLISHER
{
int Acode;
char Aname[20];
float Amount;
public:
AUTHOR();
void Start();
void Show();
};
(i) Write the names of data members, which are accessible from objects belonging to class AUTHOR.
(ii) Write the names of all the member functions which are accessible from objects belonging to class BRANCH.
(iii) Write the names of all the members which are accessible from member functions of class AUTHOR.
(iv) How many bytes will be required by an object belonging to class AUTHOR?
3. Write a function in C++ to merge the contents of two sorted arrays A & B into
third array C. Assuming array A and B are sorted in ascending order and the
resultant array C is also required to be in ascending order.
4. Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement 2 using seekp() and seekg() functions for performing the required task.
#include <fstream.h>
class Item
{
int Ino;char Item[20];
public:
//Function to search and display the content from a particular record number
void Search(int );
//Function to modify the content of a particular record number
void Modify(int);
};
void Item::Search(int RecNo)
{
fstream File;
File.open("STOCK.DAT",ios::binary|ios::in);
______________________ //Statement 1
File.read((char*)this,sizeof(Item));
cout<<Ino<<"==>"<<Item<<endl;
File.close();
}
void Item::Modify(int RecNo)
{
fstream File;
File.open("STOCK.DAT",ios::binary|ios::in|ios::out);
cout>>Ino;cin.getline(Item,20);
______________________ //Statement 2
File.write((char*)this,sizeof(Item));
File.close();
}
5. Write a function in C++ to count the number of lines present in a text file "STORY.TXT".
6. Write a function in C++ to search for a BookNo from a binary file "BOOK.DAT", assuming the binary file is containing the objects of the following class.
class
{
int Bno;
char Title[20];
public:
int RBno(){return Bno;}
void Enter(){cin>>Bno;gets(Title);}
void Display(){cout<<Bno<<Title<<endl;}
};
7.Answer the questions (i) and (ii) after going through the following program:
class Match
{
int Time;
public:
Match() //Function 1
{
Time=0;
cout<<"Match commences"<<end1;
}
void Details() //Function 2
{
cout<<"Inter Section Basketball Match"<<end1;
}
Match(int Duration) //Function 3
{
Time=Duration;
cout<<"Another Match begins now"<<end1;
}
Match(Match &M) //Function 4
{
Time=M.Duration;
cout<<"Like Previous Match "<<end1;
}
};
i) Which category of constructor - Function 4 belongs to and what is the purpose
of using it?
ii) Write statements that would call the member Functions 1 and 3
Q1.Name the header file(s) that shall be needed for the following code :
void main()
{
char Text[]=”Computer Science”;
cout<<setw(20)<<Text;
}
Q2.Rewrite the following C++ program code after removing the syntax error(s) (if any) . Underline each correction.
#include<iostream.h>
class Product
{
char P_name[20];
float Rate;
Product()
{
strcpy(P_Name,"Sheet");
Rate=450;
}
public:
void Display()
{
cout<<P_Name<<":"<<Rate<<endl;
}
};
void main()
{
Product P;
Display.P();
}
Q3.Find the output of the following program code :
#include<iostream.h>
struct Box
{
int Len, Bre, Hei;
};
void Measure(Box B)
{
cout<<B.Len<<":"<<B.Bre<<":";
cout<<B.Hei<<endl;
}
void main()
{
Box B1={10,20,30},B2,B3;
++B1.Hei;
Measure(B1);
B2=B1;
++B2.Len;
B2.Bre++;
Measure(B2);
B3=B2;
B3.Hei+=5;
B3.Len-=2;
Measure(B3);
}
Q4.Find the output of the following program code:
#include<iostream.h>
#include<ctype.h>
void Mycode(char Msg[], char ch)
{
for(int I=0;Msg[I]!='\0';I++)
{
if((Msg[I]>='B')&&(Msg[I]<='G'))
Msg[I]=tolower(Msg[I]);
else
if((Msg[I]=='A')||(Msg[I]=='a'))
Msg[I]=ch;
else
if(I%2==0)
Msg[I]=toupper(Msg[I]);
else
Msg[I]=Msg[I-1];
}
}
void main()
{
char Mytext[]="HyPERActiVE";
Mycode(Mytext,'@');
cout<<"Changed Text is : "<<Mytext<<endl;
}
Q5.Study the following program and select the possible output from it . Justify your answer.
#include<iostream.h>
#include<stdlib.h>
const int first=25;
void main()
{
randomize();
int last=5,mid;
for(int cnt=1;cnt<=4;cnt++)
{
mid=first+random(last);
cout<<mid<<"*";
last--;
}
}
i. 29*26*25*28*
ii. 24*28*25*26*
iii. 29*26*24*28*
iv. 29*26*25*26*
Q6.Define a class ITEM in C++ with the following description :
Private members :
*ICode 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 item)
*A member function Disc() to calculate discount as per the following rule :
If Qty=50 Discount is 0
If 50<Qty<=100 Discount is 5%
If Qty>100 Discount is 10%
Public members:
*A constructor to assign initial values of Item with the word “NOT ASSIGNED” and other members as 0;
*A function Purchase() to allow the user to enter values for ICode , Item, Price, Qty and call function Disc() to calculate the discount.
*A function View() to allow the user to view the content of all the data members.
Q7.Consider the following and answer the questions that follow:
class CEO
{
double Turnover;
protected:
int Noofcomp;
public:
CEO();
void input(int);
void output();
};
class Director:public CEO
{
int noofemp;
public:
Director();
void INDATA();
void OUTDATA();
protected:
float funds;
};
class Manager:protected Director
{
float expenses;
public:
void Display(void);
};
1. Which constructor will be called first at the time of declaration of object of class Manager?
2. How many bytes will an object belonging to the class Manager require?
3. Name the member functions thet can be accessed by an object of class Manager?
4. Is the member function output() accessible by the objects of class Director?
Q8.Given a binary file named SPORT.DAT containing records of the following structure type.
struct Sport
{
char SportName[20];
char Participant[10][30];
};
Write a function in C++ that would read contents from the file SPORT.DAT and creates a file named FOOT.DAT copying only those records from SPORT.DAT when the game name is “Foot Ball”.
Q9. An array A[40][50] is stored in the memory along the row with each element occupying 4 bytes. Find out the base address and address of the element A[10][40] , if the element A[5][20] is stored at the address 5500 .
Q10. Write a function change() in C++ , which accepts an array of integers and its size as parameters and divide all those array elements by 10 which are divisible by 10 and multiply other array elements by 2.
Sample input:
| A[0] | A[1] | A[2] | A[3] | A[4] |
| 10 | 6 | 15 | 30 | 12 |
Sample output:
| A[0] | A[1] | A[2] | A[3] | A[4] |
| 1 | 12 | 30 | 3 | 24 |
1. What is an operating system? What are its functions?
2. What do you mean by utility software? Give one example.
3. What do you mean by Non-Pre emptive scheduling? Give examples
4. What do you meant by Pre emptive scheduling? Give examples.
5. What is meant by multiprogramming and multitasking?
6. Define device management.
7. Define file management.
8. What is a bus? How are they classified?
9. Convert (4A8C)16 to binary.
10. Convert 10010110101110 to hexadecimal.
11. Convert the following binary number to decimal
(a)10010 (b)101010
12. Convert the decimal no 84 to its binary equivalent.
13. Which character is automatically added to a string in C++?
14. What are the difference between a keyword and an identifier?
15. What is the input operator ”>>” and output operator “<<” called?
16. Write a program in C++ to accept marks in five subjects for a student and display the average mark.
17. Write a program in C++ to accept marks in five subjects for a student and display the average mark.
18. What is the difference between Runtime and Syntax errors?
19. What will be the character size of the following constants: ‘\a’, “\a”, “sachin\’s bat”.
20. What will be the character size of the following constants: ‘\a’, “\a”, “sachin\’s bat”.
21. What type of constants are the following: 14,011, 3.123, 0xA.
22. Given the following two definitions
Unsigned int u1=0, u2=7;
What is the result of each of the following expressions?
(a) u1&&u2 (b)u1||u2 (c)!u1 (d)!!u1
23. Given the following set of identifiers:
char ch;
short sh;
int intval;
log longval;
float fl;
Identify he datatype of the following expressions:
(a)’a’-3 (b) intval * longval - ch (c) fl + longval / sh
24. Predict and rectify errors:
int main()
{
cout<<enter the two numbers;
cin>>num>>auto;
float area= length*breadth;
cout<<area is<<area
}
25. Point out the errors in the following program
void main()
{ cout<<”Enter a number”;
cin>>no;
square=no*no
cout<<”The square is”<<square;
26. Correct the errors if any in the following expressions:
i) cout<<”a” a;
ii) cout>>”you are a fool”;
iii) int a; b ;
iv) include<conio.h>
27. Write a program in c++ to convert temperature in Celsius to Fahrenheit?
28. What output will be the following code fragment produce? Downloaded from
int val, res, n=1000;
cin>>val;
res = n+val >1750 ? 400 : 200;
cout<<res;
i) if the input is 2000 ii) if the input is 500
29. What is the result of the following expression:
a>=b&&(a+b)>a
(1) a=3,b=0 (2)a=7,b=7
30. Evaluate X=a++ + --a; if a=20 initially?
31. Write a c++ program to input two numbers and print their quotient and reminder ?
32. What data type is required for a variable to store 34000?
33. What is meant by type conversion?
34. What is meant by type promotion?
35. Program to accept three numbers and print the largest of these three numbers.
36. Write a program in c++ to check whether a given number is even or odd?
37. Write a program to calculate the factorial of an integer.
38. Write a program to print the first n natural umbers and their sum.
39. Write an alternative code for the following using switch-case construct:
char wish;
if( wish== ‘a’)
cout<< “ YOU WILL GETT 40 OUT OF 40”;
else if( wish== ‘b’)
cout<< “ MY FRIEND WILL GET 40 OUT OF 40”;
else if( wish== ‘c’)
cout<< “ TEACHER WILL NOT GIVE 40 OUT OF 40”;
else
cout<<”NO ONE WILL GET 40 OUT OF 40”;
40. Predict the out put :
i) for (int a=10;a>=0;a-=3);
cout<<a;
ii) for( int outer=1;outer<10;outer+=4)
41. Write a program to print first n natural numbers and their sum.
42. Write a program to calculate and print the roots of a quadratic equation ax2+bx+c=0.
43. Write a program to check whether a number is prime or not.
44. Write equivalent while loop for the following for loop:
int sum;
for( int i=0,sum=0;i<10;i++)
sum+=i;
cout<< sum;
Questions:
Question 1. a) Write a Get1From2( ) function in C++ to transfer the content from two arrays FIRST[] 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 array SECOND[].
Example:
If the FIRST[] array contain
30,60,90
And the SECOND[] array contain
10,50,80
The ALL[] array should contain
30,10,60,50,90,80
Answer:
```cpp void Get1From2(int FIRST[], int SECOND[], int ALL[], int N) { for (int i = 0; i < N; i++) { ALL[2 * i] = FIRST[i]; // Assigns to even index positions (0, 2, 4, ...) ALL[2 * i + 1] = SECOND[i]; // Assigns to odd index positions (1, 3, 5, ...) } } ```
In simple words: This function takes two arrays of the same size and weaves their elements together into a third array, putting elements from the first array in even indexes and elements from the second array in odd indexes.
Exam Tip: Remember that for an element at index i in the source arrays, its corresponding even position in the target array is 2 * i and the odd position is 2 * i + 1.
Question 1. b) An array T[50][20] is stored in the memory along the column with each of the element occupying 4 bytes, find out the base address and address of element T[30][15], if an element T[25][10] is stored at the memory location 9800.
Answer:
Since the array is stored along the column, we use the Column-Major formula to find the address of $T[i][j]$:
$$\text{Address}(T[i][j]) = \text{Base Address} + W \times [ j \times R + i ]$$
Where:
- Number of Rows ($R$) = 50
- Number of Columns ($C$) = 20
- Size of each element ($W$) = 4 bytes
- Given element address: $\text{Address}(T[25][10]) = 9800$
Step 1: Find the Base Address $$\text{Address}(T[25][10]) = \text{Base Address} + 4 \times [ 10 \times 50 + 25 ]$$ $$9800 = \text{Base Address} + 4 \times [ 500 + 25 ]$$ $$9800 = \text{Base Address} + 4 \times [ 525 ]$ $$9800 = \text{Base Address} + 2100$$ $$\text{Base Address} = 9800 - 2100 = 7700$$
Step 2: Find the Address of $T[30][15]$ $$\text{Address}(T[30][15]) = 7700 + 4 \times [ 15 \times 50 + 30 ]$$ $$\text{Address}(T[30][15]) = 7700 + 4 \times [ 750 + 30 ]$$ $$\text{Address}(T[30][15]) = 7700 + 4 \times [ 780 ]$ $$\text{Address}(T[30][15]) = 7700 + 3120$$ $$\text{Address}(T[30][15]) = 10820$$
In simple words: First we calculate the base (starting) address of the array, which is 7700, using the known address of T[25][10] in column-major order. Then, we use this base address to locate the target element T[30][15] at memory address 10820.
Exam Tip: Be careful with row-major vs. column-major indexing instructions. Column-major formula multiplies the column index by the total number of rows (R).
Question 1. c) Write a function QUEDEL() in C++ to display and delete an element in a dynamically allocated Queue containing nodes of the following given structure:
struct NODE
{ int Itmemo;
char Iteamname[20];
NODE *Link; };
Answer:
```cpp void QUEDEL(NODE *&front, NODE *&rear) { if (front == NULL) { cout << "Queue Underflow! No items to delete.\n"; return; } NODE *temp = front; // Display details of the node being deleted cout << "Deleted Item Code: " << temp->Itmemo << "\n"; cout << "Deleted Item Name: " << temp->Iteamname << "\n"; // Move front pointer to the next node front = front->Link; // If the queue becomes empty, update rear pointer to NULL if (front == NULL) { rear = NULL; } // Free the memory of deleted node delete temp; } ```
In simple words: This function displays the details of the item at the front of the queue, advances the front pointer to the next element, and then frees up the memory of the deleted node.
Exam Tip: Always make sure to set the rear pointer to NULL if deleting the last remaining node makes the queue completely empty.
Question 1. d) Define a function SWAPARR() in C++ to swap (interchange) the first row elements with the last row elements, for a two dimensional integer array passed as the argument of the function.
Example: If the two dimensional array contains
5 6 3 2
1 2 4 9
2 5 8 1
9 7 5 8
After swapping of the content of first row and last row, it should be as follows:
9 7 5 8
1 2 4 9
2 5 8 1
5 6 3 2
Answer:
```cpp void SWAPARR(int A[4][4], int R, int C) { for (int j = 0; j < C; j++) { int temp = A[0][j]; A[0][j] = A[R - 1][j]; A[R - 1][j] = temp; } } ```
In simple words: This function loops through all columns and swaps each element in the top row (row 0) with the corresponding element in the bottom row (row R-1).
Exam Tip: Keep the column dimensions in the function argument matching the fixed-size array requirements of standard C++ compilers.
Question 1. e) Convert the following infix expression to its equivalent postfix expression showing stack contents for the conversion:
A+B*(C - D)/ E
Answer:
Let us trace the conversion process step-by-step using an operator stack:
| Element Scanned | Stack Status | Postfix Expression |
|---|---|---|
| A | (empty) | A |
| + | + | A |
| B | + | AB |
| * | + * | AB |
| ( | + * ( | AB |
| C | + * ( | ABC |
| - | + * ( - | ABC |
| D | + * ( - | ABCD |
| ) | + * | ABCD- |
| / | + / | ABCD-* |
| E | + / | ABCD-*E |
| (end) | (empty) | ABCD-*E/+ |
The equivalent postfix expression is: **ABCD-*E/+**
In simple words: By using a stack to keep track of operations, we convert the expression so that mathematical operators appear after their corresponding variables.
Exam Tip: When scanning '/' while '*' is at the top of the stack, pop '*' because division and multiplication have equal precedence, and operators are processed left-to-right.
Question 2. a) Write a function in C++ to combine the contents of two equi-sized arrays A and B by adding their corresponding elements as the formula A[i]+B[i]; where value i varies from 0 to N-1 and transfer the resultant content in the third same sized array C.
Answer:
```cpp void CombineArrays(int A[], int B[], int C[], int N) { for (int i = 0; i < N; i++) { C[i] = A[i] + B[i]; } } ```
In simple words: This code loops through two equal-sized arrays, adds their corresponding index values, and places the resulting sum into a third array.
Exam Tip: Remember to pass array sizes as function arguments to avoid hardcoding issues and ensure versatility.
Question 2. b) Write a function in C++ which accepts an integer array and its size as arguments and exchanges the values of first half side elements with the second half side elements of the array. E.g. If the array contains values as 2, 4, 1, 6, 7, 9, 23, 10. The function should rearrange array as 7, 9, 23, 10, 2, 4, 1, 6
Answer:
```cpp void exchangeHalves(int arr[], int size) { int half = size / 2; for (int i = 0; i < half; i++) { int temp = arr[i]; arr[i] = arr[i + half]; arr[i + half] = temp; } } ```
In simple words: This function finds the midpoint of the array and swaps each element in the first half with its corresponding partner in the second half.
Exam Tip: Ensure your swap loop only runs up to size/2; continuing further will swap the elements back to their original positions.
Question 2. c) An array P[20][30] is stored in the memory along the row with each of the element occupying 2 bytes, find out the base address of the array, if an element P[2][20] is stored at the memory location 5000.
Answer:
Since the array is stored along the row, we use the Row-Major formula to find the address of $P[i][j]$:
$$\text{Address}(P[i][j]) = \text{Base Address} + W \times [ i \times C + j ]$$
Where:
- Number of Rows ($R$) = 20
- Number of Columns ($C$) = 30
- Size of each element ($W$) = 2 bytes
- Given element address: $\text{Address}(P[2][20]) = 5000$
Calculate Base Address: $$5000 = \text{Base Address} + 2 \times [ 2 \times 30 + 20 ]$$ $$5000 = \text{Base Address} + 2 \times [ 60 + 20 ]$$ $$5000 = \text{Base Address} + 2 \times [ 80 ]$$ $$5000 = \text{Base Address} + 160$$ $$\text{Base Address} = 5000 - 160 = 4840$$
In simple words: By using the row-major formula with the known coordinate of memory location 5000, we find that the very first element (the base address) of this 2-byte array is stored at memory location 4840.
Exam Tip: For Row-Major storage, remember that the row index is multiplied by the total number of columns (C) in the array structure.
Question 2. d) Write a function in C++ to perform PUSH on a dynamically allocated Stack containing Passenger details as given in the following definition of NODE.
struct NODE
{
long Pno; //passenger Number
char Pname[20]; //passenger Name
NODE *Link ;
} ;
Answer:
```cpp void PUSH(NODE *&top, long passengerNo, const char passengerName[]) { NODE *temp = new NODE; if (temp == NULL) { cout << "Stack Overflow! Out of memory.\n"; return; } temp->Pno = passengerNo; strcpy(temp->Pname, passengerName); temp->Link = top; top = temp; } ```
In simple words: This function allocates memory for a new node, populates it with passenger details, hooks it to point to the current top of the stack, and then updates the top pointer to this new node.
Exam Tip: Remember to pass the top pointer by reference (NODE *&top) so changes persist after the function ends.
Question 2. e) Evaluate the following postfix notation of expression:
True, False, AND, True, True, NOT, OR, AND
Answer:
Let us trace the evaluation of this boolean postfix expression using an operand stack:
| Token Scanned | Operation | Stack Contents |
|---|---|---|
| True | Push | [True] |
| False | Push | [True, False] |
| AND | Pop False, Pop True. Evaluate (True AND False) | [False] |
| True | Push | [False, True] |
| True | Push | [False, True, True] |
| NOT | Pop True. Evaluate (NOT True) | [False, True, False] |
| OR | Pop False, Pop True. Evaluate (True OR False) | [False, True] |
| AND | Pop True, Pop False. Evaluate (False AND True) | [False] |
The final evaluated result of the postfix expression is: **False**
In simple words: We push boolean values onto a stack and evaluate logical operators (like AND, OR, NOT) using the values on top of the stack until a single final result is obtained.
Exam Tip: Pay attention to unary operators like NOT, which only pop a single operand from the stack, unlike binary operators (AND, OR) which require two operands.
Question 3 a) Write a function SWAP2BEST(int ARR[ ],int Size) in C++ to modify the content of the 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
Answer:
```cpp void SWAP2BEST(int ARR[], int Size) { int i = 0; while (i < Size - 1) { if (ARR[i] % 10 == 0) { // Swap element with the very next element int temp = ARR[i]; ARR[i] = ARR[i + 1]; ARR[i + 1] = temp; i += 2; // Move past the swapped pair } else { i++; } } } ```
In simple words: This function looks through the array. If it finds a number ending in 0 (multiple of 10), it swaps it with the next number and then skips past both of them to prevent multiple swaps.
Exam Tip: Ensure that you skip the index forward by 2 after a successful swap to avoid swapping the same element repeatedly down the array.
Question 3 b) An array V[40][10] is stored in the memory along the column with each of the element occupying 4 bytes, Find out the address of the location V[3][6] if the location V[30][10] is stored at the address 9000.
Answer:
Let us solve this step-by-step using Column-Major storage (assuming 1-based indexing as the column index 10 is specified):
$$\text{Address}(V[i][j]) = \text{Base Address} + W \times [ (j - 1) \times R + (i - 1) ]$$
Where:
- $R = 40, C = 10$
- $W = 4$ bytes
- $\text{Address}(V[30][10]) = 9000$
Step 1: Calculate Base Address $$9000 = \text{Base Address} + 4 \times [ (10 - 1) \times 40 + (30 - 1) ]$$ $$9000 = \text{Base Address} + 4 \times [ 9 \times 40 + 29 ]$$ $$9000 = \text{Base Address} + 4 \times [ 360 + 29 ]$$ $$9000 = \text{Base Address} + 4 \times [ 389 ]$$ $$9000 = \text{Base Address} + 1556$$ $$\text{Base Address} = 9000 - 1556 = 7444$$
Step 2: Calculate Address of $V[3][6]$ $$\text{Address}(V[3][6]) = 7444 + 4 \times [ (6 - 1) \times 40 + (3 - 1) ]$$ $$\text{Address}(V[3][6]) = 7444 + 4 \times [ 5 \times 40 + 2 ]$ $$\text{Address}(V[3][6]) = 7444 + 4 \times [ 202 ]$$ $$\text{Address}(V[3][6]) = 7444 + 808 = 8252$$
In simple words: First we calculate the starting memory address of the column-major array, which is 7444. Using this, we find that the element V[3][6] resides at address 8252.
Exam Tip: Note that regardless of whether you assume 0-based indexing (with index 10 treated mathematically) or 1-based indexing, the relative spacing and final address calculation yield the same result.
Question 3 c) Write a function in C++ to perform Insert operation in static circular Queue containing Players information (represented with the help of an array of structure PLAYER).
struct PLAYER
{
long PID ; // Player ID
char Pname [20] ; // Player Name
};
Answer:
```cpp const int SIZE = 50; // Defining maximum size of static circular queue void InsertPLAYER(PLAYER Queue[], int &front, int &rear, PLAYER player) { if ((rear + 1) % SIZE == front) { cout << "Queue Overflow! Unable to insert player.\n"; return; } if (front == -1) { front = 0; // Initialize front on first insertion } rear = (rear + 1) % SIZE; Queue[rear] = player; } ```
In simple words: This function adds a new player's information to a circular array. It checks if the queue is full, increments the rear position in a loop, and copies the data.
Exam Tip: Remember the modulus operation (rear + 1) % SIZE is what enables the index to cycle back to the beginning of the array, making it circular.
Question 3 d) Write a function CHANGE( ) in C++, which accepts a 2-D array of integer and its size as parameters and divide all those array elements by 7 which are not in the range 70 to 700 and find the square root of all other elements.
Answer:
```cpp #include
In simple words: This function loops through all elements of a grid. For each value, it checks if it is between 70 and 700; if yes, it replaces the value with its square root. Otherwise, it divides the value by 7.
Exam Tip: Using double or float for array types is ideal here since division and square roots often produce decimal results.
Question 3 e) Evaluate the following POSTFIX notation. Show status of Stack after every step of evaluation (i.e., after each operator)
32, 4, /, 2, *, 12, 3, -, +
Answer:
Let us trace the step-by-step evaluation of the numerical postfix expression:
| Token Scanned | Action Taken | Stack Status |
|---|---|---|
| 32 | Push | [32] |
| 4 | Push | [32, 4] |
| / | Pop 4, Pop 32. Evaluate (32 / 4 = 8) | [8] |
| 2 | Push | [8, 2] |
| * | Pop 2, Pop 8. Evaluate (8 * 2 = 16) | [16] |
| 12 | Push | [16, 12] |
| 3 | Push | [16, 12, 3] |
| - | Pop 3, Pop 12. Evaluate (12 - 3 = 9) | [16, 9] |
| + | Pop 9, Pop 16. Evaluate (16 + 9 = 25) | [25] |
The final evaluated result of the postfix expression is: **25**
In simple words: Numbers are pushed onto the stack. When an operator is met, we pop the top two numbers, apply the math operation, and push the result back. At the end, 25 remains.
Exam Tip: Be careful with subtraction and division order. The first popped element acts as the divisor/subtrahend, and the second popped element acts as the dividend/minuend.
Question 4. a) What do you understand by Degree and Cardinality of a table?
Answer:
These are two fundamental terms used in relational database management systems:
- **Degree:** Refers to the total number of attributes (columns) present in a table structure.
- **Cardinality:** Refers to the total number of tuples (rows/records) stored within a table at any given time.
In simple words: The degree of a table is how many columns it has, whereas the cardinality is how many rows of data are filled inside it.
Exam Tip: Memorize this simple relation: Columns = Degree, Rows = Cardinality. It's a highly repeated short question in exams.
Question 4. b) Consider the following tables ACTIVITY and COACH. Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii)
Answer:
SQL Commands:
(i) `SELECT ActivityName, ACode FROM ACTIVITY ORDER BY ACode DESC;`
(ii) `SELECT ParticipantsNum, SUM(PrizeMoney) FROM ACTIVITY GROUP BY ParticipantsNum;`
(iii) `SELECT Name, ACode FROM COACH ORDER BY ACode ASC;`
(iv) `SELECT * FROM ACTIVITY WHERE ScheduleDate < '01-Jan-2004' ORDER BY ParticipantsNum ASC;` (Alternatively using '2004-01-01' depending on the SQL platform).
Outputs for Queries (v) to (viii):
(v)
| COUNT(DISTINCT ParticipantsNum) |
|---|
| 3 |
(vi)
| MAX(ScheduleDate) | MIN(ScheduleDate) |
|---|---|
| 19-Mar-2004 | 12-Dec-2003 |
(vii)
| SUM(PrizeMoney) |
|---|
| 54000 |
(viii) *(Assuming corrected SQL statement targeting column `ACode` in table `COACH`)*:
| ACode |
|---|
| 1001 |
| 1008 |
| 1003 |
In simple words: We write basic database commands to fetch, group, sort, and calculate mathematical values (like sum, minimum, maximum, and count) across different tables.
Exam Tip: Date comparisons in standard SQL queries are usually evaluated chronologically, meaning older dates are smaller/minimum and newer dates are larger/maximum.
Question 5. a) What do you understand by Primary Key & Candidate Keys?
Answer:
These are essential key constraints utilized in database modeling:
- **Primary Key:** A uniquely designated column or group of columns that identifies each database record as one-of-a-kind. It strictly prohibits duplicate or NULL values.
- **Candidate Key:** All attributes or set of attributes that possess the qualities required to become a primary key. The designated primary key is selected from these available candidate keys.
In simple words: Candidate keys are all the possible candidates that can uniquely identify table rows. From these options, we pick the best one to act as our official Primary Key.
Exam Tip: A table can contain multiple candidate keys, but it is permitted to have only one primary key constraint.
Question 5. b) Consider the following tables GAMES and PLAYER and answer (c) and (d) parts of this question:
Answer:
SQL Commands for (c):
(i) `SELECT GameName, GCode FROM GAMES;`
(ii) `SELECT * FROM GAMES WHERE PrizeMoney > 7000;`
(iii) `SELECT * FROM GAMES ORDER BY ScheduleDate ASC;` (or 'Schedule Date')
(iv) `SELECT Type, SUM(PrizeMoney) FROM GAMES GROUP BY Type;`
Outputs for Queries (d):
(i)
| COUNT(DISTINCT Number) |
|---|
| 2 |
(ii)
| MAX(ScheduleDate) | MIN(ScheduleDate) |
|---|---|
| 19-Mar-2004 | 12-Dec-2003 |
(iii)
| Name | GameName |
|---|---|
| Ravi Sahai | Lawn Tennis |
(iv)
| Gcode |
|---|
| 101 |
| 108 |
| 103 |
In simple words: We fetch matching data across both tables. For example, Ravi Sahai is the only player whose sport has a prize pool greater than 10,000 (Lawn Tennis, 25,000).
Exam Tip: When calculating relational join outputs, carefully verify the common matching column (Gcode) values across both tables before filtering with WHERE conditions.
Free study material for Computer Science
Free CBSE Practice Worksheets: Class 12 Computer Science All Chapters
Download Chapter Worksheets: Class 12 Computer Science
Review targeted practice exercises for Class 12 Computer Science All Chapters. Curated to match official CBSE guidelines, these printable problem sets support daily revision and improve overall test readiness.
Concept Clarification for All Chapters
Built using official NCERT guidelines for Class 12 Computer Science, these practice sheets provide reliable academic support. Cross-reference your completed work with our detailed solutions to learn standard answer-writing formats for CBSE exams.
Effective Revision Strategies for School Exams
Wrap up your chapter revision by testing your knowledge against standard objective question formats. Explore our full library of free, up-to-date printable assignments to maximize your academic results in upcoming CBSE evaluations.
FAQs
You can download the latest chapter-wise printable worksheets for Class 12 Computer Science All Chapters for free from StudiesToday.com. These have been made as per the latest CBSE curriculum for this academic year.
Yes, Class 12 Computer Science worksheets for All Chapters focus on activity-based learning and also competency-style questions. This helps students to apply theoretical knowledge to practical scenarios.
Yes, we have provided solved worksheets for Class 12 Computer Science All Chapters to help students verify their answers instantly.
Yes, our Class 12 Computer Science test sheets are mobile-friendly PDFs and can be printed by teachers for classroom.
For All Chapters, regular practice with our worksheets will improve question-handling speed and help students understand all technical terms and diagrams.