Beruflich Dokumente
Kultur Dokumente
Lipp
Exam System Design (1010/1039) / MSE
(Prüfungsleistung) WS2014/15 A (02.02.15)
Support Material UML Reference List
Remarks Please check immediately if all pages of the exam (21) + UML
reference list are available
Duration: 180min
Enter your name, Matr.-Number on the first page and sign it
If you finish within the last 15min of the exam, please stay
seated to avoid disturbing your colleagues.
Name
Matr.-Number
Signature
Mark: ________
Page 1 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
[3] You see a use case in a use case diagram that has no association with any of the actors…
This is not allowed.
This means that the use case is triggered by the system internally (e. g. by a timer).
[2] The difference between the keywords struct and class is…
… that struct may be used only in C
(X) … that struct is used in C to define classes while class is used in C++ to define
classes.
(X) … that struct can only be used to define classes without methods.
Some people have pointed out that it is formally possible to define a method in a struct in C++ (never seen this being
used, though), therefore either the second or third answer will be accepted.
X The device is locked after entering a wrong PIN for three times.
Page 2 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
[2] If A and B are classes and class A has an attribute of type B*, then
X … their relationship is an association, aggregation or composition
[2] Testing …
… tries to proof software correctness.
X … is not debugging.
Page 3 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
x
o x
o
x
x
x – Waypoints
Route o – Points of Interest
Page 4 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
Add all missing class relations to the class diagram below. Do not forget multiplicities and possible
dependencies.
Page 5 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
Provide the code for the following 2 functions, fulfilling the following requirements (2)
Check, if the screen is connected to a route
If yes, call the route print routine using the current screen object as parameter
void CGUIScreen::drawRoute()
{
if (m_pRoute != 0)
{
m_pRoute->print(this);
}
}
void CCRTScreen::drawRoute()
{
if (m_pRoute != 0)
{
m_pRoute->print(this);
}
}
Considering your implementation, explain the review comment. (8)
What does it mean?
What problems can you expect during the implementation?
How can the design be improved? Provide a sketch (conceptual class diagram, containing
the relevant classes, dependencies and methods).
The derived screen classes (CGUIScreen, CCRTScreen) only act a type provider, they do not
implement any real “view” functionality. Hard to implement, hard to test design due to the many
relations. Circular dependencies require forward declarations (normal includes will not work).
Improvement: Provide data of CWaypoint and CPoi via CRoute to Screen classes, implement the
drawing functionality up there.
1
Model–view–controller (MVC) is a software architectural pattern for implementing user interfaces. It divides
a given software application into three independent parts, separating the data structure (model) from the
processing (control) and presentation layer (view).
Page 6 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
You decide to implement both solutions and to use a preprocessor directive to either perform a
comparison by pointer or by value. Use the preprocessor defines below and provide the complete
and syntactically correct code.
#define BYPOINTER 1
#define BYVALUE 2
//Check content
//2
for (list<CWaypoint*>::const_iterator source=m_pRoute.begin();
source != m_pRoute.end(); ++source)
{
//1
bool elementFound = false;
//1
if (!elementFound) return false;
}
return true;
}
Page 8 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
Page 9 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
Draw a UML activity diagram that describes the normal operation from waiting for a hand close to
the sensor until the towel is ejected. Assume that the hand is removed immediately after the motor
starts. Omit the special case of empty supply. Remember that the descriptions of activities must
include a verb. Observe the formal rules for UML activity diagrams.
Start with an activity “Check hand sensor”. Another activity that you should use somewhere in your
diagram is “Wait for motor turn event”. Granularity hint: you should have about 5 activities and 2
decision points.
0.5
1 (-0.5, -0.5)
0.5
0.5
0.5
0.5
0.5
1 (-0.5, -0.5)
Page 10 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
3.2 Implementation
You are now to implement the controller for the paper towel dispenser. There is already an
interface class for the controller and some predefined actor and sensor classes.
The motor can be turned on and off by invoking the appropriate methods. The implementation of
the run() method is given as:
void CController::run()
{
while (true) {
handleEvent(m_evSrc->getEvent());
}
}
Page 11 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
Draw a state diagram for the controller. Use the event names and actions as can be derived from
the class diagram. Observe the formal rules for UML diagrams. Complexity hint: you should need
about 4 states.
1 0.5
0.5
0.5
1 1.5
0.5
0.5
1
0.5
0.5
0.5
Page 12 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
Provide your own implementation of a controller class (both class definition and method
implementations). Use the “switch(state)” pattern from the lecture (not using the pattern results in 0
points).
public:
MyController(CMotor* motor, CLed* led, 0.5
CEventSource* evtSrc, CPaperSupplySwitch* paperSw);
void handleEvent(Event event);
};
m_state = Idle;
m_cnt = 0; 0.5
}
case Eject1:
if (event == MotorTurn) { 0.5
if (m_ps->isEmpty()) {
m_motor->off(); 0.5
m_led->on();
m_state = WaitForRefill;
} else if (m_cnt < 300 && !m_ps->isEmpty()) {
m_cnt += 1; 0.5
} else {
m_motor->off(); 0.5
Page 13 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
m_state = Idle;
}
} else if (event == HandRemoved) 0.5
if (m_cnt < 150) {
m_state = Eject2; 0.5
} else {
m_motor->off();
m_state = Idle; 0.5
}
}
break;
case Eject2:
if (event == MotorTurn) { 0.5
if (m_ps->isEmpty()) {
m_motor->off(); 0.5
m_led->on();
m_state = WaitForRefill;
} else if (m_cnt < 150 && !m_ps->isEmpty()) {
m_cnt += 1; 0.5
} else {
m_motor->off(); 0.5
m_state = Idle;
}
break;
case WaitForRefill:
if (event == DispenserClosed) { 0.5
if (!m_ps->isEmpty()) {
m_led->off();
0.5
m_state = Idle;
}
}
}
Page 14 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
Your colleague points out that it would be nice to turn the motor on and off by assigning true or
false to an object of type CMotor. Provide the implementation of the required operator
overloading.
Page 15 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
Initial state:
All array elements are initialized to zero. The average value in this case is 0.
0 0 0
The Moving Average filter is implemented as a template class, taking 3 template arguments:
DATA The type of the stored data element, e.g. int, float, double…
RESULT The type of the calculated result value e.g. float in case of int elements
SIZE The number of filter stages
Page 16 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
void clear();
};
Page 17 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
//3
template <class DATA, class RESULT, unsigned int SIZE>
void CMovAvg<DATA, RESULT, SIZE>::clear()
{
m_numSamples = 0;
m_total = RESULT(0);
//1
template <class DATA, class RESULT, unsigned int SIZE>
CMovAvg<DATA, RESULT, SIZE>::CMovAvg()
{
clear();
}
Page 18 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
//1
template <class DATA, class RESULT, unsigned int SIZE>
void CMovAvg<DATA, RESULT, SIZE>::add (DATA data)
{
m_data[(m_numSamples++) % SIZE] = data;
}
//3
template <class DATA, class RESULT, unsigned int SIZE>
RESULT CMovAvg<DATA, RESULT, SIZE>::getAverage()
{
if (m_numSamples == 0) return RESULT(0);
Page 19 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
Page 20 / 21
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp
//1
template <class DATA, class RESULT, unsigned int SIZE>
RESULT CMovAvg<DATA, RESULT, SIZE>::addAndGetAverage(DATA data)
{
//3
if (m_numSamples >= SIZE)
{
//Delete oldest element, before adding new
m_total -= m_data[m_numSamples % SIZE];
}
//1
add(data);
//1
m_total += (RESULT)data;
//2
return m_total / (m_numSamples<SIZE?m_numSamples:SIZE);
Page 21 / 21