wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C++Test OOPS

Total questions: 60

Worksheet time: 52mins

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.

How structures and classes in C++ differ?

a)

In Structures, members are public by default whereas, in Classes, they are private by default

b)

In Structures, members are private by default whereas, in Classes, they are public by default

c)

Structures by default hide every member whereas classes do no

d)

Structures cannot have private members whereas classes can have

3.

Which concept allows you to reuse the written code?

a)

Encapsulation

b)

Abstraction

c)

Inheritance

d)

Polymorphism

4.

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

5.

C++ is ______________

a)

procedural programming language

b)

object oriented programming language

c)

functional programming language

d)

both procedural and object oriented programming language

6.

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

a)

1

b)

2

c)

3

d)

4

7.

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

8.

Which of the following is a correct comment?

a)

*/ Comments */

b)

** Comment **

c)

/* Comment */

d)

{ Comment }

9.
Which command moves the shown text to the next line?
a)
\t
b)
\n
c)
\r
d)
\s
10.
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
11.

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

12.

In a class the access specifiers are _______ by default:

a)

Private

b)

Protected

c)

Public

13.
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

14.

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

15.
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();

16.

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

17.

A function can have _____ inside the parenthesis

a)

loops

b)

Arguments/Parameters

c)

Braces

d)

Types

18.

A function that has no return type starts with:

a)

int

b)

void

c)

Arguments

d)

Braces

19.

A function that returns a whole number starts with the word

a)

int

b)

void

c)

string

d)

{ }

20.

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

21.

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

22.

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

23.

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

a)

True

b)

False

24.

Select all of the types you may have for a function

a)

string

b)

bool

c)

void

d)

variable

e)

int

25.

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

a)

variable calculation

b)

printing statement

c)

Return statement

d)

cout statement

26.

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

27.

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

a)

int

b)

float

c)

double

d)

all of the above

28.

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

29.

an object is a /an instance of _______________

a)

class

b)

C++

c)

object

d)

iostream.h

30.

function is executed when it is

a)

defined

b)

prototyped

c)

declared

d)

called

31.

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

32.

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

33.

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

34.

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

35.

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

36.

Fill in the blank to have this function work properly


_____ function ( int num) {


return num * 2;


}

a)

string

b)

void

c)

int

d)

variable

37.

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

a)

* (asterisk)  

b)

| (pipeline) 

c)

- (hyphen)  

d)

_ (underscore)

38.

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)

                                  % / - + =

39.

In which order do the following gets evaluated

1. Relational 2. Arithmetic 3. Logical 4. Assignment

a)

1234

b)

4321

c)

2134

d)

3214

40.

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

a)

A. hello123

b)

B. _123hello

c)

C. _

d)

D. 123 hello

41.

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

a)

A. hello123

b)

B. _123hello

c)

C. _

d)

D. 123 hello

42.

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

43.

What is the output for this program?

a)

5

b)

0

c)

20

d)

3

44.

What is the output for this program?

a)

1

b)

2

c)

3

d)

5

45.

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

a)

0

b)

1

c)

2

d)

3

46.
What is the output of the program?
a)
Ict Profi
b)
IctProfi
c)
Ict
Profi
d)
Profi
Ict
47.
What sign is used to end the code sentence ?
a)
,
b)
.
c)
:
d)
;
48.
Which code line is not correct in calculator program?
a)
2
b)
3
c)
1
d)
4
49.
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
50.

What output is produced by the following segment of code:


for(int fun = 20; fun > 1; fun -=3)

cout << fun << " ";

a)

20 17 14 11 8 5 2 -1

b)

20 17 14 11 8 5 2

c)

17 14 11 8 5 2 -1

d)

20 17 14 11 8 5

e)

Infinite Loop

51.
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

52.
a)

I only

b)

II only

c)

III only

d)

I and II only

e)

II and II only

53.
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();

54.
a)

0

b)

5

c)

-5

d)

10

e)

-10

55.
a)

Compile Error

b)

Inside Fun1()

c)

Inside Fun2()

d)

Inside Fun1() Inside Fun2()

e)

Inside Fun2() Inside Fun1()

56.
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

57.

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

a)

{ }

b)

-> and <-

c)

BEGIN and END

d)

( and )

58.
A list of instructions that enable a computer to perform a specific task is a...
a)
Computer Program
b)
Algorithm
c)
Machine Code
d)
Binary Code
59.
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
60.

STL comprise of which components?

a)

Iterators

b)

algorithms

c)

containers

d)

all the above