Custom image

Computer Science

Probable viva questions on C++

Questions and Answers Topic Wise (XII):

1. Revision Tour

2. Object Oriented Programming

3. Function Overloading

4. Classes and Objects

5. Constructors and Destructors

6. Inheritance

7. Data File Handling

8. Pointers

9. Arrays

10. Stacks & Queues

11. Database Concept

12. SQL

13. Boolean Algebra

14. Communication and Networking Concepts

Revision Bytes (XII)

  1. Header Files
  2. Stack through Linked List
  3. Queue through Linked List
  4. Communication & Networking Full Forms
  5. Data File Handling File Pointers
  6. Data File Handling Differences
  7. Network Devices
  8. Pointers + (Array, String)
  9. Boolean Algebra
  10. Linked List and its creation
  11. Circular Queue through Linked List

Practice Time

  1. Constructors
  2. Inheritance
  3. Review of C++
  4. Binary File Handling

Tips for Class XII Students


Mindmap of CBSE Board Exam Question Paper (Question-wise)

Question No. 1 (12 Marks)

  • Part a question based on theory (2 marks)
  • Part b question based on header files (1 Mark)
  • Part c question based on Error finding (2 Marks)
  • Part d question based on output (2 Marks)
  • Part e question based on output (3 Marks)
  • Part f question based on output (2 Marks)

Question No. 2 (12 Marks)

  • Part a Theory question based on OOPs concept (2 Marks)
  • Part b question based on Constructor & Destructor (2 Marks)
  • Part c question Define a class (4 Marks)
  • Part d question based on Inheritance (4 Marks)

Question No. 3 (14 Marks)

  • Part a question based on Array (2 Marks)
  • Part b question based on Array (3 Marks)
  • Part c question based on Linked Stack/Queue (4 Marks)
  • Part d question based on Address Calculation of 2D Arrays (3 Marks)
  • Part e question based on Stack Implementation (2 Marks)

Question No. 4 (6 Marks)

  • Part a question based on File Pointer Position (1 Mark)
  • Part b question based on File Handling using text file (2 Marks)
  • Part c question based on File Handling using Binary files (3 Marks)

Question No. 5 (8 Marks)

  • Part a theory question based on RDBMS concepts (2 Marks)
  • Part b question based on SQL (Queries + output) (4+2=6 Marks)

Question No. 6 (8 Marks)

  • Part a question based on Basic Postulates of Boolean Algebra (2 Marks)
  • Part b question based on Circuit Diagram (2 Marks)
  • Part c question based on SOP/POS (1 Marks)
  • Part d question based on K-Map (3 Marks)

Question No. 7 (10 Marks)

  • Part a-f question based on Network Theory (6 Marks)
  • Part g question based on Network Case Study (1 x 4=4 Marks)

Arrays [4 marks HOTs Questions]

Q1: Write a function in C++, which accepts an integer array and its size as parameters and rearrange the array in reverse. Example if an array of five members initially contains the elements as 6,7,8,13,9,19
Then the function should rearrange the array as 19,9,13,8,7,6

 

Ans: Reversing means swap first element and last element, second first element and second last element and so on.
void ReverseArray(int x[], int N)
{
int i,j,temp;
/* i for taking the elements from the beginning onwards, so initialize it with 0 and increment its value(i++). j for taking the elements from the end, so initialize it with N-1 and decrement its value each time (j--) */
for(i=0,j=N-1;i{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
cout<<"After reversing the Array elements are"cout<

}

}

Stacks and Queues

Q1: Describe stack operation?

Ans:

Stack is a data structure that follows Last in First out strategy.

Stack Operations:-

  • Push – Pushes (inserts) the element in the stack. The location is specified by the pointer.
  • Pop – Pulls (removes) the element out of the stack. The location is specified by the pointer
  • Swap: - the two top most elements of the stack can be swapped
  • Peek: - Returns the top element on the stack but does not remove it from the stack
  • Rotate:- the topmost (n) items can be moved on the stack in a rotating fashion

A stack has a fixed location in the memory. When a data element is pushed in the stack, the pointer points to the current element.

Q 2: Describe queue operation?

 

Ans:-

Queue is a data structure that follows First in First out strategy.

Queue Operations:

  • Push – Inserts the element in the queue at the end.
  • Pop – removes the element out of the queue from the front
  • Size – Returns the size of the queue
  • Front – Returns the first element of the queue.
  • Empty – to find if the queue is empty.

Q 3: Discuss how to implement queue using stack?

Ans:-

A queue can be implemented by using 2 stacks:-

  • 1. An element is inserted in the queue by pushing it into stack 1
  • 2. An element is extracted from the queue by popping it from the stack 2
  • 3. If the stack 2 is empty then all elements currently in stack 1 are transferred to stack 2 but in the reverse order
  • 4. If the stack 2 is not empty just pop the value from stack 2.

Q 4: What are Priority Queues?

Ans:-

A priority queue is essentially a list of items in which each item has associated with it a priority

Items are inserted into a priority queue in any, arbitrary order. However, items are withdrawn from a priority queue in order of their priorities starting with the highest priority item first.

Priority queues are often used in the implementation of algorithms.

 

Classes and Objects

Q 1: What happens when we try to compile the class definition in following code snippet?

class Birds {};
class Peacock : protected Birds {};

 

A. It will not compile because class body of Birds is not defined.
B. It will not compile because class body of Eagle is not defined.
C. It will not compile because a class cannot be protectedly inherited from other class.
D. It will compile succesfully.

 

Ans: D

Q 2:

Which of the following statements is incorrect?

A. Friend keyword can be used in the class to allow access to another class.
B. Friend keyword can be used for a function in the public section of a class.
C. Friend keyword can be used for a function in the private section of a class.
D. Friend keyword can be used on main().

Ans: D

Q 3:

Which of the following two entities (reading from Left to Right) can be connected by the dot operator?

A. A class member and a class object.
B. A class object and a class.
C. A class and a member of that class.
D. A class object and a member of that class.

Ans: D

Q 4:Which of the following statements is correct when a class is inherited publicly?

A. Public members of the base class become protected members of derived class.
B. Public members of the base class become private members of derived class.
C. Private members of the base class become protected members of derived class.
D. Public members of the base class become public members of derived class.

Ans: D

Q 5:

Which of the following statements is correct about the constructors and destructors?

A. Destructors can take arguments but constructors cannot.
B. Constructors can take arguments but destructors cannot.
C. Destructors can be overloaded but constructors cannot be overloaded.
D. Constructors and destructors can both return a value.

Ans: B

Q 6:Which of the following access specifies is used in a class definition by default?

A. Protected B. Public
C. Private D. Friend

Ans: C

Q 7:Which of the following keywords is used to control access to a class member?

A. Default B. Break
C. Protected D. Asm

Ans: C

Q 8:Which of the following can access private data members or member functions of a class?

A. Any function in the program.
B. All global functions in the program.
C. Any member function of that class.
D. Only public member functions of that class.

Ans: C

Q 9:Which of the following also known as an instance of a class?

A. Friend Functions
B. Object
C. Member Functions
D. Member Variables

Ans: B

Q 10:

Constructor is executed when _____.

A. an object is created
B. an object is used
C. a class is declared
D. an object goes out of scope.

Ans: A

Q 11:What does the class definitions in following code represent?

class Bike
{
    Engine objEng;
};
class Engine
{
    float CC;
};
A. kind of relationship
B. has a relationship
C. Inheritance
D. Both A and B

Ans: B

Q 12:

Which of the following statements is correct when a class is inherited privately?

A. Public members of the base class become protected members of derived class.
B. Public members of the base class become private members of derived class.
C. Private members of the base class become private members of derived class.
D. Public members of the base class become public members of derived class.

Ans:B

Q 13:Which of the following statements is correct?

A. Data items in a class must be private.
B. Both data and functions can be either private or public.
C. Member functions of a class must be private.
D. Constructor of a class cannot be private.

Ans:B

Q 14:Which of the following can be overloaded?

A. Object
B. Functions
C. Operators
D. Both B and C

Ans: D

Q 15:Which of the following is the only technical difference between structures and classes in C++?

 

A. Member function and data are by default protected in structures but private in classes.
B. Member function and data are by default private in structures but public in classes.
C. Member function and data are by default public in structures but private in classes.
D. Member function and data are by default public in structures but protected in classes.

Ans:C

----------------------------------------------------------------------------------------------------------------------------------------------------------

HEADER FILES (Some important library functions)

stdio.h :

fclose, fcloseall, feof, fflush, fgetchar, fgets, fileno, fopen, fprintf, fputchar, fputs, fread, fseek, fwrite, getc, getchar, gets

string.h

setmem, strcpy, strcat, strcmp, strcmpi, strlen, strrev, strset

math.h

abs, cos, exp, fabs, floor, fmod, fmodl, pow, sin, sqrt, tan

stdlib.h

abort, abs, atof, atoi, exit, atol, calloc, free, rand, random, randomize, realloc

conio.h

cgets, clrscr, cprintf, cputs, cscanf, getch, getche, gettext, putch, puttext, textbackground, textcolor

----------------------------------------------------------------------------------------------------------------------------------

EXAMPLES OF INFIX, POSTFIX(REVERSE POLISH NOTATION) AND PREFIX(POLISH NOTATION) NOTATIONS:

INFIX POSTFIX PREFIX NOTES
A*B+C/D AB*CD/+ +*AB/CD Multiply A and B, divide C by D, add the results
A*(B+C)/D ABC+*D/ /*A+BCD Add B and C, multiply by A, divide by D
A*(B+C/D) ABCD/+* *A+B/CD Divide C by D, add B, multiply by A