NEW
Font size
WorksheetsC++ Final Test 16-DEC-2024
Total questions: 70
Worksheet time: 1hrs 24mins
Wrapping data and its related functionality into a single entity is known as _____________
Abstraction
Encapsulation
Polymorphism
Modularity
Which concept allows you to reuse the written code?
Encapsulation
Abstraction
Inheritance
Polymorphism
vWhich of the following explains Polymorphism?
int func(int, int); float func1(float, float);
int func(int); int func(int);
int func(float); float func(int, int, char);
int func(); int new_func();
C++ is ______________
procedural programming language
object oriented programming language
functional programming language
both procedural and object oriented programming language
How many types of polymorphism are there in C++?
1
2
3
4
iostream
Displays output from the screen and input from the keyboard
Has all the math equations
Counts the time
Checks if the code has a function
Which of the following is a correct comment?
*/ Comments */
** Comment **
/* Comment */
{ Comment }
When a class is derived from a base class it gets access to:
Private
Protected
Private and Protected
Protected and Public
Private, Protected and Public
In a class the access specifiers are _______ by default:
Private
Protected
Public
Equal strings
There will be a compile error and it will not run
Nothing will be output on the console
None of the above
When class B is inherited from class A, what is the order in which the destructors are called.
Class A first Class B next
Class B first Class A next
Class B's only as it is the child class
Class A's only as it is the parent class
The derived class can not call the base class func().
Must place “using namespace Base” at the top of the file.
Base::d.func();
d.Base::func();
What will happen when the following code is executed?
void main()
{
printf("MIET");
main();
}
Wrong statement
It will keep on printing MIET
It will print MIET once
None of these
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
{ }
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
Fill in the blank to have this function work properly
_____ function ( ) {
int a;
cin >> a;
cout<<"You chose " << a <<endl;
}
string
void
int
variable
True or False. We can call functions inside of other functions.
True
False
A function that is not void needs to have a _____ _______
variable calculation
printing statement
Return statement
cout statement
Fill in the blank to have this function work properly
double function ( ) {
int a;
cin >> a;
cout<<"You chose " << a <<endl;
return ____ ;
}
"a"
a
a * 3.14
cin
Select the data types that can be used with the % operator.
int
float
double
all of the above
an object is a /an instance of _______________
class
C++
object
iostream.h
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
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 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
Which of the following special symbol allowed in a variable name?
* (asterisk)
| (pipeline)
- (hyphen)
_ (underscore)
Which of the following is the correct order of evaluation for the below expression?
z = x + y * z / 4 % 2 - 1
/ % + - =
= / % + -
/ % - + =
% / - + =
The following naming conventions are valid for C++, except:
A. hello123
B. _123hello
C. _
D. 123 hello
The following naming conventions are valid for C++, except:
A. hello123
B. _123hello
C. _
D. 123 hello
The escape sequence \n when output with cost, causes the cursor to position
A. Next blank space on the same line
B. Beginning of the same line on the screen
C. End of the same line on the screen
D. Beginning of the next line on the screen
What is the output for this program?
5
0
20
3
What is the output for this program?
1
2
3
5
Ali buy 4 books. How many vouchers he will get?
0
1
2
3
Profi
Ict
Equal strings
There will be a compile error and it will not run
Nothing will be output on the console
None of the above
0
5
-5
10
-10
Compile Error
Inside Fun1()
Inside Fun2()
Inside Fun1() Inside Fun2()
Inside Fun2() Inside Fun1()
Inside try
Exception Caught
After throw
After catch
Inside try
Exception Caught
After catch
Inside try
Exception Caught
Inside try
After throw
After catch
What punctuation is used to signal the beginning and end of code blocks?
{ }
-> and <-
BEGIN and END
( and )
y = 3;
x = 5 * y;
Which of the following inserts the element in vector at end.
insert()
push()
push_back()
push_back(argument)
Iterators are pointer like entities used to access individual elements in a container.
True
False
Data structures that hold anything like other objects also.
Iterators
Algorithms
Stack
Containers
Which of the following is odd?
size()
count()
find()
sort()
Which of the following statements is true about vectors?
Vectors allow you to store multiple values in a single variable
Vectors can only hold one type of value
Vectors are dynamic and can grow in size
All of the other options are true
Which of the following is NOT a correct way to create a vector?
vector<string> greeting {"Hello", "Hola"};
vector<int> nums {3, 6, 7.8, 9};
vector<bool> option {true};
All of the options are correct
What will be printed from the following code snippet?
vector<string> count {"One", "Two", "Three"};
cout << count.at(1) << endl;
cout << count[2] << endl;
1
2
One
Two
Two
Three
Three
Which statement best describes the actions of the push_back command?
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.
push_back adds a new element to the end of the vector, increasing the size by 1.
push_back replaces the first element in the vector.
push_back replaces the last element in the vector.
What does the following code segment return?
vector<string> lang {"C++", "Java", "Python", "JavaScript"};
cout << lang.at(lang.size() - 2) << endl;
C++
Java
Python
JavaScript
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;
2
3
2.718
0.577
Which of the following code segments will print all members of an int vector v?
1 only
2 only
Neither 1 or 2
Both 1 and 2
Which of the following statements is true about traversing a vector?
for-each loops and for loops are completely interchangeable
A benefit of the for-each loop is that it is easier to read and code
A benefit of the for-each loop is that it has a tracker variable to reference the index
Both for-each and for loops access the values of the vector via the vector’s index value
What would be the output from the following code snippet?
3 5 2 6 9 3
9 6 9
6 3 2 6
The code will print an error.
What is the main difference between an array and a vector in C++?
Arrays can store multiple data types, vectors cannot
Vectors can grow or shrink in size, but arrays cannot
Arrays can be resized dynamically, vectors cannot
None of the options is correct.
Which header library is needed to use vectors in C++?
<array>
<vector>
<string>
<iostream>
How would you create a vector called cars to store strings?
vector cars<string>;
string vector cars;
vector<string> cars;
cars<vector> string;
Which function adds an element to the end of a vector?
add()
push_back()
append()
insert()
Consider the following code. What does it do?
cars.pop_back();
Removes the first element of the vector
Adds an element to the end of the vector
Removes the last element of the vector
Clears all elements in the vector
Which method is used to find out how many elements a vector has?
lenght()
count()
size()
capacity()
What will the following code output?
vector cars = {"Volvo", "BMW", "Ford"};
cars.push_back("Tesla");
cout << cars.size();
3
4
5
0
