4.5.  Review Questions

[ fromfile: lists-questions.xml id: lists-questions ]

  1. Name three applications in which QStringList would be useful.

  2. How can you convert a QStringList to a QString? Why might you want to do that?

  3. How can you convert a QString to a QStringList? Why might you want to do that?

  4. What is the Iterator pattern? Give three examples.

     

    An object or programming structure that provides indirect access to each element in a container, without being bound to a specific underlying type.

    Examples: STL-style iterators, Java-style Iterators, and foreach loops.

  5. Draw a UML diagram with three or more classes and make sure that all these different kinds of relationships are represented.

    • Aggregation and composition

    • One-to-One and One-to-Many

    • Unidirectional and bidirectional

    The classes should represent real-world concepts, and the relationships should attempt to represent reality. Write a couple of paragraphs explaining why there is a relationship of each kind in your diagram.

  6. What is the difference between composition and aggregation?

      In a composition relationship one object (the one closest to the filled diamond) manages the object(s) at the other end (called components). The manager has responsibility for destroying the component(s)as part of its own destruction. In an aggregate relationship, the lifetimes of the objects on either end are not related to one another.

  7. Read the API docs for QList and find three distinct ways to add elements to the list.

     

    void append ( const T & value )
    void prepend ( const T & value )
    void push_back ( const T & value )
    void push_front ( const T & value )
    QList<T> & operator<< ( const QList<T> & other )
    QList<T> & operator<< ( const T & value )
    QList<T> & operator+= ( const QList<T> & other )
    QList<T> & operator+= ( const T & value )
    

  8. List three methods that exist in QStringList but are not in QList.

     

    QString join(const QString& separator) const
    QStringList& replaceInStrings(const QRegExp& rx, const QString& after)
    void sort()
    

  9. Why does QList have an iterator and an Iterator? What is the difference between them?

  10. Discuss the advantages and disadvantages of Qt or STL container classes as compared with arrays.

  11. Discuss the syntax of the QList declaration. What should be in <angle brackets>? Why is it necessary?

  12. Why does Qt support so many different kinds of iterators?

  13. What is the difference between QFile and QFileInfo?