NEW
Font size
Worksheets8.12 C++ Test on Classes
Total questions: 15
Worksheet time: 7mins
A ________ is blue print that defines certain characteristics and behavior. It is simply a representation of different types of objects.
Class
Object
Attribute
Characteristics
an object is a /an instance of _______________
class
C++
object
iostream.h
A function can have _____ inside the parenthesis
loops
Arguments/Parameters
Braces
Types
A function that has no return type starts with:
int
void
Arguments
Braces
A function that returns a whole number starts with the word
int
void
string
{ }
function is executed when it is
defined
prototyped
declared
called
A function that changes the values of an object's attributes in a Class is also known as a:
string function
setter
getter
changer
A function that returns values of an object's attributes in a Class is also known as a:
void function
setter
getter
integer
Fill in the blank to have this function work properly
_____ function ( ) {
int a = 4;
int b = 5;
cout<<a*b;
}
string
int
void
variable
Fill in the blank to have this function work properly
_____ function ( ) {
string greeting = "Welcome to my game";
return greeting;
}
string
void
int
variable
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"?
monkey.name();
mon.setName("Sir Monkey");
mon.setName(Sir Monkey);
monkeymon.setName("Sir Monkey");
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:
player name();
Player user("John", 13);
Player user(John, "13");
Player user(name, age);
Given the following Banana class in C++:
class Banana{
string color;
Player(string c){
color = c;
}
}
int main(){
_________________
}
Create a new Banana object properly:
banana name(color);
Banana sample("yellow", 1);
Banana sample("yellow");
Banana sample();
Fill in the blank to have this function work properly
_____ function ( int num) {
return num * 2;
}
string
void
int
variable
