NEW
Font size
WorksheetsC++ Final Quiz
Total questions: 65
Worksheet time: 1hrs 2mins
C++ was developed by __________.
Charles
Bjarne Stroustrup
Pascal
Dennis Ritchy
C++ is a ________ language.
Office-oriented procedure
Office-oriented programming
Object-oriented procedure
Object-oriented programming
Which of the following are the C++ tokens?
Variables
Operators
Keywords
All
Keywords are also called as ________.
Reserved words
Same words
Individual words
Special words
A ______ is a meaningful name of data storage location in computer memory.
constant
keyword
operator
variable
Which symbols are called as arithmetic operators?
< > <= >= == !=
&& || !
+ - * / %
=+ =- =* =/ =%
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
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
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);
Bank tom = new Bank(5000.0);
Which is the class?
Bank tom = new Bank(5000.0);
Which is the object?
What is inheritance in C++?
Inheritance in C++ is used to create new classes based on existing classes
Inheritance in C++ allows a class to inherit properties and behaviors from another class.
Inheritance in C++ is limited to inheriting only data members from another class
Inheritance in C++ is not supported in object-oriented programming
What is the syntax for inheriting a class in C++?
class DerivedClass :: BaseClass {}
class DerivedClass : public BaseClass {}
class DerivedClass : BaseClass {}
class DerivedClass : accessSpecifier BaseClass {}
What is the difference between public, private, and protected inheritance in C++?
Protected inheritance makes the private members of the base class protected in the derived class
Private inheritance makes the public members of the base class private in the derived class
Public inheritance makes the private members of the base class accessible in the derived class
Public inheritance makes the public members of the base class accessible in the derived class, private inheritance makes the public and protected members of the base class private in the derived class, and protected inheritance makes the public and protected members of the base class protected in the derived class.
Explain the concept of virtual inheritance in C++.
Virtual inheritance in C++ is used to allow multiple instances of the common base class to be inherited by the derived class
Virtual inheritance in C++ is used to resolve the ambiguity that arises when a class is derived from multiple classes that have a common base class. It ensures that only one instance of the common base class is inherited by the derived class.
Virtual inheritance in C++ is used to prevent a class from being inherited by any other class
Virtual inheritance in C++ is used to create instances of classes that are not physically present in memory
What are the different types of polymorphism in C++? Explain with examples.
Compile-time polymorphism and runtime polymorphism. Compile-time polymorphism is achieved through function overloading and operator overloading, while runtime polymorphism is achieved through virtual functions and function overriding.
Single polymorphism and multiple polymorphism. Single polymorphism is achieved through function overloading and multiple polymorphism is achieved through operator overloading.
Static polymorphism and dynamic polymorphism. Static polymorphism is achieved through virtual functions and dynamic polymorphism is achieved through function overloading.
Simple polymorphism and complex polymorphism. Simple polymorphism is achieved through operator overloading and complex polymorphism is achieved through function overloading.
What is encapsulation in C++?
A way to create multiple classes
The process of bundling related data members and functions together in a single class
A function that modifies variables
A mechanism for defining constants
Which of the following is an advantage of encapsulation?
It allows variables to be accessed from any class
It makes code cleaner and easier to read by grouping related data and functions
It forces all data members to be public
It removes the need for constructors
What is the difference between encapsulation and data hiding?
Encapsulation is about grouping related code, while data hiding restricts access to certain members
Data hiding is the same as encapsulation
Encapsulation always requires data hiding
Encapsulation hides implementation details, but data hiding allows full access to class members
What is the primary purpose of setter functions in C++?
To allow read-only access to private data members
To modify private data members from outside the class
To perform calculations on variables
To initialize objects
Which access specifier is used to hide class members from other classes in C++?
public
private
protected
default
What is the purpose of getter functions in C++?
To return the values of private data members
To modify private data members
To define new variables
To create objects of a class
How does encapsulation help with modifying data members in a controlled way?
By providing direct access to variables
By using getter and setter functions to control how data members are accessed or modified
By allowing all functions to modify variables directly
By creating multiple copies of data members
What happens if you try to access a private data member directly from outside the class?
The program runs successfully
The program raises a compile-time error
The variable is automatically converted to public
The variable is accessed without restriction
Pick out the defination of objects?
Member of the class
Associate of the class
Attributes of the class
Instance of the class
How many objects can present in a single class?
2
4
As many as possible
0
Which concept allows you to reuse the written code?
Encapsulation
Inheritance
Polymorphism
Class
What does modularity means?
Hiding part of program
Subdividing programs into small independent parts
Overriding parts of programs
Wrapping things into single unit?
C++ is _____________
Both procedural & object oriented programming language
Procedural programming language
Functional programming language
Which of the following explains Polymorphism?
int func(int, int);
float func1(float, float);
int func(float);
int func(int, int, char);
int func();
int new_func();
int func(int);
int func(int);
What will be the output of this piece of code?
5500.263
500.2635
500.263
500.266
What will be the output of this piece of code?
print derived class
show base class
print derived class
show derived class
Error
The overloaded operator must have at least one operand that is of which type ?
basic type
derived type
user defined type
system defined type
For overloading unary operator using member function how many argument required?
Zero
One
Two
Three
Which is not operator in C++ ?
~
!
@
^
Which of the following reduces the number of comparisons in a program ?
(A) Operator overloading
(B) Operations overloading
(C) Function Overloading
(D) Member overloading
Which of the following is invalid prototype for function overloading
(A) void fun (int x); void fun (char ch) ;
(B) void fun (int x); void fun (int y);
(C) void fun (double d); void fun (char ch);
(D) void fun (double d); void fun (int y);
What is a template in C++?
A template in C++ is a blueprint for creating functions or classes that can work with any data type.
A template in C++ is a type of variable.
A template in C++ is a specific instance of a class.
A template in C++ is a function that only accepts integers.
How do function templates differ from class templates?
Function templates require a specific return type, class templates do not.
Class templates are for functions, while function templates are for classes.
Function templates can only be used with integers.
Function templates are for functions, class templates are for classes.
What are the advantages of using templates in C++?
Slower compilation times
Limited compatibility with data types
Increased memory usage
Code reusability, type safety, reduced code duplication, and improved performance.
What is meant by the template parameter?
It can be used to pass a type as an argument
It can be used to evaluate a type
It can of no return type
It can be used to delete a type
How to declare a template?
tem
temp
template<>
temp()
How many types of templates are there in c++?
1
2
3
4
Pick out the correct statement.
you only need to write one function, and it will work with many different types
it will take a long time to execute
duplicate code is increased
it will take a long time to execute & duplicate code is increased
What do C++ Vectors represent?
Static Arrays
Dynamic Arrays
Stack
Queue
In which type of storage location are the vector members stored?
Contiguous storage locations
Non-contiguous storage locations
Contiguous & Non-contiguous storage locations
Memory storage locations
What will be the output of the following C++ code?
16
Error
16 2 77
16 2 77 29
What will be the output of the following C++ code?
Size of a 0
Size of b 3
Size of a 3
Size of b 5
Error
Size of a 3
Size of b 9
Pick out the correct statement about vector.
vector<int> values (5);
vector values (5);
vector<int> (5);
vector<5>;
Which is optional in the declaration of vector?
Type
Name
vector
Number of elements
Unlike regular variables, __________ can hold multiple values.
constants
named constants
arrays
floats
What is the last legal subscript that can be used with the following array?
int values[5];
0
5
6
4
Given the following declaration, where is the value 77 stored in the scores array?
int scores[] = {83, 62, 77, 97, 86}
scores[0]
scores[1]
scores[2]
scores[3]
What will the following code display?
int numbers[5] = {99, 87, 66, 55, 101};
for (int i = 1; i < 4; i++)
cout << numbers[i] << " ";
99 87 66 55 101
87 66 55 101
87 66 55
Nothing. This code has an error.
An array of string objects that will hold five names would be declared with which of the following statements?
string names[5];
string names(5);
string names 5;
String[5] = names;
What is wrong with the following code fragment?
const int SIZE =5;
float scores[SIZE];
for(int i=0; i<=SIZE;i++)
{ cout << "Enter a score\n"; cin >> scores[i]; }
Array indexes start at 1 not 0
Arrays must be integers
Array indexes must be less than the size of the array
Should be cin >> scores[0];
Find the output for these fragment code :
int arr[6] = { 11, 22, 33, 44 };
for(int i=0;i<6;i++)
cout<<arr[i] %2<< " ";
0 1 0 1 0 0
1 0 1 0 0 0
1 0 1 0 1 0
Error
Which one of these is the indirection operator?
&
>>
<<
*
