0% found this document useful (0 votes)
24 views49 pages

OOP Semester Final 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views49 pages

OOP Semester Final 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Asif Talukder

ID: 0622220105101004
Topic: Inheritance

1.What is inheritance in C++?

a) A way to define a new class based on an existing class

b) A way to define a new function based on an existing function

c) A way to define a new object based on an existing object

d) A way to define a new variable based on an existing variable

e) None of the above

Answer: a) A way to define a new class based on an existing class

2. Which keyword is used to inherit a class in C++?

a) inherit

b) class

c) extends

d) inherits

e) friend

Answer: b) class

3. What is the syntax for single inheritance in C++?

a) class Subclass : Superclass {}

b) class Superclass : Subclass {}

c) class Subclass :: Superclass {}

d) class Superclass :: Subclass {}

e) class Superclass1, Superclass2 :: Subclass {}

Answer: a) class Subclass : Superclass {}

4. What is the syntax for multiple inheritance in C++?

a) class Subclass : Superclass1, Superclass2 {}

b) class Superclass1, Superclass2 : Subclass {}


c) class Subclass :: Superclass1, Superclass2 {}

d) class Superclass1, Superclass2 :: Subclass {}

e) class Subclass : Superclass {}

Answer: a) class Subclass : Superclass1, Superclass2 {}

5. Which of the following is true about single inheritance in C++?

a) A class can inherit from multiple base classes simultaneously

b) A class can inherit from a single base class only

c) A class cannot inherit from any base class

d) A class can inherit from any number of base classes

e) None of the above

Answer: b) A class can inherit from a single base class only

6. Which of the following is true about multi-level inheritance in C++?

a) A class can inherit from multiple base classes simultaneously

b) A class can inherit from a single base class only

c) A class cannot inherit from any base class

d) A class can inherit from any number of base classes

e) A class can inherit from a base class, which in turn inherits from another base class

Answer: e) A class can inherit from a base class, which in turn inherits from another base class

7. Which of the following is not a type of inheritance in C++?

a) Single

b) Multiple

c) Hybrid

d) Multi-dimensional

e) Hierarchical Inheritance.

Answer: d) Multi-dimensional

8. What is a base class in C++?

a) A class that is derived from another class

b) A class that has no derived classes

c) A class that has only virtual functions


d) A class that cannot be instantiated

e) A class that has a private destructor

Answer: b) A class that has no derived classes

9. What is a derived class in C++?

a) A class that is inherited from multiple base classes

b) A class that has a constructor and destructor

c) A class that has only public members

d) A class that is created from a base class

e) A class that has only private members

Answer: d) A class that is created from a base class

10. In single inheritance, how many base classes can a derived class have?

a) One

b) Two

c) Three

d) Multiple

e) Unlimited

Answer: a) One

11. In multiple inheritance, how many base classes can a derived class have?

a) One

b) Two

c) Three

d) Multiple

e) Unlimited

Answer: d) Multiple

12. In multi-level inheritance, how many levels can there be between the base class and the derived
class?

a) One

b) Two

c) Three
d) Multiple

e) Unlimited

Answer: e) Unlimited

13. “class ABC : private XYZ” it is a:

a. private derivation

b. public derivation

c. protected derivation

d. private derivation by default

e. public derivation by default

Ans: a. private derivation

14. How many types of Inheritance in C++?

a. 6

b.4

c.3

d.5

e.7

ans: d. 5

15.Which tyoe of inharitance it is?

a) Single inheritance
b) Multilevel inheritance
c) Multiple inheritance
d) Hierarchical inheritance
e) Hybrid inheritance
Ans. d. Hierarchical inheritance.

Ibrahim Hossain
Topic: Abstract Class

1. Which class is used to design the base class?


a) abstract class
b) derived class
c) base class
d) derived & base class
e) friend class

Answer: a

2.Which is also called as abstract class?

a) virtual function
b) pure virtual function
c) derived class
d) base class
e) friend class

Answer: b

3. Where does the abstract class is used?


a) base class only
b) derived class
c) both derived & base class
d) friend class
e) virtual class

Answer: a

4. Which is used to create a pure virtual function?


a) $
b) =0
c) &
d)!
e) %

Answer: b

5. Which is the correct syntax of defining a pure virtual function?


a) pure virtual return_type func();
b) virtual return_type func() pure;
c) virtual return_type func() = 0;
d) virtual return_type func() = 1;
e) virtual return_type func();

Answer: c

6. What will be the output of the following C++ code?

#include <iostream>
#include <string>
using namespace std;
class A
{
int a;
public:
virtual void func() = 0;
};
class B: public A
{
public:
void func(){
cout<<"Class B"<<endl;
}
};

int main(int argc, char const *argv[])


{
B b;
b.func();
return 0;
}

a) Class A
b) Class B
c) Segmentation fault
d) No output
e) Error

Answer: b

7. What will be the output of the following C++ code?

#include <iostream>
#include <string>
using namespace std;
class A
{
int a;
public:
virtual void func() = 0;
};

class B: public A
{
public:
void func(){
cout<<"Class B"<<endl;
}
};

int main(int argc, char const *argv[])


{
A a;
a.func();
return 0;
}

a) Class A
b) Class B
c) Segmentation fault
d) No output
e) Error

Answer: e

• Friend Functions

8. What is a friend function in C++?


a) A function which can access all the private, protected and public members of a class

b) A function which can’t access all the private, protected and public members of a class
c) A function which is not allowed to access any member of any class
d) A function which is allowed to access public and protected members of a class
e) A function which is allowed to access only public members of a class

Answer: a

9. Which keyword is used to represent a friend function?


a) friend
b) Friend
c) friend_func
d) Friend_func
e) Friend_function

Answer: a
10. Which of the following is correct about friend functions?
a) Friend functions can access only protected members not the private members

b) Friend functions can’t be private or public

c) Friend can access the members of the class directly


d) Friend functions are in the scope of a class
e) Friend functions use the dot operator to access members of a class using class
objects

Answer: e

11. Pick the correct statement.


a) Friend functions are in the scope of a class
b) Friend functions can be called using class objects
c) Friend functions can be invoked as a normal function
d) Friend functions can access only protected members not the private members
e) Friend can access the members of the class directly

Answer: c

12. Which is the correct syntax of defining a friend function?


a) Friend return_type func_name
b) Friend return_type func_name;
c) friend return_type func_name(argument/s)
d) Friend return_type func_name (argument/s);
e) friend return_type func_name (argument/s);

Answer: e

13. Where does keyword ‘friend’ should be placed?


a) function declaration
b) function definition
c) main function
d) block function
e) function encapsulation
Answer: a

14. What will be the output of the following C++ code?


1. #include <iostream>
2. using namespace std;
3. class base
4. {
5. int val1, val2;
6. public:
7. int get()
8. {
9. val1 = 100;
10. val2 = 300;
11. }
12. friend float mean(base ob);
13. };
14. float mean(base ob)
15. {
16. return float(ob.val1 + ob.val2) / 2;
17. }
18. int main()
19. {
20. base obj;
21. obj.get();
22. cout << mean(obj);
23. return 0;
24. }
a) 200
b) 150
c) 100
d) 300
e) 400

Answer: a

15. What will be the output of the following C++ code?

#include <iostream>
#include <string>
using namespace std;
class Box
{
int capacity;
public:
Box(int cap)

{
capacity = cap;
}

friend void show();


};

void show()
{
Box b(10);
cout<<"Value of capacity is: "<<b.capacity<<endl;
}

int main(int argc, char const *argv[])


{
show();
return 0;
}

a) Value of capacity is: 10


b) Value of capacity is: 100
c) Value of capacity is: 110
d) Segmentation fault
e) Error

Answer: a

Nazmul Hassan
Topic : Friend Functiom
1.Which keyword is used to represent a friend function?

A. friend

B. Friend

C. friend_func

D. Friend_func

Ans: A

2.Where does keyword ‘friend’ should be placed?

A. function declaration

B. function definition

C. main function

D. block function

Ans:A

3.Pick the correct statement.

A. Friend functions are in the scope of a class

B. Friend functions can be called using class objects

C. Friend functions can be invoked as a normal function

D. Friend functions can access only protected members not the private members

Ans: C

4.The keyword friend does not appear in

A. the public section of a class.

B. the private section of a class.

C. the class desiring access to another class.

D. the class allowing access to another class

Ans:B

5.Which function can be called without using an object of a class in C++

A. Static function

B. Inline function

C. Friend function
D. constant function

Ans:A

6.In C++, friend functions are used for:

a) Performing arithmetic operations

b) Modifying public members of a class

c) Accessing private members of a class

d) Creating objects of a class

e) Relevant option:

Ans:c) Accessing private members of a class

7.What is the relationship between a friend function and a class?

a) Inheritance.

b) Aggregation.

c) Association.

d) Composition.

e) Relevant option:

Ans:c) Association

8.Which access specifier is used when declaring a friend function?

a) public.

b) private.

c) protected.

d) No access specifier is used.

e) Relevant option:

Ans: d) No access specifier is used.

9.Which of the following is true about the visibility of friend functions?

a) Friend functions are only visible within the class they are declared in.

b) Friend functions are only visible within the file they are defined in.

c) Friend functions are only visible within the namespace they are declared in.

d) Friend functions are visible to all classes.

e) Relevant option:
Ans:b) Friend functions are only visible within the file they are defined in.

10.How many member functions are there in this C++ class excluding constructors and

destructors?

class Box

int capacity;

public:

void print();

friend void show();

bool compare();

friend bool lost();

};

a) 1

b) 2

c) 3

d) 4

ans:b

11.What will be the output of the following C++ code?

#include <iostream>

#include <string>

using namespace std;

class B

int b;

public:

B(){}

B(int i){

b = i;

}
int show(){

return b;

};

class C

B b;

public:

C(int i){

b = B(i);

friend void show(){

C c(10);

cout<<"value of b is: "<<c.b.show()<<endl;

};

int main(int argc, char const *argv[])

show();

return 0;

a) value of b is: 10

b) value of b is: 12345435

c) error

d) segmentation fault

Ans:C

12.What is the syntax of friend function?

a) friend class1 Class2;

b) friend class;
c) friend class

d) friend class()

Ans:A

13.Global Function can be Friend functions for which of the following class?

(A). Base class

(B). Derived class

(c). Any classes

(D). None of these

Ans:C

#include <iostream>

using namespace std;

class one {

private:

int n1=1;

public:

friend int add (one);

};

int add(one object1)

return (object1.n1 + 1);

int main()

one object1

cout<<"Sum: "<< add(object1);

return 0;

}}

14.Friend functions have "objects"as___________?

(A). class

(B). arguments
(c). child

(D). Parent

Ans:B

15.
Name : Anika Bushra
ID : 0622220205101015
Topic:

1. C++ supports run time polymorphism with the help of virtual functions, which is called ……………..
binding.
A) dynamic
B) run time
C) early binding
D)static
E) compile time binding
Ans: A

2. Run time polymorphism is achieved only when a ……………….. is accessed through a pointer to the base
class.
A) member function
B) virtual function
C) static function
D) real function
E) dynamic function
Ans: B

3. Run time polimorphism can be achieved with.........


A) Virtual base class
B) container class
C) Virtual function
D) Function overloading
E) Abstract class
Ans: C

4.The word polymorphism means ____

(A) Many programs

(B) Two forms

(C) Single form

(D) Many form


E) Single program

Ans:D
5. Which among the following best describes polymorphism?
A) It is the ability for a message/data to be processed in more than one form
B) It is the ability for a message/data to be processed in only 1 form
C) It is the ability for many messages/data to be processed in one way
D) It is the ability for undefined message/data to be processed in at least one way
e)It is the inability for many messages to be processed in one way
Ans: A

6. If same message is passed to objects of several different classes and all of


those can respond in a different way, what is this feature called?
A) Inheritance B) Overloading
C) Polymorphism D) Overriding
E)Function
Ans: C

7. Which among the following can’t be used for polymorphism?


A) Static member functions
B) Member functions overloading
C)operator overloading
D) Predefined operator overloading
E) Constructor overloading
Ans: A

8. The provision of a single interface to entities of different types is called?


A. polymorphism
B. dimorphism
C. trimorphism
D. Overloading
E. Inheritance
Ans: A

9. Using operation or function in different ways depending on what they are


operating on is called?
A. classes
B.inheritence
C. polymorphism
D. dimorphism
E. operator overloading
ans: C
10.How many types of polymorphism in C++?
A) 2
B)5
C)3
D)6
E)7
Ans: A

10. Compile time polymorphism also known as ....


A) Dynamic binding
B) Virtual binding
C) Late binding
D) Base binding
E) Static binding
Ans: E

11. The languages that support classes but not polymorphism is called?
A. child Class-based language
B. Class-based language
C. Object-based language
D. object class based language
E. Procedure Oriented language
Ans: C

12. Polymorphism is achieved through ___

A) Heritance

B) Poly programming

C) Encapsulation

D) Overloading

E) Virtual function

Ans : D
13. The mechanism of giving special meaning to an operator is called ____

A) Object

B) Inheritance

C ) Ambiguity

D) Operator Overloading
E) Function overloading
Ans : D
14. When a virtual function is redefined by the derived class, it is called__________

a. Overloading
b. Overriding
c. Rewriting
d. polymorphism
e. inheritance
Ans : b

15. When an object has many froms ,it has.........


A) Inheritance
B) function overloading
C) polymorphism
D) Operator overloading
E) Ambiguity
Ans : C

Virtual Functions and Overriding


-Modhusodan Devnath
1. When a function is declared as virtual in a base class, it enables:

a) Function overloading

b) Early binding

c) Late binding
d) Function hiding

e) Static binding

Answer: c) Late binding

2. Which keyword is used to override a virtual function in a derived

class?

a) new

b) override

c) extend

d) inherit

e) virtual

Answer: b) override

3. In C++, a virtual function is defined in the base class with the

keyword:

a) base

b) virtual

c) override

d) derived

e) polymorphic

Answer: b) virtual

4. In C++, a base class pointer can be used to call a derived class


function when:

a) The derived class function is static.

b) The derived class function is non-virtual.

c) The derived class function has the same name as the base class
function.

d) The derived class function is defined after the base class


function.

e) The derived class function overrides the base class function.

Answer: e) The derived class function overrides the base class

function.
5. Which keyword is used to prevent further overriding of a virtual

function in derived classes?

a) restrict

b) override

c) final

d) prevent

e) lock

Answer: c) final

6. What is the purpose of a virtual destructor in a base class?

a) To prevent memory leaks in derived classes.

b) To allow the destruction of base class objects only.

c) To enable the calling of derived class destructors.

d) To ensure proper cleanup of resources in derived classes.

e) To mark the class as abstract.

Answer: d) To ensure proper cleanup of resources in derived

classes.

7. In C++, a virtual function table is used for:

a) Storing all the virtual functions in a program.

b) Resolving function calls at runtime.

c) Determining the size of objects at compile time.

d) Preventing function hiding in derived classes.

e) Initializing static variables.

Answer: b) Resolving function calls at runtime.

8. When a derived class overrides a virtual function from the base

class, the function in the derived class:

a) Must have the same return type as the base class function.

b) Must have a different name than the base class function.

c) Must have the same access specifier as the base class function.
d) Must have the same number of parameters as the base class

function.

e) Must have a different return type than the base class function.

Answer: a) Must have the same return type as the base class

function.

9. In C++, a function declared as pure virtual in a base class:

a) Must be defined in the derived class.

b) Cannot be called directly.

c) Can only be called using base class objects.

d) Is automatically called when the derived class is instantiated.

e) Is not allowed to have any parameters.

Answer: a) Must be defined in the derived class.

10. In C++, the "final" keyword is used to:

a) Prevent a class from being derived.

b) Prevent a function from being overridden.

c) Specify the final value of a constant.

d) Indicate the end of a loop.

e) Define a static variable.

Answer: b) Prevent a function from being overridden.

11. A class that contains at least one pure virtual function is called

a/an:

a) Concrete class

b) Derived class

c) Abstract class

d) Final class

e) Static class
Answer: c) Abstract class

12. The process of providing a different implementation of a base

class function in a derived class is called:

a) Overloading

b) Overriding

c) Polymorphism

d) Inheritance

e) Encapsulation

Answer: b) Overriding

13. What is the main advantage of using virtual functions in C++?

a) They allow for function overloading.

b) They enable late binding and runtime polymorphism.

c) They provide a way to define abstract classes.

d) They eliminate the need for derived classes.

e) They improve code efficiency.

Answer: b) They enable late binding and runtime polymorphism.

14. What is the purpose of the virtual keyword in a base class

function declaration?

a) It indicates that the function can be overridden in derived

classes.

b) It specifies that the function is a static member of the class.

c) It enables function overloading for the function.

d) It ensures that the function is visible to all classes in the program.

e) It indicates that the function cannot be called directly.

Answer: a) It indicates that the function can be overridden in

derived classes.
Topic: object oriented I/o.
Meherun Kajol

1.The unformatted input functions are handled by...

A. ostream class.

B. instream class.

c. istream class.

D. bufstream class.

E.imstream class.

Answer: B

1. A class that defined the cout , cerr , and clog objects and stream insertion operator is called…
A. Istream.
B. Ostream.
C. Fstream.
D. Kstream.
E. Bufstream.
Answer; B

3.The I/o operations that use the extraction and insertion operations, are called…

A. Formatted I/o.

B. Formatted strings.

c. Formatted flogs.

d. Formatted o/I

E. all of them.

Answer: A

2. Pick out the currect objects about the instantiation of output stream..
A. Cout
B. Cerr
C. Clog
D. Cin
E. A to c
Answer: E

4.How many groups of output of operation are there in c++…

A. 1

B. 2

c. 3

D. 4

Answer: B

5. What can be the input a string with blank space.


A. Inline
B. Getline
C. Putline
D. Setline
E. Outline
Answer: B

6.Whice is used to get the input during runtime.

A. cout

B. cin

c. coi

D. cinout

E. clog

Answer: B

7. Whice operator is used for input stream…

A. >

B. >>

C. <

D. <<

E. >^
Answer: B

8. if we have object from ofstream class , then default mode of opening the file is

A. ios:: ate

B. ios:: nocreate

c. ios:: noreplace

D. ios:: truncate

E. ios:: create

Answer: D

9. To create a output stream , we must declare the stream to be of class…

A. of stream

B. ifstream

C. iostream

D. offstream

E. Fstream

Answer: A

10. To perform File I/O operations, we must use…………… header file.

A. <iostream>

B. <ofstream>

C. <fstream>

D. <instream>

E. < offstream>

Answer: A

11. how many objects are used for input and output to a string?

A. 1

B.2
C. 3

D.4

E. 5

Answer: C

12. which from the following functions doesnot extract the delimiter character from the input stream.

A. get()

B. getline()

C. get char()

D. get string()

E. get float()

Answer: A

13. which function is used to position back from the end of file object?

A. seekg

B. seekp

c. seekf

D. seekg&seekp

E. seekm

Answer: A

14. What will be the output of the following c++ code.

Include<iostream>

Using namespace std

Int main 0

Int I;

Cout<< “Enter the number”<<endl;


Cin>> i+4;

return 0;

A. 73
B. Your value +4
C. Error
D. 63
E. 34
Answer: C

15. the iostream class defines the …

A. cin objects

B. stream extraction operator for formatted input

C. cout object

D. A and B

E. c in out objects

Answer: D

Samiya Islam

Overview of Standard Template Library (STL)


( Vector & Iterators )
Sadia Islam Brishty
1.What is the Standard Template Library ?

a)Set of C++ template classes to provide common programming data structures & functions.

B)Set of C++ classes.

c)Set of Template functions used for easy data structures implementation.

d)Set of Template data structure only.

e)

Answer:a

2. How many components STL has?

a) 1

b) 2

c) 3

d) 4

e)5

Answer: d

3.What are Iterators?

a) Iterators are used to iterate over C-like arrays

b) Iterators are used to iterate over pointers

c) Iterators are used to point memory addresses of STL containers

d) Iterators are used to iterate over functions

e)

Answer: c

4.Which header file is used for Iterators?

a) <iterator>

b) <algorithm>

c) <iter>
d) <loopItere>

e)<iostream>

Answer: a

5. How many types of Iterators are provided by C++?

a) 2

b) 3

c) 4

d) 5

e) 6

Answer: d

6. Pick the correct statement.

a) Input iterator moves sequentially forward

b) Input iterator moves sequentially backward

c) Input iterator moves in both direction

d) Input iterator moves sequentially downwards

e)

Answer: a

7. Which of the following is correct?

a) Input Iterators are used for assigning

b) Output Iterators are used for accessing

c) Output Iterators are used for assigning

d) Both Input and Output Iterators are used for accessing

e) Both Input and Output Iterators are used for assigning

Answer: c

8. What are Bi-directional iterators?


a) Iterator same as Forward Iterator

b) Forward Iterator that can be used in both directions

c) Iterator that can only be used to access the sequence from both sides

d) Iterator that can only be used to assign the sequence from both sides

e) Forward Iterator that can’t be used in both directions

Answer: b

9. What are the vectors?

a) Arrays with dynamic size

b) Arrays with different types of elements

c) Same as array classes

d) Arrays with static size but use template classes

Answer: a

10. Which of the following header file is needed to use vectors in your program?

a) <array>

b) <vector>

c) <containers>

d) <stdio>

e)<iostream>

Answer: b

11. Which of the following(s) can be used to access the first element of a vector v?

a) v.begin[0]

b) v.cbegin[ ]

c) v( )

d) v.at(0)

e) v.begin[ ]
Answer:d

12. Which of the following(s) can be used to access the last element of a vector v?

a) v.end()

b) v.cend()

c) both v.end() and v.cend()

d) vectors do not have a function to access the last element

e) V.END[ ]

Answer: d

13. Which is the following is syntactically correct for vector<int> v?

a) vector <int> :: const_iterator itr = v.rbegin();

b) vector <int> :: reverse_iterator itr = v.begin();

c) vector <int> :: iterator itr = v.begin();

d) vector <int> :: iterator itr = v.cbegin();

e) vector <int> :: iterator itr = v.cbegin[ ]

Answer: c

14. Which of the following function is used to get the actual number of elements

stored in vector?

a) v.size()

b) v.capacity()

c) v.max_size()

d) v.no_of_elements()

e) v.capacity [1]

Answer: a

15. How the size of a vector increases once it is full?

a) Vector increases its capacity one by one


b) Vector doubles its capacity after it is full

c) Vector increases its capacity by half of its previous size

d) Vector increases its capacity by a constant factor

e) Vector decreases its capacity one by one

Answer: b

Neyamul Islam

ID 0922220105101005

1. What is a thread in multi-threaded programming?

A. A sequential block of code

B. A separate process

C. A lightweight process

D. A subroutine

E. An input/output operation

Answer: C. A lightweight process

2. Which of the following is an advantage of multi-threaded programming?

A. Better utilization of system resources

B. Lower memory consumption

C. Easier debugging

D. Higher portability

E. Higher security

Answer: A. Better utilization of system resources


3. What is a critical section in multi-threaded programming?

A. A section of code that must be executed by all threads simultaneously

B. A section of code that must be executed by only one thread at a time

C. A section of code that must be executed by a specific thread

D. A section of code that is executed when a thread is terminated

E. A section of code that is executed when a thread is started

Answer: B. A section of code that must be executed by only one thread at a time

4. Which of the following is a technique to avoid race conditions in multi-threaded programming?

A. Synchronization

B. Preemption

C. Deadlock

D. Segmentation

E. Garbage collection

Answer: A. Synchronization

5. What is a thread-safe function in multi-threaded programming?

A. A function that can be executed by multiple threads simultaneously without causing race conditions

B. A function that can only be executed by one thread at a time

C. A function that is executed when a thread is terminated

D. A function that is executed when a thread is started

E. A function that is executed when a thread is waiting for input/output

Answer: A. A function that can be executed by multiple threads simultaneously without causing race
conditions

6. What is a thread pool in multi-threaded programming?

A. A group of threads that execute a specific task

B. A group of threads that execute different tasks simultaneously


C. A group of threads that execute only one task

D. A group of threads that are terminated when the program ends

E. A group of threads that execute only input/output operations

Answer: A. A group of threads that execute a specific task

7. What is a deadlock in multi-threaded programming?

A. A situation where two or more threads are waiting for each other to release a resource

B. A situation where two or more threads are executing the same critical section

C. A situation where a thread is terminated while holding a resource

D. A situation where a thread is waiting for input/output operations to complete

E. A situation where a thread is waiting for a signal from another thread

Answer: A. A situation where two or more threads are waiting for each other to release a resource

8. Which of the following is a way to prevent deadlocks in multi-threaded programming?

A. Using synchronization

B. Using preemption

C. Using segmentation

D. Using garbage collection

E. Using timeouts

Answer: E. Using timeouts

9. Which library in C++ provides support for multi-threading?

A. stdio.h

B. math.h

C. pthread.h

D. stdlib.h

E. time.h

Answer: C. pthread.h
Answer: A. A data structure used to synchronize threads

10. Which of the following best describes a thread?

A. A process that is currently executing on the CPU

B. A lightweight process that shares memory and resources with other threads

C. A unit of work that is scheduled by the operating system

D. A data structure used to store information about a process

E. A programming language construct used to define a sequence of operations

Answer: B. A lightweight process that shares memory and resources with other threads

11. What is the primary advantage of using threads in a program?

A. Increased program complexity

B. Improved program design

C. Enhanced modularity

D. Better resource utilization

E. Reduced program execution time

Answer: D. Better resource utilization

12. Which of the following is NOT a synchronization mechanism used in multi-thread programming?

A. Semaphores

B. Monitors

C. Locks

D. Mutexes

E. Context switches

Answer: E. Context switches

13. What is a race condition in multi-thread programming?

A. A condition in which two or more threads try to access a shared resource simultaneously

B. A condition in which a thread executes faster than another thread


C. A condition in which a thread becomes blocked and cannot proceed

D. A condition in which a thread deadlocks with another thread

E. A condition in which a thread exits before completing its task

Answer: A. A condition in which two or more threads try to access a shared resource simultaneously

14. What is a deadlock in multi-thread programming?

A. A condition in which two or more threads try to access a shared resource simultaneously

B. A condition in which a thread executes faster than another thread

C. A condition in which a thread becomes blocked and cannot proceed

D. A condition in which a thread deadlocks with another thread

E. A condition in which a thread exits before completing its task

Answer: D. A condition in which a thread deadlocks with another thread

15. What is thread pooling in multi-thread programming?

A. A technique that allows threads to share resources with each other

B. A technique that creates a fixed number of threads and reuses them to execute tasks

C. A technique that ensures that threads execute in a specific order

D. A technique that guarantees thread safety

E. A technique that allows threads to communicate with each other

Answer: B. A technique that creates a fixed number of threads and reuses them to execute tasks

E. Binary search tree

Answer: C. Hash table


Shimanto Kumar
Id:0622220105101023

1. What is a template function in C++?

a) A function that can be used to create multiple functions with the same code

b) A function that takes only one parameter

c) A function that can be called without any parameters

d) A function that can be used to declare variables

e) None of the above

Answer: a) A function that can be used to create multiple functions with the same code

2. What is the syntax for declaring a template function in C++?

a) template <typename T> void functionName(T parameter);

b) void functionName<T>(T parameter);

c) template <T> void functionName(T parameter);

d) void functionName(template T, T parameter);

e) None of the above

Answer: a) template <typename T> void functionName(T parameter);

3. Which of the following is an advantage of using template functions in C++?

a) They allow for code reuse

b) They improve program efficiency

c) They make programs easier to understand

d) They enable functions to accept multiple data types


e) All of the above

Answer: e) All of the above

4. What is the purpose of the typename keyword in a template function?

a) To specify the return type of the function

b) To specify the data type of the parameter

c) To specify the data type of a variable

d) To specify that a type is a template parameter

e) None of the above

Answer: d) To specify that a type is a template parameter

5. Can a template function be overloaded?

a) Yes

b) No

c) It depends on the compiler

d) It depends on the number of template parameters

e) It depends on the type of the template parameter

Answer: a) Yes

6. What is a non-type template parameter?

a) A template parameter that represents a data type

b) A template parameter that represents a function

c) A template parameter that represents a value or constant

d) A template parameter that represents a class

e) None of the above


Answer: c) A template parameter that represents a value or constant

7. Which of the following is an example of a non-type template parameter?

a) int

b) float

c) char

d) const int

e) None of the above

Answer: d) const int

8. Can a template function have both type and non-type template parameters?

a) Yes

b) No

c) It depends on the data types used

d) It depends on the number of template parameters

e) It depends on the function return type

Answer: a) Yes

9. What is the purpose of explicit instantiation in C++?

a) To allow for the creation of a template function with specific template parameters

b) To allow for the creation of a non-template function

c) To allow for the creation of a template function with no template parameters

d) To allow for the creation of a template function with a non-type template parameter

e) None of the above


Answer: a) To allow for the creation of a template function with specific template parameters

10. What is the purpose of partial template specialization in C++?

a) To create a specialized version of a template function for a specific data type

b) To create a specialized version of a template function for a specific non-type template parameter

c) To create a specialized version of a template function for a specific combination of template


parameters

d) To create a specialized version of a template function with a different return type

e) None of the above

Answer: c) To create a specialized version of a template function for a specific combination of template
parameters

11. What is a class in C++?

a) A type of data that can store multiple values

b) A way to organize data and functions into a single entity

c) A reserved word that is used to declare a variable

d) A mathematical function that performs operations on numbers

e) None of the above

Answer: b) A way to organize data and functions into a single entity

12. What is the default access specifier for members of a class in C++?

a) Public

b) Private

c) Protected

d) Static

e) None of the above


Answer: b) Private

13. What is encapsulation in the context of C++ classes?

a) The process of combining multiple classes into a single entity

b) The process of hiding the implementation details of a class from the outside world

c) The process of creating a new object from an existing object

d) The process of overriding a function in a base class

e) None of the above

Answer: b) The process of hiding the implementation details of a class from the outside world

14. What is the difference between a constructor and a destructor in C++?

a) A constructor is used to create an object, while a destructor is used to destroy an object

b) A constructor is called when an object is destroyed, while a destructor is called when an object is
created

c) A constructor is used to allocate memory for an object, while a destructor is used to deallocate
memory for an object

d) A constructor is called automatically when an object is created, while a destructor is called


automatically when an object is destroyed

e) None of the above

Answer: d) A constructor is called automatically when an object is created, while a destructor is called
automatically when an object is destroyed

15. What is the difference between a member function and a static member function in a C++ class?

a) A member function is called on an object, while a static member function is called on the class itself

b) A member function can access only public members of a class, while a static member function can
access all members of a class

c) A member function is declared with the static keyword, while a static member function is declared
without the static keyword
d) A member function can be called from outside the class, while a static member function can be called
only from within the class

e) None of the above

Answer: a) A member function is called on an object, while a static member function is called on the
class itself

You might also like