TCS Papers: Sample Questions 464 - 465 of 502

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 464

» Languages » C & C Plus Plus

MCQ▾

Question

Which of the following type of class allows only one object of it to be created?

Choices

Choice (4) Response

a.

Singleton Class

b.

Abstract Class

c.

Virtual Class

d.

Friend Class

Answer

a.

Explanation

  • Singleton pattern is a software design pattern that restricts the instantiation of a class to one object.

  • C++ Singleton class using inheritance: In this example the base class enforces a singleton pattern.

  • Note that the function calls are static calls to their global names using the scope resolution operator.

  • The functions create () and instance () are defined as static functions in the class definitions.

  • The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects.

Singleton class

Singleton Class

Given the image is define the singleton class in c++.

Question number: 465

» Languages » C & C Plus Plus

MCQ▾

Question

Cout is a/an ________.

Choices

Choice (4) Response

a.

Operator

b.

Macro

c.

Function

d.

Object

Answer

d.

Explanation

  • In most environments, standard output is on screen- C++ stream object defined to access this standard output is cout. Cout is an object which encapsulates the complexity of outputting to the screen.

  • For formatted output operations, cout is used together with the insertion operator, which is written as < < (i. e. , two “less than” signs).

The output using cout object

The Output Using Cout Object

Given the image is define the output using cout object