Download Class 12 Computer Science Practice Worksheets
Access comprehensive chapter-wise worksheets for All Chapters using the CBSE Class 12 Computer Science Revision Worksheet Set 02. Designed to align with the 2026-27 academic syllabus for Class 12 Computer Science, these printable practice sets help students reinforce key concepts and improve their overall exam readiness.
Access All Chapters Practice Papers and Solutions
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.
Q1. Write the output of the following program:
#include<iostream.h>
int Execute (int M)
{
if(M%3==0)
return M=3;
else
return M+10;
}
void Output (int B=2)
{
for(int T=0;T<B;T++)
cout<<Execute(T)<<”*”;
cout<<endl;
}
void main()
{
Output(4);
Output();
Output(3);
}
Q2. Write an interactive program in C++ to read the values of three coefficients of quadratic equation (Ax2 + Bx + C=0). Find the roots of the equation and display them on your screen (including complex roots) specifying the nature of roots.
Q1. Differentiate between CALL by reference and CALL by value.
Q2. When will you make a function inline and why?
Q3. Differentiate between a run‐time error and syntax error. Give one example of each.
Q4. What is the difference between global variables and local variables?
Give an example to illustrate the same.
Q5. What would be output by the following segment of C++?
int fact, i;
fact=1;
i=2;
while (i<=6)
fact*=i;
i++;
cout<<fact;
Q6. What output will be produced by following codes?
(a) int i;
i=‐12;
do
{
cout<<i<<endl;
i=i‐1;
}
while(i>0);
(b)int i;
i=‐12;
do
{
cout<<i<<endl;
i=i‐1;
}
while(i<0);
Q7. How is an entry controlled loop different from exit controlled loop?
Q8. What is the similarity and difference between break and continue statements?
Q10. What is the difference between global variables and local variables? Give an example to illustrate the same.
Q1. Distinguish between an object and a class.
Q2. Differentiate between Data hiding and Encapsulation.
Q3. What is base class? What is a derived class? How are these two interrelated.
Q4. Define the following terms: (i) Inheritance (ii) Encapsulation.
Q5. What is polymorphism?
Q6. What is a reference variable? What is its use?
Q7. How is an entry controlled loop different from exit controlled loop?
Q8. What is the similarity and difference between break and continue statements?
Q9. What is an inline function?
Q10. What do you mean by function prototyping? Write down the advantages of function prototypes in C++.
1. a) Answer the questions (i) and (ii) after going through the following class:
class serial
{
int serialcode;
char title[20];
float duration;
int no_of_episode;
public:
serial() //function 1
{ duration = 30;
no_of_episode = 10;
}
serial(int d, int noe) //function 2
{ duration = d;
no_of_episode = noe;
}
serial( &s1) // function3
{ }
~serial() // function 4
{
cout<<”Destroying Object”<<endl;
}
};
i. Complete definition of function 3
ii. Give example how function1 and function 2 get executed when object is created.
iii. Write an explicit call to function 2
b) Define a class Bank to represent the bank account of a customer with the following
specification
Private Members:
- Name of type character array(string)
- Account_no of type long
- Type_of_account ( S for Saving Account, C for current Account) of type char
- Balance of type float
Public Members:
A constructor to initialize data members as follows
- Name NULL
- Account_no 100001
- Type_of_account ‘S’
- Balance 1000
A function NewAccount() to input the values of the data members Name,
Account_no, Type_of_account and Balance with following two conditions
• Minimum Balance for Current account is Rs.3000
• Minimum Balance for Saving account is Rs.1000
A function Deposit() to deposit money and update the Balance amount.
A function Withdrawal() to withdraw money. Money can be withdrawn if minimum
balance is as >=1000 for Saving account and >=3000 for Current account.
A function Display() which displays the contents of all the data members for a account.
c) Answer the questions (i) to (iv) based on the following code :
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: public BRANCH, private 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?
2. Identify the errors with reasonin the following code fragmen . 5
class X {
int x;
static int ctr;
public:
X( ){x=0;}
X( int i ) { x = i ; }
void init ( void )
{ c=ctr=0; }
inline static void prn ( void )
{
prn( );
cout<<ctr<<x;
}
~X(int a ){}
}; void main( ){ X X, x1,x2; X.init( );};
3. Write the output of the following:
#include<iostream.h>
class item{
static int I ;
int no;
public :
item( )
{
cout<< “DC”<< “ ”;
}
item ( item & x)
{
cout<< “CC”<<” “;
}
void getdata( int aa )
{
no =aa ;
I ++ ;
}
void putdata()
{
cout <<“\n”<< I<<“\n”;
}
~Item()
{
cout<<”Des”<<I-- ;
}
};
int item::I ;
void main( )
{
item a;
item b=a ;
item c;
c=a;
a.getdata(100);
b.getdata(200);
a.getdata(300);
a.putdata();
b.putdata();
c.putdata();
}
4. Observe the following program carefully & choose the correct possible output (if any) from
the options (i) to (iv) 2
# include <iostream.h>
# include <conio.h>
# include <stdlib.h>
void main ()
{
char serial[] = {'E', 'X', 'A', 'M'};
int number[] = { 69, 66, 67, 68};
clrscr();
randomize();
cout << number[random(3)];
for (int i = 0; i < 4; i++)
cout << serial[sizeof(int) + random(2) - 1 ];
getch();
}
outputs:
(i) 67AXXA
(ii) 67AAAM
(iii) 67XXAX
(iv) 69AXXA
1. What is “? “ Operator? Explain with example?
2. What is use of comma operator?
3. What is selection statement in C? Explain.
4. What do you mean by loop? Explain various type of loop statement in C.
5. Write a program in C to find sum of first 10 natural numbers.
6. Write a program in C to check number is odd or even.
7. Write a program in C to find greater number between two numbers, where numbers are entered by user.
8. Write a program in C to find cube of a number where number is entered by user.
9. Write a program in C to print table a number, where numbers is entered by user.
10. Write a program in C to find total marks, percentage and grade of a student on the
Question 1. Write the output of the following program:
#include<iostream.h>
int Execute (int M)
{
if(M%3==0)
return M=3;
else
return M+10;
}
void Output (int B=2)
{
for(int T=0;T<B;T++)
cout<<Execute(T)<<”*”;
cout<<endl;
}
void main()
{
Output(4);
Output();
Output(3);
}
Answer:
The output of the program is as follows:
3*11*12*3*
3*11*
3*11*12*
Tracing Steps:
1. **Output(4):** Runs a loop from T = 0 to 3.
- For T = 0: `0 % 3 == 0`, returns 3. Prints `3*`.
- For T = 1: `1 % 3 != 0`, returns `1 + 10 = 11`. Prints `11*`.
- For T = 2: `2 % 3 != 0`, returns `2 + 10 = 12`. Prints `12*`.
- For T = 3: `3 % 3 == 0`, returns 3. Prints `3*`.
- Result: `3*11*12*3*`
2. **Output():** Uses the default argument B = 2 and loops from T = 0 to 1.
- Prints: `3*11*`
3. **Output(3):** Loops from T = 0 to 2.
- Prints: `3*11*12*`
In simple words: This code calls the Output function three times with different loop limits. Each step divides the loop index by 3 to decide whether to return 3 or add 10 to it.
Exam Tip: Be careful with assignment expressions inside return statements like `return M=3;`, as this updates the value of the variable and returns the newly assigned value.
Question 2. Write an interactive program in C++ to read the values of three coefficients of quadratic equation (Ax² + Bx + C=0). Find the roots of the equation and display them on your screen (including complex roots) specifying the nature of roots.
Answer:
```cpp #include
In simple words: This program takes three numbers as inputs and calculates the roots of a quadratic equation. It checks if the roots are real or complex using the discriminant math formula.
Exam Tip: Always handle the condition where the discriminant is negative by separating the real and imaginary parts to output complex roots correctly as a + bi.
Question 3. Write an interactive C++ program to accept an integer and reverse the integer. Display both the numbers on your screen.
Answer:
```cpp #include
In simple words: This program takes any whole number, extracts its digits from right to left using the division remainder, and prints the original and reversed numbers side by side.
Exam Tip: Remember to use the absolute value function when isolating the digits of negative integers, and reapply the negative sign to the reversed output at the end.
Question 4. Write a program to accept 10 integers from a user in a single dimension array and sort the array in ascending order.
Answer:
```cpp #include
In simple words: This program reads ten numbers from a user, compares adjacent values, swaps them if they are in the wrong order, and displays them sorted from lowest to highest.
Exam Tip: Standard sorting algorithms like Bubble Sort or Selection Sort are perfect for this question. Make sure your sorting loops use correct boundary checks to avoid out-of-bounds access.
Question 5. Write a program to read to check the equality of two matrices.
Answer:
```cpp #include
In simple words: This program compares two mathematical grids. It first checks if they have the same size, then matches each corresponding element to confirm if they are completely identical.
Exam Tip: Check matrix dimension equality first before reading matrix values. This optimization saves runtime and prevents unnecessary memory usage.
Question 6. Write a program to read a string and check whether it is a palindromic string or not. (Palindrome is a string that reads the same from left to right and vice-versa.)
Answer:
```cpp #include
In simple words: This program reads a word and compares characters at opposite ends (start and finish) to see if they are the same, verifying if the word reads identically backward.
Exam Tip: Loop up to length/2 instead of checking the entire string to cut the comparison operations in half and make your solution more efficient.
Question 7. Write a program C++ to find number of vowels in a given line of text.
Answer:
```cpp #include
In simple words: This program reads an entire sentence and counts every instance of the letters a, e, i, o, and u (supporting both uppercase and lowercase inputs).
Exam Tip: Use `getline(cin, line)` instead of `cin >> line` to ensure you read the entire line of text including spaces, rather than stopping at the first space.
Question 8. Write an interactive program in C++ to read a string and make a table displaying different types of characters in the following format: For Example; Input string: THE QUICK BROWN fox jumps over the LAZY LITTLE DOG Output table Uppercase Vowels : 6 Lowercase Vowels : 7 Uppercase Consonants : 15 Lowercase Consonants : 13
Answer:
```cpp #include
In simple words: This program analyzes a text sentence, separates alphabetic letters into four categories depending on whether they are uppercase, lowercase, vowels, or consonants, and prints the totals in a structured table format.
Exam Tip: Use the library functions `isalpha()`, `isupper()`, and `tolower()` from the `
Question 9. Let A [n x n] be a given matrix. Write a program to find the sum of all the elements which lie on either diagonal. For example, for the matrix shown below, your program should output 68=(1+6+11+16+4+7+10+13);
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Answer:
```cpp #include
In simple words: This program sums up the numbers along both the main and secondary diagonals of a square grid. If the grid has an odd size (like 3x3 or 5x5), it ensures the shared central number is only added once.
Exam Tip: Always include the conditional check `if (n % 2 != 0)` to subtract the duplicate central element when calculating diagonal sums of odd-dimensioned square matrices.
Question 10. Write a function to accept a string and search for a sub-string (a group of contiguous characters). If the search is successful, the function should return the position of the sub-string and minus one (-1) otherwise.
Answer:
```cpp #include
In simple words: This function looks for a smaller word (substring) within a larger sentence. If the word is found, it returns the start position of that word; if not, it returns -1.
Exam Tip: Ensure that your outer search loop limit is set to `mainLen - subLen` to avoid looking past the end of the main string, which prevents out-of-bounds comparison errors.
Free study material for Computer Science
Download Class 12 Computer Science All Chapters Practice Worksheets
Practice Exercises for Class 12 Computer Science All Chapters
Access structured practice worksheets for All Chapters aligned with the 2026 CBSE curriculum. These downloadable exercises for Class 12 Computer Science help students build accuracy and reinforce core concepts for upcoming school tests.
Step-by-Step Solutions and Practice Guidelines
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.
Enhance Speed with Online Practice
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.