COS2614-Chapter 4: Lists
QUESTIONS AND CORRECT
ANSWERS PROVIDED
Question 1: Which of the following Qt classes is suitable for managing a list of strings?
a. QVector
b. QMap
c. QStringList
d. QMapIterator - ANSWER -c. QStringList
Question 2: What is the primary purpose of using QList in Qt?
a. To store a collection of key-value pairs
b. To manage a list of integers
c. To create a dynamic array of objects
d. To manage a list of objects with different data types - ANSWER -c. To create a
dynamic array of objects
Question 3: In Qt, which class should you inherit from if you want to create a custom list class
with additional functionality?
a. QList
b. QVector
c. QStringList
d. QListWidget - ANSWER -a. QList
Question 4: Which of the following statements is true about QListIterator in Qt?
a. QListIterator is used for directly modifying the elements of a QList.
, b. QListIterator is more efficient than a regular iterator for QList.
c. QListIterator allows both forward and backward traversal of a QList.
d. QListIterator is used for creating a copy of a QList. - ANSWER -c. QListIterator allows
both forward and backward traversal of a QList.
Question 5: What is the main purpose of QStringList in Qt?
a. To store a list of integers
b. To store a list of objects
c. To store a list of strings
d. To store a list of floating-point numbers - ANSWER -c. To store a list of strings
Question 6: In Qt, what is the key difference between QList and QVector?
a. QList is for storing objects, while QVector is for storing primitive data types.
b. QList provides faster random access than QVector.
c. QVector automatically resizes itself when elements are added or removed.
d. QList is a single-linked list, while QVector is a dynamic array. - ANSWER -d. QList is a
single-linked list, while QVector is a dynamic array.
Question 7: When drawing a UML class diagram, what does an aggregation relationship
between two classes represent?
a. Strong ownership, where the child class controls the lifetime of the parent class.
b. Weak ownership, where the parent class controls the lifetime of the child class.
c. A one-to-one relationship between classes.
d. A many-to-many relationship between classes. - ANSWER -a. Strong ownership,
where the child class controls the lifetime of the parent class.
Question 8: In a UML class diagram, how is a composition relationship between two classes
represented?
a. With a solid line and an arrow pointing to the parent class.
b. With a dashed line and an arrow pointing to the child class.
c. With a solid line and a diamond shape at the end pointing to the parent class.
QUESTIONS AND CORRECT
ANSWERS PROVIDED
Question 1: Which of the following Qt classes is suitable for managing a list of strings?
a. QVector
b. QMap
c. QStringList
d. QMapIterator - ANSWER -c. QStringList
Question 2: What is the primary purpose of using QList in Qt?
a. To store a collection of key-value pairs
b. To manage a list of integers
c. To create a dynamic array of objects
d. To manage a list of objects with different data types - ANSWER -c. To create a
dynamic array of objects
Question 3: In Qt, which class should you inherit from if you want to create a custom list class
with additional functionality?
a. QList
b. QVector
c. QStringList
d. QListWidget - ANSWER -a. QList
Question 4: Which of the following statements is true about QListIterator in Qt?
a. QListIterator is used for directly modifying the elements of a QList.
, b. QListIterator is more efficient than a regular iterator for QList.
c. QListIterator allows both forward and backward traversal of a QList.
d. QListIterator is used for creating a copy of a QList. - ANSWER -c. QListIterator allows
both forward and backward traversal of a QList.
Question 5: What is the main purpose of QStringList in Qt?
a. To store a list of integers
b. To store a list of objects
c. To store a list of strings
d. To store a list of floating-point numbers - ANSWER -c. To store a list of strings
Question 6: In Qt, what is the key difference between QList and QVector?
a. QList is for storing objects, while QVector is for storing primitive data types.
b. QList provides faster random access than QVector.
c. QVector automatically resizes itself when elements are added or removed.
d. QList is a single-linked list, while QVector is a dynamic array. - ANSWER -d. QList is a
single-linked list, while QVector is a dynamic array.
Question 7: When drawing a UML class diagram, what does an aggregation relationship
between two classes represent?
a. Strong ownership, where the child class controls the lifetime of the parent class.
b. Weak ownership, where the parent class controls the lifetime of the child class.
c. A one-to-one relationship between classes.
d. A many-to-many relationship between classes. - ANSWER -a. Strong ownership,
where the child class controls the lifetime of the parent class.
Question 8: In a UML class diagram, how is a composition relationship between two classes
represented?
a. With a solid line and an arrow pointing to the parent class.
b. With a dashed line and an arrow pointing to the child class.
c. With a solid line and a diamond shape at the end pointing to the parent class.