Beruflich Dokumente
Kultur Dokumente
Lipp
Exam System Design (1010/1039) / MSE
(Prüfungsleistung) WS2013/14 A (10.02.14)
Support Material UML Reference List
Remarks Please check immediately if all pages of the exam (24) + UML
reference list are available
Duration: 180min
Enter your name, Matr.-Number on the first page and sign it
Write legible! Hard to read writing will not yield any points.
Don’t use a pencil.
Keep the pages stapled together.
If you finish within the last 15min of the exam, please stay
seated to avoid disturbing your colleagues.
Name SOLUTION
Matr.-Number
Signature
PO 2006 Calculation
Mark: ________
Page 1 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
Contains virtual and non-virtual methods and usually contains common methods for
derived classes
Contains only pure virtual methods, a pure virtual constructor and destructor and often
serves as an interface specification for derived classes
To describe reactive systems, which have more than one user input and react differently
on every input.
To describe reactive systems, which have more than one operational mode and more
than one user input and depending on the mode react differently on the user input.
x
To describe reactive systems, which have more than one operational mode and
depending on the mode react differently to events.
Page 2 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
The highest possible number of functional and non-functional (C0, C1) tests
Enough testcases, to prove that the program does not contain any bugs
new is used for allocating memory for C++ objects, malloc is used for normal variables
x
new provided a typed-pointer to the allocated memory, malloc does not
new calls the default constructor when allocating dynamic memory, malloc does not
initialize the allocated memory
Page 3 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
x
o x
o
x
x
x – Waypoints
Route o – Points of Interest
Page 4 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
Page 5 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
CRoute List<CWaypoint*> (or map List allows fast insertion. Pointer due to
<string, CWaypoint*>) polymorph approach
CWpDatabase map<string, CWaypoint> Map with string for identification (fast lookup)
CPoiDatabase map<string, CPoi> Map with string for identification (fast lookup)
Page 6 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
}
else
{
cout << "WP-DB not connected or WP not found" << endl;
Page 7 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
MAXLONG). In case one of the parameters is not in the valid range, both values will be set to
0 and the corresponding exception enum wp_exception {LATTITUDEOUTOFRANGE,
LONGITUDEOUTOFRANGE} will be thrown.
Provide the code for the method and testcode, which will ensure a 100% C0 and C1 coverage of
your method. Note: In case an exception is thrown, print an error message “ERROR: Longitude out
of range” or “ERROR: Latitude out of range”. In case the assignment was ok, print “OK”;
m_name = name;
m_latitude = 0;
m_longitude = 0;
m_latitude = latitude;
m_longitude = longitude;
}
Page 8 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
//Testcases
//1 point per group (3 total)
// 2 point for correct catch
//Note: catch structure may be described as copy and paste
CWaypoint wp;
try
{
wp.set("wpwronglongitude",50,500);
cout << "Assignment ok" << endl;
}
catch (wp_exception& e)
{
switch (e)
{
case LATTITUDEOUTOFRANGE : cout << "ERROR: wrong lattitude" << endl; break;
case LONGITUDEOUTOFRANGE : cout << "ERROR: wrong longitude" << endl; break;
default: "OPPS"; break;
}
try
{
wp.set("wpwronglattitude",500,50);
cout << "Assignment ok" << endl;
}
catch (wp_exception& e)
{
switch (e)
{
case LATTITUDEOUTOFRANGE : cout << "ERROR: wrong lattitude" << endl; break;
case LONGITUDEOUTOFRANGE : cout << "ERROR: wrong longitude" << endl; break;
default: "OPPS"; break;
}
try
{
wp.set("ok",50,50);
cout << "Assignment ok" << endl;
}
Page 9 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
catch (wp_exception& e)
{
switch (e)
{
case LATTITUDEOUTOFRANGE : cout << "ERROR: wrong lattitude" << endl; break;
case LONGITUDEOUTOFRANGE : cout << "ERROR: wrong longitude" << endl; break;
default: "OPPS"; break;
}
Page 10 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
Page 11 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
Page 12 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
Page 13 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
3.2 Implementation
You are now to implement the controller for the lawn sprinkler system. There is already an
interface class for the controller and some predefined actor and sensor classes.
The sprinkler valve can be turned on and off by invoking the appropriate methods. The timer can
be started with the specified number of minutes. When the time has elapsed, the timer sends the
event “evExpired” to its associated controller. The timer can be cancelled at any time by invoking
its cancelTimer() methods. Note that invoking startTimer() when the timer already runs is
illegal and results in undefined behavior of the timer.
The lawn sprinkler system is started when the start button is pushed which results in an event
“evStart” being sent to the controller (i. e. handleEvent(“evStart”) is invoked). At any time,
the stop button can be pushed which causes “evStop” to be sent to the controller (i. e.
handleEvent(“evStop”) is invoked) which must stop the system immediately.
Page 14 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
valveOn m_valve->on()
Diagram:
Remarks:
The diagram above (being created with Together) does not use abbreviations for actions.
Page 15 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
private:
State m_state;
public:
MyController(CSprinklerValve* valve, CHumiditySensor* hSensor);
void setTimer(CTimer* timer);
};
Page 16 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
case SPRINKLING:
if (event == "evStop") {
m_valve->off();
m_timer->cancel();
m_state = OFF;
break;
}
if (event == "evExpired") {
m_valve->off();
m_timer->start(5);
m_state = PAUSING;
}
break;
case PAUSING:
if (event == "evStop") {
m_timer->cancel();
m_state = OFF;
break;
}
if (event == "evExpired") {
if (m_sensor->getValue() < 30) {
m_valve->on();
m_timer->start(15);
m_state = SPRINKLING;
break;
}
m_state = OFF;
}
break;
}
}
Page 17 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
Header:
Implementation;
Page 18 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
element
element
element
0
Physical implementation
Read Pointer
m_idxRead m_pBuffer
element
0 element
element
element
m_pBuffer
Detailled Requirements:
The constructor creates an array of the required size. The memory for the elements will
not be allocated yet. All pointers will be initialized to 0. The index values as well as the
filling level will be set to 0.
The write operation writes a data element to the next free location. If no memory for this
element has been allocated yet (i.e. first round of the buffer), the memory will be allocated
and the content of the data element will be copied by the copy constructor. If memory
Page 19 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
is present, the content will be copied by the assignment operator. The write index
and the filling level will be incremented, considering the special handling required for
position 0. The boolean return value reflects the success of the operation.
The read operation reads a value from the current read index position. The read
index will be incremented, again considering the special handling required for position 0.
The filling level will be decremented. The boolean return value reflects the
success of the operation.
The destructor deletes the memory of the elements as well as the dynamic array
holding the pointers.
//Templatisation: 5 points
//Destructor: 2 points
//Write: 8 points
Template <class T>
class CRingBuffer
{
private:
T** m_pBuffer; //Pointer to the dynamic array representing the buffer
unsigned int m_size; //Size of the ringbuffer
unsigned int m_filled; //Number of elements in the buffer
unsigned int m_idxRead; //Read index
unsigned int m_idxWrite; //Write Index
public:
CRingBuffer(unsigned int size);
~CRingBuffer();
void print();
};
m_filled = 0;
m_idxRead = 0;
m_idxWrite = 0;
{
m_pBuffer[i] = (T*)0; //cast optional
}
delete[] m_pBuffer;
}
if (m_filled > 0)
{
element = *m_pBuffer[m_idxRead++];
Page 21 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
m_idxRead %= m_size;
m_filled--;
return true;
}
else
{
return false;
}
}
Page 22 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
5 Cheat sheet
std::<container>::insert
single element
iterator insert (iterator position, const value_type& val);
(1)
This effectively increases the container size by the amount of elements inserted.
The arguments determine how many elements are inserted and to which values they are initialized:
Parameters
position
Position in the container where the new elements are inserted.
iterator is a member type, defined as a bidirectional iterator type that points to elements.
val
Value to be copied (or moved) to the inserted elements.
Member type value_type is the type of the elements in the container, defined in list as an
alias of its first template parameter (T).
n
Number of elements to insert. Each element is initialized to a copy of val.
Member type size_type is an unsigned integral type.
first, last
Iterators specifying a range of elements. Copies of the elements in the range
[first,last) are inserted at position (in the same order).
Notice that the range includes all the elements between first and last, including the element
pointed by first but not the one pointed by last.
The function template argument InputIterator shall be an input iterator type that points
to elements of a type from which value_type objects can be constructed.
il
An initializer_list object. Copies of these elements are inserted at position (in the same
order).
Page 23 / 24
System Design (1010 / 1039 MSE) Prof. P. Fromm / Prof. M. Lipp
Return value
An iterator that points to the first of the newly inserted elements.
The storage for the new elements is allocated using the container's allocator, which may throw
exceptions on failure (for the default allocator, bad_alloc is thrown if the allocation request does
not succeed).
Page 24 / 24