wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

8.12 C++ Test on Classes

Total questions: 15

Worksheet time: 7mins

Name
Class
Date
1.

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

2.

an object is a /an instance of _______________

a)

class

b)

C++

c)

object

d)

iostream.h

3.

A function can have _____ inside the parenthesis

a)

loops

b)

Arguments/Parameters

c)

Braces

d)

Types

4.

A function that has no return type starts with:

a)

int

b)

void

c)

Arguments

d)

Braces

5.

A function that returns a whole number starts with the word

a)

int

b)

void

c)

string

d)

{ }

6.

function is executed when it is

a)

defined

b)

prototyped

c)

declared

d)

called

7.

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

8.

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

9.

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

10.

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

11.

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

12.

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

13.

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

14.

Fill in the blank to have this function work properly


_____ function ( int num) {


return num * 2;


}

a)

string

b)

void

c)

int

d)

variable

15.
What are these?
a)
Fields
b)
Properties
c)
Classes
d)
Constructors