Welcome! Log In Create A New Profile

Advanced

Notes & Review questions from the book + answers

Posted by Rey 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
avatar
Rey
Notes & Review questions from the book + answers
November 17, 2009 10:14AM
Hi

These are my notes.
1st they were done last year (didn't manage to write the exam), I may have used notes from someone else as a base.
2nd I take no responsibility for their accuracy.
3rd If you make any changes please post them here so that I can add them, and everyone else can benefit.
4th Leave a note if you feel they are good/bad, just so that I know I'm not leading everyone down the garden path.

PDF (For people without OO)
http://rapidshare.com/files/308186341/cos.v1.pdf
http://go.greenlight.co.za/wp-content/uploads/2009/11/cosv1.pdf (Only for people having trouble with Rapidshare, PLEASE)

OpenOffice (So that you can make changes)
http://rapidshare.com/files/308187968/cos.v1.odt
http://go.greenlight.co.za/wp-content/uploads/2009/11/cosv1.odt (Only for people having trouble with Rapidshare, PLEASE)

Notes from ShaunGVW
http://go.greenlight.co.za/wp-content/uploads/2009/11/qt_cppnotes.doc Qt and C++ Notes
http://go.greenlight.co.za/wp-content/uploads/2009/11/design_patterns.doc Design Patterns


I'm looking for notes on INF320 for the current edition of the book. Anyone got? email me rey (at) xhuma (dot) co (dot) za


Some review questions from http://cartan.cas.suffolk.edu/oopdocbook/opensource/main.html .From the book.
As for the Exam 2008 thread from Shawn. If I get time during the week I'll make some answers. Please feel free to PM me or add answers to the thread.

Chapter 3:
1.What is a project file? How can you produce one for your project?
2.What does the TEMPLATE variable mean in the qmake project file? What are possible values?
3.What is a Makefile? How can you produce a Makefile for your project?

Chapter 7:
1.For each of these items, decide whether it would normally be found in a header (.h) file or an implementation (.cpp) file and explain why.
1.function definitions
2.function declarations
3.static object declarations
4.static object definitions
5.class definitions
6.class declarations
7.inline function definitions
8.inline function declarations
9.default argument specifiers
2. What is the difference between a compile time dependency and a link time dependency?

Chapter 8:
1.What is a design pattern? What do most design patterns have in common?
2.What Qt classes use the Visitor pattern? Explain why.
3.Why does the FileVisitor need to be recursive?
4.There are three kinds of design patterns: structural, creational, and behavioral. Which kind is the Visitor? Why?

1. Are efficient and elegant solutions to common problems in object-oriented software design. They are high-level abstract templates that can be applied to particular kinds of design problems.
2. QDir and QFileInfo
3. As it needs to search directories recursively till it finds all files
4. Behavioral - Why?

Chapter 9:
1.What does it mean when QObject A is the parent of QObject B?
2.Which QObjects do not need a parent?
3.What happens to a QObject when it is reparented?
4.Why is the copy constructor of QObject not public?
5.What is the composite pattern?
6.How can QObject be both composite and component?
7.How can you access the children of a QObject?
8.What is an event loop? How is it initiated?
9.What is a signal? How do you call one?
10.What is a slot? How do you call one?
11.How are signals and slots connected?
12.In the case where multiple signals are connected to the same slot, how can you determine the QObject that emitted the signal?
13.How can information be transmitted from one object to another?
14.Deriving a class from QObject more than once can cause problems. How might that happen accidentally?
15.What is the difference between value types and object types? Give examples.

1. QObject B is contained or managed at run-time by QObject A.
2.
3. It is relinked to a different parent.
4. As all QObject are unique and must stay that way.
5. According to [Gamma95], the composite pattern is intended to facilitate building complex (composite) objects from simpler (component) parts by representing the part-whole hierarchies as tree-like structures
6.
7. QObject has a function called findChildren()
8. An event loop is a program structure that permits events to be prioritized, enqueued, and dispatched to objects. (QApplication).exec()
9. A signal is a message that is presented in a class definition like void function declaration. It has a parameter list but no function body. It must be emitted, and can't be called. It's part of the class interface.
10. A Slot is a void member function. It can be called as normal.
11. QObject::connect(quitButton, SIGNAL(clicked()),qApp, SLOT(quite()))
12. They are queued or executed in an asynchronous way, depending on the optional Qt::ConnectionType passed to connect()
13. Through the argument list of the signals and slots.
14. By not wrapping the header in a "#ifndef"
15. Value types are simple "Anything*, int, char, QString, QDate, and QVariant. Object types are more complex i.e QObject

Chapter 10:
1.Explain an important difference between a template parameter and a function parameter.
2.What does it mean to instantiate a template function? Describe one way to do this.
3.Normally, you need to place template definitions in header files. Why is this?
4.Some compilers support export. What is it for?
5.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?
6.Which containers provide a mappings from key to value? List and describe at least two, and tell how they are different from each other.
7.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”?
8.Give at least 3 examples of Qt classes that implement the Flyweight pattern.

1. A Template parameter differs from a function parameter in that it can be used to pass not only variables and values, but also type expressions
2. Each time the compiler see a template used for the FIRST time it is instantiated and all further calls are may into ordinary function calls
3. This is necessary for the compiler to generated code from a template declaration
4.
5. Heap Object so as to avoid memory leaks as value containers don't manage their objects
6. QMap, QHash,QMultiMap, QCache, QSet Page (220)
7. Managed heap objects are destroyed by it's parent Object when it's that Object is destroyed
8.

Chapter 11:
1.List six things that QWidgets have in common.
2.How can you save and later restore the size, position, and arrangements of widgets for a GUI app?
3.Why would you want to do such a thing?
4.What is a dialog? Where is an appropriate place to use it?
5.What is a QLayout? What is its purpose? What is an example of a concrete QLayout class?
6.Can a widget be a child of a layout?
7.Can a layout be a child of a widget?
8.What are the advantages of listing our images in a resources file?
9.What is the difference between a spacer and a stretch?
10.What is a QAction? How are actions triggered?
11.It is possible to create QMenus without using QActions. What are the advantages of using a QAction?
12.Which Qt classes use the Command pattern?

1.
2. The class QSettings can be used
3. To save the application settings across executions
4. Is a pop up box that can be used to get a user response and should only be used for obtaining and communicating important information
5. QLayout is a and abstract class. To organize the space occupied by widgets. QBoxLayout
6. Yes
7. Yes
8. They can be addressed using paths that do not depend on the local file system, and the can "move" with the executable. Also making the project more robust.
9. Spacer is a fixed size, Stretcher can size itself as requested
10. A QAction is a QObject that is a base class for user-selected actions. Clicks on a menu, short-cut key or clicks on a toolbar.
11.
12.

Chapter 12:
1.What are two important differences between a process and a thread?
2.List and explain at least two mechanisms by which a parent process communicates information to its child process.
3.List and explain at least two mechanisms by which threads synchronize with each other.
4.In what situations can a QTimer be used instead of a QThread? Why would one want to do that?
5.What does it mean for an object to be thread-safe?

1. Process runs in a separate memory space, communicate with streams and is managed by the OS. Threads share memory with other threads and are managed by the Parent process.
2. stdout and stderr. setReadChannel() and readyReadStandardOutput() is emitted. read(), readLine(),getChar() and write().
Enviroment variables. QProcess::enviroment()
3. Synchronize using locks, wait conditions, mutexes, semaphores
4. When a simple repetitive task needs to be completed, such as a simple animation.
5. When an object is one that can be accessed concurrently by multiple threads and is guaranteed to always be in a "valid" state

Chapter 13:
1.What is a regular expression? What can you use it for?
2.What is a validator? What is it used for?
3.What is a regular expression meta-character? There are four kinds of metacharacters - quantifier, character set, group, and anchor. Give examples of each type and explain what they mean.

1. Are used for validating input, for extracting data from input, and for searching and replacing
2. Validators are non-visual objects that are attached to input widgets to provide a general framework for checking user input.
3. A meta-character is a character that describes other characters. Quantifier - +, ?, * Character Set - \s , \S, \d, \D Group - [1..9] Anchor - ^, $

Chapter 14:
1.If there is a syntax error in your XML file, how do you determine the cause and location?
2.SAX is an event-driven parser. What kinds of events does it respond to?
3.Qt (as well as other language frameworks) offers two XML parser APIs, one is SAX and the other is DOM. Compare and contrast them. Why would you use one rather than the other?
4.If you have a QDomNode and it is actually “pointing” to a QDomElement, how do you get a reference to the QDomElement?
5.Explain how DomWalker is an application of the Visitor pattern.

1.
2. It responds when it encounters various elements of the XML file during parsing. Start, End of document and tags and characters
3. DOM requires the entire document to be loaded into memory. SAX process data while parsing the file.
4. "Downcast" from QDomNode to QDomElement
5. As it traverses the XML tree and has an overridden visit() function that transforms each node.

Chapter 15:
1.What is an anti-pattern? Give two examples.
2.How do you determine the number of properties defined in a QObject?
3.What Qt classes are used to do data reflection? Explain why.
4.How does the QMetaObject code for each of your QObject-derived classes get generated?
5.What is a downcast? In what situations do we use them?
6.What is the Prototype pattern? Describe an example of it.
7.What are the advantages of defining properties over regular getters and setters?
8.What does the property() function return? How do we obtain the actual stored value?

1. A common design pitfall. Copy and paste, Hard Coding, Interface Bloat, Re-inventing the wheel, and God Object.
2. methodCount()
3. QMetaObject, QMetaProperty
4. moc generates it
5. In situations where you have base class pointers to derived class objects, down-casting makes it possible to call derived class methods that do not exist in the base class interface
6.
7.
8. Returns the value of the object's named property. QVariant QObject::property ( const char * name )

Chapter 16:
1.How can a creational pattern help manage object destruction?
2.How can properties help us write a more general-purpose Writer?
3.How can an Abstract Factory help us write a more general-purpose Reader?
4.What is auto_ptr used for?
5.What is special about assignment between auto_ptr objects?
6.We can create a FormModel class in a number of ways. One approach is to create Question objects directly and add them. Another way is to create a FormModel from a DataObject. Why would we use one technique instead of the other?
7.What Qt classes are implementations of the Façade pattern? Explain why they are facades or wrappers.

1. Any object created by or child of another object is destroyed when it's parent is destroyed.
2.
3.
4. Pointer memory management
5. The assigning pointer becomes NULL and the assigned pointer takes on the new value. i.e. Only one auto_ptr will ever point to an Object
6.
7.

Chapter 17:
1.What is controller code? Which Qt classes are controller classes?
2.What pattern(s) is/are used in the design of InputField?
3.Because there is a 1:1 correspondence between InputField and Question, we could easily combine the two classes into one. What would you call that class? Explain the advantages or disadvantages of this design.
4.Why is it recommended to use the QStandardItemModel instead of the QTreeWidgetItem?
5.How do you determine what item(s) is/are selected in a QListView?
6.If we wanted to iterate through items in an QAbstractItemModel, what would be a good class to use?
7.There are two distinct model-view class pairs for storing and displaying tree-like data. What are they called? Why would you use one versus the other?

1. Controller code is code that manages the interactions among events, models, and views. QApplication, QAction
2.
3.
4.
5.
6.
7. QAbstractItemModel,QTreeView and QTreeWidgetItem, QTreeWidget


----
"Flying is learning how to throw yourself at the ground and miss." - Douglas Adams
"Time is a great teacher, but unfortunately it kills all its pupils ..." - Louis Hector Berlioz
I think animal testing is a terrible idea; they get all nervous and give the wrong answers.
Re: My Notes
November 17, 2009 02:03PM
Thanks for the notes, at a quick glance they look like a comprehensive summary.

Duncan
avatar
Rey
Re: My Notes
November 17, 2009 03:12PM
--Moved to Top --

----
"Flying is learning how to throw yourself at the ground and miss." - Douglas Adams
"Time is a great teacher, but unfortunately it kills all its pupils ..." - Louis Hector Berlioz
I think animal testing is a terrible idea; they get all nervous and give the wrong answers.
Re: My Notes
November 17, 2009 03:22PM
I also have some notes if anyone wants them, I'll have to email it though to whoever.
avatar Re: My Notes
November 17, 2009 04:29PM
Please could you explain your notes on Chapter 8: Specifically where you say one of the main disadvantages of the visitor patter breaks encapsulation. I would say that it strengthens it. Not only that, but a properly designed visitor class (eg using two classes communicating via signals and slots instead of deriving from a base class) would be a good thing since it aids in decoupling classes.
avatar
Rey
Re: My Notes
November 17, 2009 05:11PM
Breaking encapsulation: Visitor's approach assumes that the Concrete Objects interface is powerful
enough to let visitors do their job. As a result, the pattern often forces you to provide public operations
that access an element's internal state, which may compromise its encapsulation.

So visiting code is say your iterator pattern for child objects in a GUI. Each Object is visited and an operation performed like getMemoryAddress(QObject * child) (or anything else the programmer originally encapsulated). Does the "child" object know this information and should it (Should there be a method to retrieve all information about an object, just in case it's acted upon by a visitor pattern)? So forcing the visited object to open up it's internal information to the world.

Another online argument may help http://www.sapphiresteel.com/What-Is-Encapsulation-and-does-it , follow the links and search for visitor.

----
"Flying is learning how to throw yourself at the ground and miss." - Douglas Adams
"Time is a great teacher, but unfortunately it kills all its pupils ..." - Louis Hector Berlioz
I think animal testing is a terrible idea; they get all nervous and give the wrong answers.
avatar
Rey
Re: Notes & Review questions from the book + answers
November 18, 2009 09:52PM
---

----
"Flying is learning how to throw yourself at the ground and miss." - Douglas Adams
"Time is a great teacher, but unfortunately it kills all its pupils ..." - Louis Hector Berlioz
I think animal testing is a terrible idea; they get all nervous and give the wrong answers.
Anonymous User
Re: Notes & Review questions from the book + answers
November 19, 2009 10:13AM
Please post! it might help the clueless like me.
Anonymous User
Re: Notes & Review questions from the book + answers
November 22, 2009 10:17AM
Difference between reference type and value type:

Reference types are stored on the run-time heap; they may only be accessed through a reference to that storage. This allows the garbage collector to track outstanding references to a particular instance and free the instance when no references remain. A variable of reference type always contains a reference to a value of that type or a null reference. A null reference refers to nothing; it is invalid to do anything with a null reference except assign it. Assignment to a variable of a reference type creates a copy of the reference, not a copy of the value being referenced.
Value types are stored directly on the stack, either within an array or within another type. When the location containing a value type instance is destroyed, the value type instance is also destroyed. Value types are always accessed directly; it is not possible to create a reference to a value type. Prohibiting such a reference makes it impossible to refer to a value class instance that has been destroyed. A variable of a value type always contains a value of that type. Unlike reference types, the value of a value type cannot be a null reference, nor can it reference an object of a more derived type. Assignment to a variable of a value type creates a copy of the value being assigned.

eg: http://www.dotnetspider.com/resources/4468-Difference-between-value-type-reference-type.aspx
Anonymous User
Re: Notes & Review questions from the book + answers
November 22, 2009 10:31AM
Ch 14:
4.If you have a QDomNode and it is actually “pointing” to a QDomElement, how do you get a reference to the QDomElement?

QDomNode n = root.firstChild();
QDomElement e = n.toElement();
avatar Re: Notes & Review questions from the book + answers
November 22, 2009 05:27PM
Rick Wrote:
-------------------------------------------------------
> Difference between reference type and value type:
>
> Reference types are stored on the run-time heap;
> they may only be accessed through a reference to
> that storage. This allows the garbage collector to
> track outstanding references to a particular
...

Careful, c++ does not have garbage colection. Also, this is rather specific to .Net and should not be directly transferred to c++.
Have a look at p 366. and chapter 1.

Cobus Neethling
Anonymous User
Re: Notes & Review questions from the book + answers
November 22, 2009 09:08PM
yeah, it was just supposed to clarify the answer he gave for reference/variable type. A nice explanation (even though there is no gc)
avatar Re: Notes & Review questions from the book + answers
November 23, 2009 11:45AM
It is so much simpler isn't it? Would have loved to do this subject in .Net!

Cobus Neethling
Anonymous User
Re: Notes & Review questions from the book + answers
November 23, 2009 11:52AM
I always say, if one can't explain it simply, then one doesn't understand it fully winking smiley
.net ... eeewww tongue sticking out smiley
Sorry, only registered users may post in this forum.

Click here to login