Test Series - cpp

Test Number 81/102

Q: In which of the following relationship objects of related classes can occur independently?
A. Aggregation
B. Association
C. Composition
D. Both Aggregation an Association
Solution: In both Aggregations and Association of objects of related classes can occur independently. For example, an employee can have a bank and a bank can have an employee. Also, Association is a superset of Aggregation, therefore, it also follows the same.
Q: In which of the following relationship objects of related classes are strongly dependent?
A. Aggregation
B. Association
C. Composition
D. Both Composition an Association
Solution: In both Composition and Association, objects of related classes are strongly dependent. For example, books will be destroyed if the library does not exist (talking about objects of classes).
Q: Composition is a __________ type of Association relationship.
A. strong
B. weak
C. unnecessary
D. necessary
Solution: Composition is a strong type of Association relationship because in this case, objects are strongly dependent on each other. For example, human and heart cannot exist without each other.
Q: Aggregation is a __________ type of Association relationship.
A. strong
B. weak
C. unnecessary
D. necessary
Solution: Aggregation is a weak type of Association relationship because in this case objects of related classes can occur independently. For example, bank and employee can occur independently.
Q: Which type of relationship is modelled by Association?
A. Is-A relationship
B. Has-A relationship
C. Part-Of relationship
D. Have-A relationship
Solution: Association models the has-a relationship between classes. Similar to aggregation, in this children can exist without a parent, therefore, they have a relationship.
Q: Which container is used to store elements as key-value pair?
A. map
B. multimap
C. unordered map
D. all of the mentioned
Solution: C++ provides these three containers(map, multimap and unordered map) to store elements as key-value pair.
Q: Which container can have the same keys?
A. map
B. multimap
C. unordered map
D. set
Solution: C++ provide multimap container that is used to make map that can contain same keys i.e. {a: 5} and {a:10} both can exist.
Q: Which container is best to keep the collection of distinct elements?
A. multimap
B. heap
C. set
D. queue
Solution: C++ provides a set container to store a collection of distinct elements. This container behaves similar to mathematical sets.
Q: Which container is used to keep priority based elements?
A. queue
B. stack
C. set
D. priority queue
Solution: C++ provides priority queue container that stores elements based on their priority. For example, if the absolute value is the priority then -6 will be kept before 4 in the priority queue.
Q: Sets are implemented using _______________________
A. binary search tree
B. red black tree
C. avl tree
D. heap
Solution: Sets are implemented using the search tree so that we can check the presence of any element to be inserted in O(logn) time in order to remove conflicts between elements.

You Have Score    /10