COS3711 2022 JanFeb Question Paper
COS3711 2022 JanFeb Question Paper
January/February 2022
COS3711
Advanced Programming
80 Marks
Duration 2 Hours
EXAMINERS:
FIRST: DR CL PILKINGTON
SECOND: MR K HALLAND
EXTERNAL: DR L MARSHALL (UNIVERSITY OF PRETORIA)
[TURN OVER]
2 COS3711
January/February 2022
Transporting cargo around the world is essential in ensuring that customers have access to the
goods they need and want.
All such items are packaged in some sort of container (which, for the purposes of this scenario,
has some volume). Generally, there are two kinds of containers: (i) a box (where we want to
know whether it is cube shaped or not), and (ii) a cylinder (where we want to know its diameter).
For transport, containers are packed onto pallets, and pallets are then included in a load (where
each load will have a code).
1.1 Considering the scenario given above, draw a partial UML class diagram that captures
the scenario. You should include the necessary classes, class attributes, and class
relationships that are mentioned in the scenario. You do not have to include the
Client/GUI class nor indicate constructors, access specifiers, or other methods in the
classes you specify.
[You may use a software tool to create the UML class diagram.] (14)
1.2 Would you use aggregation or composition relationships in the design of this UML class
diagram? Explain why you have or have not done so. (2)
The intention is to serialise container objects using reflective programming approaches. The
idea is to convert all object data in a load to XML and save this data on a network store.
2.1 What is the major benefit of using a reflective approach in this scenario? (2)
2.2 For a container object that is urgent, the users want to add a property to just this specific
object. In such cases, the property name is urgent and its value is a message indicating
its priority (such as high priority). Assuming that the classes are set up to allow this
ability, write the code to implement this intention for an object named obj.
[Note that this approach can be used to add other optional properties to other objects
where necessary.] (2)
2.3 Consider the requirement to serialise the load class to and from XML.
2.3.1 The following UML class diagram for the serialisation has been provided (where the
QString is the XML text) for some Load class.
[TURN OVER]
3 COS3711
January/February 2022
It has been argued that this is incorrect. Provide a better UML class diagram. (3)
2.3.2 The following partial class definition has been provided to achieve the write part of the
serialisation using DOM to write to XML.
class XmlHandler
{
public:
XmlHandler();
QString writeXml(Load load);
private:
QDomDocument doc;
};
The intension is to provide the following XML code. Comments on the right are for
explanatory purposes.
[TURN OVER]
4 COS3711
January/February 2022
Using the partial code below for the function that generates this XML text, complete the
code by filling in the parts indicated. You may copy this code into your answer document
and type in the necessary code.
[TURN OVER]
5 COS3711
January/February 2022
2.4 We come now to the part where this XML text is to be sent over a network.
2.4.1 The following partial class definition is provided for the class that will be used to send the
data over the network.
class Serialize
{
public:
explicit Serialize(Load l); // load object passed to constructor
void doSerialize(); // used to transfer over the network
private:
Load load;
};
Extend this class definition so that the class can be run as a thread, including all code
that would be added to conform to best practice. (3)
2.4.2 Complete the following code (that you would expect to find in the client code) that will
run an instance of this class as a thread. The code should start the thread and clean up
afterwards.
Load load;
Serialize* s(new Serialize(load)); (6)
2.4.3 Finally, write the code for the Serialize::doSerialize() function that gets the XML
text serialisation using the XmlHandler class in 2.3.2 (repeated below) and uses UDP
to send it over the network using port 55555.
class XmlHandler
{
public:
XmlHandler();
QString writeXml(Load load);
private:
QDomDocument doc;
}; (6)
[TURN OVER]
6 COS3711
January/February 2022
A model-view approach will be used to display a list of load codes. The following class has been
proposed (which allows for the use of a memento of instances of the class).
3.1 Given the following code, write the statement that would be used to add the load
instance’s code to the list widget.
MyListMemento* MyListWidget::createMemento()
{
MyListMemento *mlm(new MyListMemento);
QStringList strlist;
for(int i=0; i<this->count(); i++)
{
strlist.append(item(i)->text());
}
mlm->setState(strlist);
return mlm;
}
Provide the class definition (that would be expected in the header file) for the
MyListMemento class. (6)
3.3 Distinguish between the use of the serialiser and memento design patterns as they have
been used in this scenario. How do they differ in terms of their ultimate purpose (apart
from the fact that the design patterns are being applied to different objects)? Make sure
that it is clear which pattern you are referring to in your answer. (4)
3.4 What model/view alternatives does Qt provide that could best be used in place of the
QListWidget? (2)
3.5 Where in the scenario presented in this paper could a factory method design pattern be
appropriately used? (2)
©
UNISA 2022