


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



ECE 3574 ♦ Applied Software Engineering Midterm Examination (19 questions, 50 points) Fall 2008 Name: Student ID#: Questions 115: 2 points each. Question 1. For overloading arithmetic symbols (+ - * /) on Fraction objects (see Example 2.14; page 65, Ezust), which is better, member functions or non-member global operators? [solution] Non-member global operators are preferred because then the first or second operand can be converted just easily to a Fraction. As a member function, only the right hand side is convertible, which means the operator won't work in a symmetric way. Question 2. Which member functions cannot be inherited from the base class? Explain why. [solution] The constructors, destructors, copy and assignment operators are all not inherited. They get generated for classes depending on certain rules, and the generated versions call base class versions. Question 3. What is a design pattern? What do most design patterns have in common? [solution] Most design patterns describe how to separate code by responsibility. They have a name, a description, and describe a problem (anti-pattern) that it attempts to solve. Question 4. There are three kinds of design patterns: structural, creational, and behavioral. Which kind is the Visitor pattern? Why? [solution] Behavioral - it describes how code is organized, and assigns the responsibility of visiting objects to a specific class. Question 5. Why does the FileVisitor need to be recursive? [solution] Because hierarchical directory structures are recursive data structures. Question 6. What does it mean when QObject A is the parent of QObject B? [solution] B is managed by A, and B will be destroyed when A is. Question 7. How can QObject be both composite and component?
[solution] When it has both parents and children. Question 8. Qt's container classes are used to collect value types. What kinds of things are not appropriate to store by value in a value collection? [solution] QObjects, polymorphic collections in general, and any class that cannot be copied because it has no copy constructor. Question 9. Which containers provide a mappings from key to value? List and describe at least two, and tell how they are different from each other. [solution] QMap and QHash. QMap maintains its values sorted by keys, where QHash does not. Also, QHash provides much faster value look- ups than QMap. Question 10. What is a QLayout? What is its purpose? What is an example of a concrete QLayout class? [solution] A QLayout is a class whose sole purpose it is to arrange other QWidgets or sub-layouts. It has no visual representation itself. There are Boxes, Grids and Stacks. Question 11. QWidget is derived from QObject and QPaintDevices. What does this multiple inheritance allow QWidget –derived classes to do? [solution] They are QObjects, so they can have parents, children, properties, signals, and slots. They are QPaintDevices, so they have a height, width, depth, and can be painted on the screen. Question 12. What is a QAction? How are actions triggered? [solution] A QAction is an object representing something that the user can do to the program. It can be triggered through menu items, button clicking, keyboard presses, etc. Question 13. It is possible to create QMenus without using QActions. What are the advantages of using a QAction? [solution] By creating a unique QAction for each action, you can add it to different menus and toolbars, and from one place, disable/enable it, or change other properties (such as its label or tooltip) and it will reflect in all views (menu-items, toolbar buttons, etc) that refer to it. Question 14. What does it mean for a container to “manage” its heap objects? How can a container of pointers to heap objects become a “managed container”?
an input widget such as a QLineEdit. Retrieve each of the QString from the container (using an iterator pattern with keys(), values(), etc.), insert it into a QLineEdit (using insert() or setText()), and add the QLineEdit as a widget to the QVBoxLayout (note that QLineEdit is a QWidget). This will display each of the QStrings in the displayed window. Connect the textChanged() signal of QLineEdit to a slot, which will insert the signal’s returned QString parameter into the container class. (textChanged() signal is emitted whenever the text changes and the user-entered text is returned as the signal’s parameter.) Connect the “insert” QPushButton’s clicked() signal to the slot addItem() as before. But this slot will now create the QString “item #...”, insert it into a QLineEdit, and add the QLineEdit as a widget to the QVBoxLayout. It will also add the QString to the container class. Question 18. What is the difference between aggregation and composition relationships? [3 points] [solution] In an aggregate relationship, the lifetimes of the objects on either end are not related to each other. In contrast, in a composition relationship, the “whole” object is responsible for the lifetime of the “part” object. Question 19. Draw a UML diagram with three or more classes, different from all the examples given in Ezust, and make sure that all of these different kinds of relationships are represented: aggregation composition one-to-one and one-to-many unidirectional The classes should represent real-world concepts, and the relationships should attempt to represent reality. Justify why there is a relationship of each kind in your diagram. [8 points]