Explore topic-wise InterviewSolutions in Current Affairs.

This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.

1.

A constructor which can take arguments is called ………(a) parameterised constructor(b) default constructor(c) copy constructor(d) destructor

Answer»

(a) parameterised constructor

2.

The most important feature of C++ is ………(a) object (b) class (c) public(d) All the above

Answer»

The most important feature of C++ is class

3.

What is parameterized constructor?

Answer»

A constructor which can take arguments is called parameterized constructor.This type of constructor helps to create objects with different initial values. This is achieved by passing parameters to the function.

4.

Objects are also called as ………..(a) instance of class(b) class(c) function(d) scope

Answer»

(a) instance of class

5.

Which of the following access specifier protects data from inadvertent modifications?(a) Private(b) Protected(c) Public(d) Global

Answer»

(b) Protected

6.

Which of the following create a temporary instance? (a) Implicit call to the constructor(b) Explicit call to the constructor(c) Implicit call to the destructor(d) Explicit call to the destructor

Answer»

(b) Explicit call to the constructor

7.

class x{int y; public:x(int z){y=z;} }x1[4];int main(){x x2(10);return 0;}How many objects are created for the above program?(a) 10(b) 14(c) 5(d) 2

Answer»

5 objects are created for the above program

8.

What are called members?

Answer»

Class comprises of members. Members are classified as Data Members and Member functions. Data members are the data variables that represent the features or properties of a class. Member functions are the functions that perform specific tasks in a class.

9.

What is the difference between the class and object in terms of OOP?

Answer»

Object:

  • Object is an instance of a class.
  • Object is a real world entity such as pen, laptop, mobile, chair etc.
  • Object allocates memory when it is created.

Class:

  • Class is a blueprint or template from which objects are created.
  • Class is a group of similar objects.
  • Class doesn’t allocate memory when it is created.
10.

Which of the following constructor is executed for the following prototype?add display( add &); // add is a class name(a) Default constructor(b) Parameterized constructor(c) Copy constructor(d) Non Parameterized constructo

Answer»

(d) Non Parameterized constructor

11.

What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero – argument constructor?(a) Compile – time error(b) Domain error(c) Runtime error(d) Runtime exception

Answer»

(d) Runtime exception

12.

Differentiate structure and class though both are user defined data type.

Answer»

The only difference between structure and class is the members of structure are by default public where as it is private in class.

13.

The variables declared inside the class are known as data members and the functions are known as ………(a) data functions (b) inline functions(c) member functions(d) attributes

Answer»

(c) member functions

14.

State whether the following statements about the constructor are True or False.(i) constructors should be declared in the private section.(ii) constructors are invoked automatically when the objects are created.(a) True, True(b) True, False(c) False, True(d) False, False

Answer»

(c) False, True

15.

In the absence of user defined constructor, what will the constructor do?

Answer»

In the absence of user defined constructor the compiler automatically provides the default constructor. It simply allocates memory for the object.

16.

A member function can call another member function directly, without using the dot operator called as ……(a) sub function(b) sub member(c) nesting of member function(d) sibling of member function

Answer»

(c) nesting of member function

17.

the name of the symbol is ……..(a) hash(b) arrow(c) tilde(d) bracket

Answer»

the name of the symbol is tilde

18.

What is called as nesting of member functions?

Answer»

Only the public members of a class can be accessed by the object of that class, using dot operator. However a member function can call another member function of the same class directly without using the dot operator. This is called as nesting of member functions.

19.

Which of the following statements about member functions are True or False?(i) A member function can call another member function directly with using the dot operator.(ii) Member function can access the private data of the class.(a) (i) – True,(ii) – True(b) (i) – False, (ii)-True(c) (i) – True, (ii) – False(d) (i) – False, (ii) – False

Answer»

(a) (i) – True, (ii) – True

20.

Define methods of a class and write its types.

Answer»

Class comprises of members. Member functions are called as methods.

The member functions of a class can be defined in two ways.

1. Inside the class definition

2. Outside the class definition

21.

…….. can be defined either in private or in public section of a class.(a) Object(b) Data type (c) Memory (d) constructor

Answer»

(d) constructor

22.

When a class is declared within another class, the inner class is called …….. and the outer class is called ……(a) enclosing class, nested class(b) nested class, enclosing class(c) first class, second class(d) A class, B class

Answer»

(b) nested class, enclosing class

23.

When one class become the member of another class, the relationship is called ………..(a) containership(b) partnership(c) friendship(d) all the above

Answer»

(a) containership

24.

Define a class RESORT with the following description in C++ :

Answer»

Private members:

1. Rno // Data member to store room number.

2. Name // Data member to store user name.

3. Charges // Data member to store per day charge.

4. Days //Data member to store the number of days.

5. Compute () // A function to calculate total amount as Days * Charges and if the //total amount exceeds 11000 then total amount is 1.02 * Days ’’’Charges.

Public member:

getinfo() // Function to Read the information like name, room no, charges and days dispinfo () // Function to display all entered details and total amount calculated

//using COMPUTE function

//include

//include

//include

Class RESORT

{

Private:

int Rno;

char name [20];

float charges; int days; float compute();

Public:

void getinfoO;

void dispinfo();

}

void RESORT: : getinfo()

{

cout <<“Enter Registration number:”; cin>> Rno.; 

cout <<“\n Enter name:”; gets(name);

cout <<  “\n Enter per day charges:”; cin >> charges;

cout <<“\n Enter number of days:”; cin >> days;

}

void RESORT: : dispinfo()

{

cout << “\n1. Registration number:” <<

Rno << “\n2. Name:”; puts(name);

cout << “\n3. charges per day:” << charges << “\n4. Number of days:” <<days;

cout<< “\n5. Amount:” << compute();

}

long float;

amount = charges*days;

if (amount> 11000)

amount = 1,02*days*charges;

return amount;

}

RESORT obj;

void main()

{

clrscr();

obj.getinfo();

obj.dispinfoQ;

getch();

}

25.

Mention the differences between constructor and destructor.

Answer»

Constructor:

  • The name of the constructor must be same as that of the class.
  • No return type can be specified for constructor.
  • A constructor can have parameter list.
  • The constructor function can be overloaded.
  • They cannot be inherited but a derived class can call the base class constructor.
  • The compiler generates a constructor, in the absence of a user defined constructor.

Destructor:

  • The destructor has the same name as that of the class prefixed by the tilde character It has no return type.
  • The destructor cannot have arguments.
  • Destructors cannot be overloaded i.e., there can be only one destructor in a class.
  • They cannot be inherited. 
  • In the absence of user defined destructor, it is generated by the compiler.
26.

Write a program to display numbers from 1 to 10 except 6 using continue statement.

Answer»

C++ program to display numbers from 1 to 10 except 6 using continue statement

#include

using namespace std;

int main()

{

if (i = 6)

continue;

else

cout<<i<<" "

}

return 0;

}

Output:

1 2 3 4 5 7 8 9 10

27.

Rewrite the given program.C++ program to sum the numbers from 1 to 10 using for loop#include&lt;iostream&gt;using namespace std;int main (){sum = 0;while(i&lt;10){sum = sum + i;i--}cout&lt;&lt;"\n The sum is = "&lt;&lt;sum;return 0;}

Answer»

#include<iostream>

using namespace std;

int main ()

{

int i, sum = 0;

for(i=1;i<=10;i++)

{

sum = sum + i

}

cout<<"The sum of 1 to 10 is"<<sum;

return 0;

}

Output:

The sum of 1 to 10 is 55

28.

Write a program to check whether a person is eligible to vote using if statement. C++ program to check whether a person is eligible to vote using if statement

Answer»

#include <iostream>

using namespace std;

int main()

{

int age;

cout<<"\n Enter your age:";

cin>> age;

if(age>=18)

cout<<"\n You are eligible for voting ....";

cout<<"This statement is always executed.";

return 0;

}

Output:

Enter your age: 23

You are eligible for voting …. 

This statement is always executed.

29.

Compare an if and a? : operator.

Answer»
     If        ?:
'if' is a c++ statement'?:' is a c++ operator
Syntax:
if(
expression)
true-block;
statement -x;
Syntax:
Expression 1?Expression 2 :Exp 3:
30.

What will be the output of the following code.

Answer»

int a, b, largest;

cout <<“\n Enter any two numbers:”; cin>> a

>>b;

largest = (a > b)? a:b;

cout << “\n Largest number:” << largest;

return 0;

Output:

Enter any two numbers:

5 10

Largest number:

10

31.

Rewrite the following code so that it is functional:

Answer»
Given codeFunction code
v=5;
do;
{
total + v;
cout <<total;
while v< = 10
int c = 5, total = 0;
do
{
total + = v;
cout <<total;
v++;}
while(c<=10);
32.

What is the output of the following code?for (int i = 2; i &lt; = 10 ; i + = 2)cout&lt;&lt;i;

Answer»

Output:

2 4 6 8 10

33.

What is sequence statements?

Answer»

The sequential statement are the statements that are executed one after another only once from top to bottom. These statements do not alter the flow of execution. These statements are called as sequential flow statements. They always end with a semicolon (;)

34.

When a switch is a part of the statement sequence of another switch, then it is called as …..(a) if – else ladder(b) Switch statement(c) Nested switch statement(d) Empty statement

Answer»

(c) Nested switch statement

35.

What will be the output of the following code:int year;cin&gt;&gt;year;if(year%100==0)if(year%400==0)cout&lt;&lt;"Not Leap year";If the input given is1. 20002. 20033. 2010?

Answer»

1. Output

(Input = 2000)

Leap

2. Output

(Input = 2003)

Not leap Year

3. Output (Input = 2010)

Not leap Year

36.

…….. is more efficient than if-else statement.(a) Control statement(b) Switch statement(c) Empty statement(d) Null statement

Answer»

(b) Switch statemen

37.

Convert the following if – else to a single conditional statement:If (x&gt;=10)a = m;

Answer»

a = (x> =10)? m + 5:m;

38.

Correct the following code segment:

Answer»
Given codeCorrected code
if (x = 1)
p = 100;
else
p = 10;
if (x==1)
p = 100;
else
p = 10;
39.

In C++, the group of statements should enclosed within: (a) { } (b) [] (c) () (d) &lt;&gt;

Answer»

In C++, the group of statements should enclosed within: { }

40.

The multi way branching statement:(a) if(b) if … else(c) switch(d) for

Answer»

The multi way branching statement is switch

41.

What is the alternate name of null statement?(a) No statement(b) Empty statement (c) Void statement(d) Zero statement

Answer»

(b) Empty statement

42.

In C++ any non – zero is iterated as true …….. and zero is treated as false.(a) positive numbers(b) negative numbers(c) prime numbers(d) none of these

Answer»

(b) negative numbers

43.

The set of statements that are executed again and again in iteration is called as:(a) condition(b) loop(c) statement(d) body of loop

Answer»

(d) body of loop

44.

……….. is a multi – path decision making statement. (a) if(b) if – else(c) else – if (d) if – else ladder

Answer»

(d) if – else ladder

45.

Iteration statement is called as ……..(a) Null statement(b) Block statement(c) Selection statement(d) Looping statement

Answer»

(d) Looping statement

46.

What is selection statement? Write it’s types.

Answer»

The selection statement means the statements are executed depends – upon a condition. If a condition is true, a true block (a set of statements) is executed, otherwise a false block is executed. This statement is also called decision statement or selection statement because it helps in making decision about which set of statements are to be executed.

Types:

1. Two way branching

2. Multiway branching

47.

A loop that contains another loop inside its body: (a) Nested loop(b) Inner loop(c) Inline loop(d) Nesting of loop

Answer»

(a) Nested loop

48.

Selection statement is also called as ……(a) Decision statement(b) Sequence statement(c) Null statement(d) Compound statement

Answer»

(a) Decision statement

49.

Write short notes on Test expression.

Answer»

The test expression is an expression or condition whose value decides whether the loop – body will be executed or not. If the expression evaluates to true (i.e., 1), the body of the loop is executed, otherwise the loop is terminated. In an entry – controlled loop, the test – expression is evaluated before the entering into a loop whereas in an exit – controlled loop, the test – expression is evaluated before exit from the loop.

50.

What are the differences between break and continue statement.

Answer»

Break:

  • Break is used to terminate the execution of the loop.
  • It breaks the iteration.
  • When this statement is executed, control will come out from the loop and executes the statement immediate after loop.
  • Break is used with loops as well as switch case.

Continue:

  • Continue is not used to terminate the execution of loop.
  • It skips the iteration.
  • When this statement is executed, it will not come out of the loop but moves/jumps to the next iteration of loop.
  • Continue is only used in loops, it is not used in switch case.