wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C++ Final Test 16-DEC-2024

Total questions: 70

Worksheet time: 1hrs 24mins

Name
Class
Date
1.

Wrapping data and its related functionality into a single entity is known as _____________

a)

Abstraction

b)

Encapsulation

c)

Polymorphism

d)

Modularity

2.

Which concept allows you to reuse the written code?

a)

Encapsulation

b)

Abstraction

c)

Inheritance

d)

Polymorphism

3.

vWhich of the following explains Polymorphism?

a)

int func(int, int); float func1(float, float);

b)

int func(int); int func(int);

c)

int func(float); float func(int, int, char);

d)

int func(); int new_func();

4.

C++ is ______________

a)

procedural programming language

b)

object oriented programming language

c)

functional programming language

d)

both procedural and object oriented programming language

5.

How many types of polymorphism are there in C++?

a)

1

b)

2

c)

3

d)

4

6.

iostream

a)

Displays output from the screen and input from the keyboard

b)

Has all the math equations

c)

Counts the time

d)

Checks if the code has a function

7.

Which of the following is a correct comment?

a)

*/ Comments */

b)

** Comment **

c)

/* Comment */

d)

{ Comment }

8.
Which command moves the shown text to the next line?
a)
\t
b)
\n
c)
\r
d)
\s
9.
A programmer is:
a)
person who writes code and communicates instructions to a computer
b)
person who types
c)
person who studies computers
d)
error or mistake in your code
10.

When a class is derived from a base class it gets access to:

a)

Private

b)

Protected

c)

Private and Protected

d)

Protected and Public

e)

Private, Protected and Public

11.

In a class the access specifiers are _______ by default:

a)

Private

b)

Protected

c)

Public

12.
a)

Equal strings

b)

There will be a compile error and it will not run

c)

Nothing will be output on the console

d)

None of the above

13.

When class B is inherited from class A, what is the order in which the destructors are called.

a)

Class A first Class B next

b)

Class B first Class A next

c)

Class B's only as it is the child class

d)

Class A's only as it is the parent class

14.
a)

The derived class can not call the base class func().

b)

Must place “using namespace Base” at the top of the file.

c)

Base::d.func();

d)

d.Base::func();

15.

What will happen when the following code is executed?

void main()

{

printf("MIET");

main();

}

a)

Wrong statement

b)

It will keep on printing MIET

c)

It will print MIET once

d)

None of these

16.

A function can have _____ inside the parenthesis

a)

loops

b)

Arguments/Parameters

c)

Braces

d)

Types

17.

A function that has no return type starts with:

a)

int

b)

void

c)

Arguments

d)

Braces

18.

A function that returns a whole number starts with the word

a)

int

b)

void

c)

string

d)

{ }

19.

Fill in the blank to have this function work properly


_____ function ( ) {


int a = 4;

int b = 5;


cout<<a*b;


}

a)

string

b)

int

c)

void

d)

variable

20.

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

21.

Fill in the blank to have this function work properly


_____ function ( ) {


int a;

cin >> a;


cout<<"You chose " << a <<endl;


}

a)

string

b)

void

c)

int

d)

variable

22.

True or False. We can call functions inside of other functions.

a)

True

b)

False

23.

A function that is not void needs to have a _____ _______

a)

variable calculation

b)

printing statement

c)

Return statement

d)

cout statement

24.

Fill in the blank to have this function work properly


double function ( ) {


int a;

cin >> a;


cout<<"You chose " << a <<endl;


return ____ ;


}

a)

"a"

b)

a

c)

a * 3.14

d)

cin

25.

Select the data types that can be used with the % operator.

a)

int

b)

float

c)

double

d)

all of the above

26.

an object is a /an instance of _______________

a)

class

b)

C++

c)

object

d)

iostream.h

27.

function is executed when it is

a)

defined

b)

prototyped

c)

declared

d)

called

28.

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

29.

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

a)

void function

b)

setter

c)

getter

d)

integer

30.

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");

31.

Given the following Banana class in C++:


class Banana{

string color;


Player(string c){


color = c;


}


}


int main(){


_________________


}


Create a new Banana object properly:

a)

banana name(color);

b)

Banana sample("yellow", 1);

c)

Banana sample("yellow");

d)

Banana sample();

32.

Fill in the blank to have this function work properly


_____ function ( int num) {


return num * 2;


}

a)

string

b)

void

c)

int

d)

variable

33.

Which of the following special symbol allowed in a variable name?

a)

* (asterisk)  

b)

| (pipeline) 

c)

- (hyphen)  

d)

_ (underscore)

34.

Which of the following is the correct order of evaluation for the below expression?

z = x + y * z / 4 % 2 - 1

a)

/ % + - =

b)

                                 = / % + -

c)

/ % - + =

d)

                                  % / - + =

35.

The following naming conventions are valid for C++, except:

a)

A. hello123

b)

B. _123hello

c)

C. _

d)

D. 123 hello

36.

The following naming conventions are valid for C++, except:

a)

A. hello123

b)

B. _123hello

c)

C. _

d)

D. 123 hello

37.

The escape sequence \n when output with cost, causes the cursor to position

a)

A. Next blank space on the same line

b)

B. Beginning of the same line on the screen

c)

C. End of the same line on the screen

d)

D. Beginning of the next line on the screen

38.

What is the output for this program?

a)

5

b)

0

c)

20

d)

3

39.

What is the output for this program?

a)

1

b)

2

c)

3

d)

5

40.

Ali buy 4 books. How many vouchers he will get?

a)

0

b)

1

c)

2

d)

3

41.
What is the output of the program?
a)
Ict Profi
b)
IctProfi
c)
Ict
Profi
d)
Profi
Ict
42.
What sign is used to end the code sentence ?
a)
,
b)
.
c)
:
d)
;
43.
Which code line is not correct in calculator program?
a)
2
b)
3
c)
1
d)
4
44.
How many times will it repeat displaying the text(I deserve a good education) on the screen?
a)
4
b)
5
c)
6
d)
infinite
45.
a)

Equal strings

b)

There will be a compile error and it will not run

c)

Nothing will be output on the console

d)

None of the above

46.
a)

0

b)

5

c)

-5

d)

10

e)

-10

47.
a)

Compile Error

b)

Inside Fun1()

c)

Inside Fun2()

d)

Inside Fun1() Inside Fun2()

e)

Inside Fun2() Inside Fun1()

48.
a)

Inside try

Exception Caught

After throw

After catch

b)

Inside try

Exception Caught

After catch

c)

Inside try

Exception Caught

d)

Inside try

After throw

After catch

49.

What punctuation is used to signal the beginning and end of code blocks?

a)

{ }

b)

-> and <-

c)

BEGIN and END

d)

( and )

50.
After running the following code, what will be the value of x?
y = 3;
x = 5 * y;
a)
3
b)
5
c)
15
d)
0
51.

Which of the following inserts the element in vector at end.

a)

insert()

b)

push()

c)

push_back()

d)

push_back(argument)

52.

Iterators are pointer like entities used to access individual elements in a container.

a)

True

b)

False

53.

Data structures that hold anything like other objects also.

a)

Iterators

b)

Algorithms

c)

Stack

d)

Containers

54.

Which of the following is odd?

a)

size()

b)

count()

c)

find()

d)

sort()

55.

Which of the following statements is true about vectors?

a)

Vectors allow you to store multiple values in a single variable

b)

Vectors can only hold one type of value

c)

Vectors are dynamic and can grow in size

d)

All of the other options are true

56.

Which of the following is NOT a correct way to create a vector?

a)

vector<string> greeting {"Hello", "Hola"};

b)

vector<int> nums {3, 6, 7.8, 9};

c)

vector<bool> option {true};

d)

All of the options are correct

57.

What will be printed from the following code snippet?

vector<string> count {"One", "Two", "Three"};

cout << count.at(1) << endl;

cout << count[2] << endl;

a)

1

2

b)

One

Two

c)

Two

Three

d)

Three

58.

Which statement best describes the actions of the push_back command?

a)

push_back adds a new element to the front of the vector, pushing all of the elements back 1 index and increasing the overall size by 1.

b)

push_back adds a new element to the end of the vector, increasing the size by 1.

c)

push_back replaces the first element in the vector.

d)

push_back replaces the last element in the vector.

59.

What does the following code segment return?

vector<string> lang {"C++", "Java", "Python", "JavaScript"};

cout << lang.at(lang.size() - 2) << endl;

a)

C++

b)

Java

c)

Python

d)

JavaScript

60.

What will print from the following code snippet?

vector<double> constants {3.14, 2.718, 0.577};

constants.pop_back();

constants.push_back(constants.size());

cout << constants[2] << endl;

a)

2

b)

3

c)

2.718

d)

0.577

61.

Which of the following code segments will print all members of an int vector v?

a)

1 only

b)

2 only

c)

Neither 1 or 2

d)

Both 1 and 2

62.

Which of the following statements is true about traversing a vector?

a)

for-each loops and for loops are completely interchangeable

b)

A benefit of the for-each loop is that it is easier to read and code

c)

A benefit of the for-each loop is that it has a tracker variable to reference the index

d)

Both for-each and for loops access the values of the vector via the vector’s index value

63.

What would be the output from the following code snippet?

a)

3 5 2 6 9 3

b)

9 6 9

c)

6 3 2 6

d)

The code will print an error.

64.

What is the main difference between an array and a vector in C++?

a)

Arrays can store multiple data types, vectors cannot

b)

Vectors can grow or shrink in size, but arrays cannot

c)

Arrays can be resized dynamically, vectors cannot

d)

None of the options is correct.

65.

Which header library is needed to use vectors in C++?

a)

<array>

b)

<vector>

c)

<string>

d)

<iostream>

66.

How would you create a vector called cars to store strings?

a)

vector cars<string>;

b)

string vector cars;

c)

vector<string> cars;

d)

cars<vector> string;

67.

Which function adds an element to the end of a vector?

a)

add()

b)

push_back()

c)

append()

d)

insert()

68.

Consider the following code. What does it do?

cars.pop_back();

a)

Removes the first element of the vector

b)

Adds an element to the end of the vector

c)

Removes the last element of the vector

d)

Clears all elements in the vector

69.

Which method is used to find out how many elements a vector has?

a)

lenght()

b)

count()

c)

size()

d)

capacity()

70.

What will the following code output?

vector cars = {"Volvo", "BMW", "Ford"};

cars.push_back("Tesla");

cout << cars.size();

a)

3

b)

4

c)

5

d)

0