Font size
WorksheetsC++Test OOPS
Total questions: 60
Worksheet time: 52mins
Wrapping data and its related functionality into a single entity is known as _____________
Abstraction
Encapsulation
Polymorphism
Modularity
How structures and classes in C++ differ?
In Structures, members are public by default whereas, in Classes, they are private by default
In Structures, members are private by default whereas, in Classes, they are public by default
Structures by default hide every member whereas classes do no
Structures cannot have private members whereas classes can have
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
Select all of the types you may have for a function
string
bool
void
variable
int
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
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
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 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
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
/ % + - =
= / % + -
/ % - + =
% / - + =
In which order do the following gets evaluated
1. Relational 2. Arithmetic 3. Logical 4. Assignment
1234
4321
2134
3214
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
What output is produced by the following segment of code:
for(int fun = 20; fun > 1; fun -=3)
cout << fun << " ";
20 17 14 11 8 5 2 -1
20 17 14 11 8 5 2
17 14 11 8 5 2 -1
20 17 14 11 8 5
Infinite Loop
Equal strings
There will be a compile error and it will not run
Nothing will be output on the console
None of the above
I only
II only
III only
I and II only
II and II only
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();
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;
STL comprise of which components?
Iterators
algorithms
containers
all the above
