wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C++ Final Quiz

Total questions: 65

Worksheet time: 1hrs 2mins

Name
Class
Date
1.

C++ was developed by __________.

a)

Charles

b)

Bjarne Stroustrup

c)

Pascal

d)

Dennis Ritchy

2.

C++ is a ________ language.

a)

Office-oriented procedure

b)

Office-oriented programming

c)

Object-oriented procedure

d)

Object-oriented programming

3.

Which of the following are the C++ tokens?

a)

Variables

b)

Operators

c)

Keywords

d)

All

4.

Keywords are also called as ________.

a)

Reserved words

b)

Same words

c)

Individual words

d)

Special words

5.

A ______ is a meaningful name of data storage location in computer memory.

a)

constant

b)

keyword

c)

operator

d)

variable

6.

Which symbols are called as arithmetic operators?

a)

< > <= >= == !=

b)

&& || !

c)

+ - * / %

d)

=+ =- =* =/ =%

7.

A ________ is blue print that defines certain characteristics and behavior. It is simply a representation of different types of objects.

a)

Class

b)

Object

c)

Attribute

d)

Characteristics

8.

an object is a /an instance of _______________

a)

class

b)

C++

c)

object

d)

iostream.h

9.

A function can have _____ inside the parenthesis

a)

loops

b)

Arguments/Parameters

c)

Braces

d)

Types

10.

A function that has no return type starts with:

a)

int

b)

void

c)

Arguments

d)

Braces

11.

function is executed when it is

a)

defined

b)

prototyped

c)

declared

d)

called

12.

A function that changes the values of an object's attributes in a Class is also known as a:

a)

string function

b)

setter

c)

getter

d)

changer

13.

Fill in the blank to have this function work properly


_____ function ( ) {


string greeting = "Welcome to my game";


return greeting;


}

a)

string

b)

void

c)

int

d)

variable

14.

Given the following class:


class Monkey{

string name;

int age;


public:

void setName(string n){


name = n;

}


}


How can you change the name for a Monkey mon object to "Sir Monkey"?

a)

monkey.name();

b)

mon.setName("Sir Monkey");

c)

mon.setName(Sir Monkey);

d)

monkeymon.setName("Sir Monkey");

15.

Given the following Player class in C++:


class Player{

string name;

int age;


Player(string n, int a){


name = n;

age = a;

}


}


int main(){


_________________


}


Create a new Player object properly:

a)

player name();

b)

Player user("John", 13);

c)

Player user(John, "13");

d)

Player user(name, age);

16.
In the statement 
 Bank tom = new Bank(5000.0);
Which is the class?
a)
Bank
b)
tom
c)
new
d)
5000.0
17.
In the statement 
Bank tom = new Bank(5000.0);

Which is the object?
a)
Bank
b)
tom
c)
new
d)
5000.0
18.

What is inheritance in C++?

a)

Inheritance in C++ is used to create new classes based on existing classes

b)

Inheritance in C++ allows a class to inherit properties and behaviors from another class.

c)

Inheritance in C++ is limited to inheriting only data members from another class

d)

Inheritance in C++ is not supported in object-oriented programming

19.

What is the syntax for inheriting a class in C++?

a)

class DerivedClass :: BaseClass {}

b)

class DerivedClass : public BaseClass {}

c)

class DerivedClass : BaseClass {}

d)

class DerivedClass : accessSpecifier BaseClass {}

20.

What is the difference between public, private, and protected inheritance in C++?

a)

Protected inheritance makes the private members of the base class protected in the derived class

b)

Private inheritance makes the public members of the base class private in the derived class

c)

Public inheritance makes the private members of the base class accessible in the derived class

d)

Public inheritance makes the public members of the base class accessible in the derived class, private inheritance makes the public and protected members of the base class private in the derived class, and protected inheritance makes the public and protected members of the base class protected in the derived class.

21.

Explain the concept of virtual inheritance in C++.

a)

Virtual inheritance in C++ is used to allow multiple instances of the common base class to be inherited by the derived class

b)

Virtual inheritance in C++ is used to resolve the ambiguity that arises when a class is derived from multiple classes that have a common base class. It ensures that only one instance of the common base class is inherited by the derived class.

c)

Virtual inheritance in C++ is used to prevent a class from being inherited by any other class

d)

Virtual inheritance in C++ is used to create instances of classes that are not physically present in memory

22.

What are the different types of polymorphism in C++? Explain with examples.

a)

Compile-time polymorphism and runtime polymorphism. Compile-time polymorphism is achieved through function overloading and operator overloading, while runtime polymorphism is achieved through virtual functions and function overriding.

b)

Single polymorphism and multiple polymorphism. Single polymorphism is achieved through function overloading and multiple polymorphism is achieved through operator overloading.

c)

Static polymorphism and dynamic polymorphism. Static polymorphism is achieved through virtual functions and dynamic polymorphism is achieved through function overloading.

d)

Simple polymorphism and complex polymorphism. Simple polymorphism is achieved through operator overloading and complex polymorphism is achieved through function overloading.

23.

What is encapsulation in C++?

a)

A way to create multiple classes

b)

The process of bundling related data members and functions together in a single class

c)

A function that modifies variables

d)

A mechanism for defining constants

24.

Which of the following is an advantage of encapsulation?

a)

It allows variables to be accessed from any class

b)

It makes code cleaner and easier to read by grouping related data and functions

c)

It forces all data members to be public

d)

It removes the need for constructors

25.

What is the difference between encapsulation and data hiding?

a)

Encapsulation is about grouping related code, while data hiding restricts access to certain members

b)

Data hiding is the same as encapsulation

c)

Encapsulation always requires data hiding

d)

Encapsulation hides implementation details, but data hiding allows full access to class members

26.

What is the primary purpose of setter functions in C++?

a)

To allow read-only access to private data members

b)

To modify private data members from outside the class

c)

To perform calculations on variables

d)

To initialize objects

27.

Which access specifier is used to hide class members from other classes in C++?

a)

public

b)

private

c)

protected

d)

default

28.

What is the purpose of getter functions in C++?

a)

To return the values of private data members

b)

To modify private data members

c)

To define new variables

d)

To create objects of a class

29.

How does encapsulation help with modifying data members in a controlled way?

a)

By providing direct access to variables

b)

By using getter and setter functions to control how data members are accessed or modified

c)

By allowing all functions to modify variables directly

d)

By creating multiple copies of data members

30.

What happens if you try to access a private data member directly from outside the class?

a)

The program runs successfully

b)

The program raises a compile-time error

c)

The variable is automatically converted to public

d)

The variable is accessed without restriction

31.

Pick out the defination of objects?

a)

Member of the class

b)

Associate of the class

c)

Attributes of the class

d)

Instance of the class

32.

How many objects can present in a single class?

a)

2

b)

4

c)

As many as possible

d)

0

33.

Which concept allows you to reuse the written code?

a)

Encapsulation

b)

Inheritance

c)

Polymorphism

d)

Class

34.

What does modularity means?

a)

Hiding part of program

b)

Subdividing programs into small independent parts

c)

Overriding parts of programs

d)

Wrapping things into single unit?

35.

C++ is _____________

a)

Both procedural & object oriented programming language

b)

Procedural programming language

c)

Functional programming language

36.

Which of the following explains Polymorphism?

a)

int func(int, int);

float func1(float, float);

b)

int func(float);

int func(int, int, char);

c)

int func();

int new_func();

d)

int func(int);

int func(int);

37.

What will be the output of this piece of code?

a)

5500.263

b)

500.2635

c)

500.263

d)

500.266

38.

What will be the output of this piece of code?

a)

print derived class

show base class

b)

print derived class

show derived class

c)

Error

39.

The overloaded operator must have at least one operand that is of which type ?

a)

basic type

b)

derived type

c)

user defined type

d)

system defined type

40.

For overloading unary operator using member function how many argument required?

a)

Zero

b)

One

c)

Two

d)

Three

41.

Which is not operator in C++ ?

a)

~

b)

!

c)

@

d)

^

42.

Which of the following reduces the number of comparisons in a program ?

a)

(A) Operator overloading

b)

(B) Operations overloading

c)

(C) Function Overloading

d)

(D) Member overloading

43.

Which of the following is invalid prototype for function overloading

a)

(A) void fun (int x); void fun (char ch) ;

b)

(B) void fun (int x); void fun (int y);

c)

(C) void fun (double d); void fun (char ch);

d)

(D) void fun (double d); void fun (int y);

44.

What is a template in C++?

a)

A template in C++ is a blueprint for creating functions or classes that can work with any data type.

b)

A template in C++ is a type of variable.

c)

A template in C++ is a specific instance of a class.

d)

A template in C++ is a function that only accepts integers.

45.

How do function templates differ from class templates?

a)

Function templates require a specific return type, class templates do not.

b)

Class templates are for functions, while function templates are for classes.

c)

Function templates can only be used with integers.

d)

Function templates are for functions, class templates are for classes.

46.

What are the advantages of using templates in C++?

a)

Slower compilation times

b)

Limited compatibility with data types

c)

Increased memory usage

d)

Code reusability, type safety, reduced code duplication, and improved performance.

47.

What is meant by the template parameter?

a)

It can be used to pass a type as an argument

b)

It can be used to evaluate a type

c)

It can of no return type

d)

It can be used to delete a type

48.

How to declare a template?

a)

tem

b)

temp

c)

template<>

d)

temp()

49.

How many types of templates are there in c++?

a)

1

b)

2

c)

3

d)

4

50.

Pick out the correct statement.

a)

you only need to write one function, and it will work with many different types

b)

it will take a long time to execute

c)

duplicate code is increased

d)

it will take a long time to execute & duplicate code is increased

51.

What do C++ Vectors represent?

a)

Static Arrays

b)

Dynamic Arrays

c)

Stack

d)

Queue

52.

In which type of storage location are the vector members stored?

a)

Contiguous storage locations

b)

Non-contiguous storage locations

c)

Contiguous & Non-contiguous storage locations

d)

Memory storage locations

53.

What will be the output of the following C++ code?

a)

16

b)

Error

c)

16 2 77

d)

16 2 77 29

54.

What will be the output of the following C++ code?

a)

Size of a 0

Size of b 3

b)

Size of a 3

Size of b 5

c)

Error

d)

Size of a 3

Size of b 9

55.

Pick out the correct statement about vector.

a)

vector<int> values (5);

b)

vector values (5);

c)

vector<int> (5);

d)

vector<5>;

56.

Which is optional in the declaration of vector?

a)

Type

b)

Name

c)

vector

d)

Number of elements

57.

Unlike regular variables, __________ can hold multiple values.

a)

constants

b)

named constants

c)

arrays

d)

floats

58.
In an array, every element has the same
a)
data type
b)
subscript
c)
memory location
d)
all of the above
59.

What is the last legal subscript that can be used with the following array?

int values[5];

a)

0

b)

5

c)

6

d)

4

60.

Given the following declaration, where is the value 77 stored in the scores array?

int scores[] = {83, 62, 77, 97, 86}

a)

scores[0]

b)

scores[1]

c)

scores[2]

d)

scores[3]

61.

What will the following code display?

int numbers[5] = {99, 87, 66, 55, 101};

for (int i = 1; i < 4; i++)

cout << numbers[i] << " ";

a)

99 87 66 55 101

b)

87 66 55 101

c)

87 66 55

d)

Nothing. This code has an error.

62.

An array of string objects that will hold five names would be declared with which of the following statements?

a)

string names[5];

b)

string names(5);

c)

string names 5;

d)

String[5] = names;

63.

What is wrong with the following code fragment?

const int SIZE =5;

float scores[SIZE];

for(int i=0; i<=SIZE;i++)

{ cout << "Enter a score\n"; cin >> scores[i]; }

a)

Array indexes start at 1 not 0

b)

Arrays must be integers

c)

Array indexes must be less than the size of the array

d)

Should be cin >> scores[0];

64.

  Find the output for these fragment code :

 int arr[6] = { 11, 22, 33, 44 };

   for(int i=0;i<6;i++)

    cout<<arr[i] %2<< " ";

a)

0 1 0 1 0 0

b)

1 0 1 0 0 0

c)

1 0 1 0 1 0

d)

Error

65.

Which one of these is the indirection operator?

a)

&

b)

>>

c)

<<

d)

*