



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 3 574 ⌠Applied Software Engineering Midterm Examination Solutions (16 questions, 50 points) Fall 2010 Name: Student ID#: Questions 1-15: 3 points each. Use your own words in your answers. Question 1. Consider the function call graduate(&gs) in Example 6.5 of Ezust (page 141). Why is that (a) this call prints [Student] and not [GradStudent] and (b) this call does not print GradStudentâs support (Support) information? [solution] (a) getClassName() is not defined as a virtual function in the class Student. Thus, the call graduate(&gs) will invoke Studentâs getClassName(), which returns the string âStudentâ. If getClassName() was defined as virtual in class Student, then graduate(&gs) will invoke GradStudentâs getClassName(), which returns the string âGradStudentâ, as result of dynamic binding. (b) toString() is not defined as a virtual function in the class Student. Thus, the call graduate(&gs) will invoke Studentâs toString() function, which doesnât print any Support information. In contrast, GradStudentâs toString() function prints the Support information. Question 2. What is an abstract class? What is it used for? What can you do with a concrete class that you cannot do with an abstract class? [solution] An abstract class contains at least one pure virtual function, and cannot be instantiated like a concrete class. An abstract class is used to group features that are common to many classes in a design, but the class by itself doesnât have a real world physical counterpart. Question 3. For each of these items, determine whether it would normally be found in a header (.h) file or an implementation (.cpp) file and explain why. (a) function definitions [solution] implementation -Ââ they should be only compiled once, and not included by other modules that use it. (b) function declarations [solution] usually the header file, to refer to functions defined in other separate implementation files.
(c) static object declarations [solution] header files, like most declarations. (d) static object definitions [solution] implementation file, just like functions. We do not wish to have redundant storage allocation for statics. (e) class definitions [solution] these go in the header file. (f) class declarations [solution] header file -Ââ usually they are forward declarations. (g) inline function definitions [solution] header files -Ââ unlike regular functions which can be linked together, inline functions need to be fully defined before they can be used. (h) inline function declarations [solution] Header file -Ââ Rarely used for member functions except when the declaration is separated from the definition -Ââ but kept in the same header file. (i) default argument specifiers [solution] header file -Ââ default arguments to a function changes the way the function is called. This is the realm of the header file. Question 4. 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 5. What happens to a QObject when it is reparented? [solution] It is removed from its former parent's child list, and added to the new parent's child list. Question 6. Why is the copy constructor of QObject not public? [solution] To prevent it from being copied. QObjects are supposed to have identity, and so there should be no âexactâ copy. In addition, copying a QObject would mean copying all its children, a potentially expensive operation.
are added, and decremented when references are deleted. When the counter reaches zero, the handler destroys the shared object. Qt example implementations of this pattern include QList, QString, and QSet. Question 14. What is the difference between a spacer and a stretch? [solution] A spacer is a fixed amount of space that does not stretch, while a stretch starts with a certain amount of space and expands to gobble up available space. In the case of multiple stretches in the same layout, the ratio can be used to determine which stretch expands faster. Question 15. What is the Model View pattern? How is it useful? [solution] The Model View pattern is a generic solution to the problem of visually rendering a collection of data items. Instead of combing the code for storing, indexing, and accessing the data with that for visually rendering them, the pattern uses different classes for doing this. The Model class provides an interface for accessing the data and the View class visually renders that data. The pattern thus allows decoupling of the model and the view â i.e., it allows one to use different View classes (for obtaining different views) for a given model, and different Model classes (for storing and accessing data in different ways) for a given view.
Question 16. Consider the following UML diagram: Explain this diagram by identifying the different types of class relationships (i.e., which class is related to which class and how) and the multiplicities in the relationships. This design follows the model/view paradigm. Identify the model class(es) and the view class(es). [5 points] [solution] Class relationships: