Sie sind auf Seite 1von 25

System Design (1010/1039) / MSE Prof. P. Fromm / Prof. M.

Lipp
Exam System Design (1010/1039) / MSE
(Prüfungsleistung) WS2013/14 B (27.03.14)
Support Material • UML Reference List

Remarks • Please check immediately if all pages of the exam (25) + 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. Exams that aren't stapled
will not be accepted!
• If you finish within the last 15min of the exam, please stay
seated to avoid disturbing your colleagues.

Name

Matr.-Number

Signature

Max. Points Achieved Points


1. Knowledge Corner 15
2. Extending the Navi System 35
3. Train Booking system 30
4. Template Class 20

Total Points Exam 100


Additional Points from Lab 18
Total 118

Mark: ________

Page 1 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

1 Knowledge Corner (15)


For the following questions, only one answer is right or the best answer. Marking:
Best answer: + points
No answer: 0 points
Wrong answer: - points

[2] If a class has a destructor…


... it usually doesn't need an assignment operator

... it never needs an assignment operator but always a copy constructor

... it usually also needs a copy constructor and an assignment operator

[3] Static member variables…


... may not be returned by reference

... keep their state after the destructor has been invoked

... are allocated on the stack

[2] Inheritance relationships …


... are bidirectional relationships between two classes

... are unidirectional relationships between classes and objects

... can form a hierarchy

Page 2 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

[2] Methods of derived classes can ...


... access the private and protected attributes of their base classes

... access the private and public attributes of their base classes

... access the protected and public attributes of their base classes

[2] Overriding a method of a base class …


... is only possible when using static polymorphism

... is only possible when using dynamic polymorphism

... may have no effect when using static polymorphism

[2] The keyword throw …


... requires a parameter

... may only be used in a try ... catch block

... can be used without parameter in a catch block

[2] Testing …
... is only important after the implementation has been finished

... must be considered from the beginning of the project

... should not require more than 25% of the total project effort

Page 3 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

2 Extending the navigation system (35)


In the lab we have designed a rather inelegant implementation of a route, by providing different
containers for the waypoints and the points of interest of the route. A better implementation would
be the following polymorph design:
- All waypoints and POI’s are stored in separate databases
- The route itself is stored in a single common container, which contains both the waypoints
and the POI’s in the order the driver would reach them (sketch below).

x
o x

o
x
x
x – Waypoints
Route o – Points of Interest

The design for this concept is already implemented in the class diagramm below.
In this exercise, we want to extend a functionality TripDatabase, which tracks a trip and stores it in
a database.

2.1 Class relations (10)


Add all class relations for the class CTrip to the diagram below, fulfilling the following requirements:
• The current position is measured using the GPS sensor and stored in a attribute (STL
container)
• After finishing the trip, it can be stored in another attribute, containing all previous trips (i.e.
database of all trips)
• As a special feature, one of the recorded trips can be analyzed to check which POI’s have
been close to it. This is done by comparing the distance between every recorded trip
waypoint with the positions of all POI’s in the POI database. The found POI’s will be
printed.
Additional hints:
• Do not forget the multiplicities.
• Not all attributes are displayed!
• Dependencies have also to be shown if local object will be used in the implementation file
• Relations between wrong classes will lead to negative points!

Page 4 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

Page 5 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

2.2 CTrip Attributes (5)


Provide the attributes (code) for the class CTrip fulfilling the following requirements:
• The position will be measured using the GPS object (Note: there is only one GPS object in
the system)
• The measured position is stored in a STL container (choose an appropriate one for the
given requirements)
• Once a trip is finished, all recorded positions are stored in the trip database. Every trip is
identified by its name
• The trip object obviously has to address the POI database

class CTrip {
private:

public:

CTrip();

void connectToGpsAndPoiDatabase(CGPSSensor* gps, CPoiDatabase* poidb);

bool storeGpsInTrip();

void storeTripInDatabase(string nameTrip);

void showAllPoiInTrip(string nameTrip);

};

Page 6 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

Explain your choice for the selected STL containers!

2.3 Activity diagram bool CTrip::storeGpsInTrip() (5)


Draw an activity diagram describing the following functionality:
• The current position is measured using the GPS sensor
• This position is compared to the previously stored position. If the distance is bigger than a
given epsilon value DELTATWOPOS, the position is considered to have changed (i.e. the
navigation system is moving) and the new position is stored in the current trip attribute,
defined in the previous exercise. In this case, the function returns true.
• If the distance if below the epsilon value, the navigation system is considered not to move.
In this case, the record will not be stored.
• If the system did not move for two subsequent calls, the trip is considered to have finished
and the function returns false.
• In all other cases, the function returns true.

Page 7 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

2.4 Implementation bool CTrip::storeGpsInTrip() (10)


Provide the code for the function storeGpsInTrip(). Use proper C++ Syntax!

Page 8 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

2.5 State Diagram (5)


Draw the state diagram describing the moving / standstill logic of the trip function.
• The System will start in the state Standby.
• It will be activated by firing the event ev_start.
• Once started, the system will move into the state Measuring.
• Every time, the GPS sensor provides new data, the system will fire the event ev_newData
• In case the distance to the last position is big enough (checked by the guard
g_distanceOK(), the position is stored using the function storeData()
• If the distance is not big enough, the system will move into the state NotMoving
• In case the next GPS value has a big enough distance from the last position, the system
will change into the Measuring state again.
• Otherwise the system will terminate and go back to the Standby state.
Note: Only use the states, events, guards, actions mentioned in the text. Make sure to use the
correct syntax for state diagrams.

Page 9 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

Page 10 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

3 Train Booking System (30)


A railway company owns quite a lot of wagons (identified by a unique id) that it uses to assemble
trains. The information about the wagons is kept in an inventory database. The information about
the assembled trains is kept in an operations database. Each train has an identifier. The identifier
is used to reference trains in the time schedule. The time schedule consists of routes (train's initial
start city, train's final target city, intermediate stops, arrival and departure times and id of train
serving the route). Customers can book seats on trains. Booked seats are identified by the train id,
the wagon id and the seat number. The information about the customers and their bookings is also
kept in the operational database.

3.1 Class relations (5)


Add all class relations to the diagram below. Provide as much information as possible. Note: Not all
attributes are displayed!

Page 11 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

3.2 Implementing a relationship (11)


The relationship between CBooking and CBookedSeat (hint: it is either an aggregation or a
composition) is implemented using a dynamic array (i. e. not using STL containers).

3.2.1 Class definition (3)


Provide the class definition of CBooking. Provide only the attributes required for implementing the
relationship with CBookedSeat. Provide declarations for a constructor that takes the maximum
number of seats associated with the booking, a copy constructor, a destructor, an assignment
operator and a method that adds a booked seat to the booking. The method that adds a booking
returns true if the seat could successfully be added or false if not (because the maximum
number of seats has been reached). Use proper C++ Syntax!

Page 12 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

3.2.2 Method implementations (8)


Provide implementations for the methods declared in your class definition. Use proper C++ Syntax!

Page 13 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

Page 14 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

3.3 Booking Algorithms (14)


We shall now focus on handling some booking requests. A modern train wagon of “Deutsche
Bahn” uses the following numbering scheme for seats.

5 7 13 15
6 8 14 16

2 4 10 12
1 3 9 11

This scheme has some interesting properties. An interesting property is that all seats with odd
numbers are windows seats and seats with even numbers are aisle seats.
For this exercise we use a simplified class CWagon as shown in this UML diagram.

The attribute m_booked is an array of bools dynamically allocated by the constructor. It contains
as many bools as there are seats in the wagon. A value of true in the array indicates that the
corresponding seat is booked, a value of false indicates that it is free. Note that while seat
numbers start with 1 when used as parameters or return values (i. e. at the class interface), the
first element in the array (corresponding to seat 1) has index 0, of course.

3.3.1 Booking a single seat (6)


The method findSeat searches for a single free seat with a given property. If one is found, its
number is returned, else -1 is returned. The code implementing this method is given on the next
page.

Page 15 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

int CWagon::findSeat(SeatType type)


{
for (int i = 0; i < m_seats; i++) {
if (m_booked[i]) {
continue;
}
switch (type) {
case WINDOW:
if ((i + 1) % 2 == 1) {
return i + 1;
}
break;
case AISLE:
if ((i + 1) % 2 == 0) {
return i + 1;
}
break;
default:
return i + 1;
}
}
return -1;
}

Assume that the number of seats in the wagon is 4. Find out how many test cases you need to
achieve C1 test coverage for this code. For each test case provide the parameter for the invocation
of findSeat and the required values in the array m_booked.

Parameter m_booked[0] m_booked[1] m_booked[2] m_booked[3]

Page 16 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

3.3.2 Booking several seats (8)


Provide an implementation of findSeats. The method gets the number of requested consecutive
seats as a parameter. It returns true and the number of the first and last seat if the required
number of consecutive seats could be found, else it returns false. Note that due to previous
bookings and cancellations seats may arbitrarily be booked or free.

Page 17 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

Page 18 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

4 Template (20)
Your task is to implement a flexible storage class representing a simple list data structure, storing
any number of any object.

A list consists of a list object, pointing to the first and last content object. Every content object
points to its successor. The last element points to Null (0).

The class diagram shows the recursive structure of the design.

Page 19 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

The iterator class allows the user to access the data using the iterator design pattern, e.g.

CList<int> intList;

intList.addEnd(1);
intList.addEnd(2);

intList.print();

CListIterator<int> iterator (intList);


for (iterator.first(); !iterator.last(); ++iterator)
{
cout << "i = " << *iterator << endl;
}

The code for the CContent class is provided below:

template <class T>


class CContent {

private:
/**
* @link aggregation
*/
CContent<T>* m_next;

Page 20 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

T m_content;
public:

CContent(T content)
{
m_content = content;
m_next = 0;
cout << "created content at " << this << endl;
}

void setNext(CContent<T>* next)


{
m_next = next;
}

CContent<T>* getNext()
{
return m_next;
}

T getContent()
{
return m_content;
}
};

Page 21 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

4.1 CList ::addsorted (10)


Provide the code for the function addSorted(T content). Other than the already existing
method addEnd, which adds an element to the end of the list, the method addSorted searches
for the right position in the list and stores the element at this position, i.e. the first position for which
the following condition is true: all elements BEFORE are smaller than the added element – check
the sample sequence for details.
Hint: Consider
• The list can be empty, i.e. the element is the first element in the list
• The element is inserted at the correct position in between
• The element has to be added at the end, because all elements are smaller

I.e. the following sequence:


intList.addEnd(5);
intList.addEnd(10);
intList.addSorted(4);
intList.addSorted(7);
intList.addSorted(11);

produces a sorted list with the following elements:


i = 0: 4
i = 1: 5
i = 2: 7
i = 3: 10
i = 4: 11
Example code for the method addEnd:
void addEnd(T content)
{
CContent<T>* newElement = new CContent<T>(content);

//Set pointer of last element to new element, in case it exists


if (m_last != 0) m_last->setNext(newElement);

//Set pointer to last element to new element


m_last = newElement;

//Set pointer of first element to new element


//if it is the first element added to the list
if (m_first == 0) m_first = newElement;
}

Page 22 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

void addSorted(T content)


{

Page 23 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

4.2 Iterator class implementation (10)


Provide the code for the iterator class methods and overloaded operators.
template <class T>
class CList; //Forward declaration

template <class T>


class CListIterator
{
private:
/**
* @link aggregation
*/
CContent<T>* m_current;
/**
* @link aggregation
*/
CList<T>* m_list;
public:

CListIterator(CList<T> &list)
{
//Connects the pointer attribute to the list passed as parameter
m_list = &list;
}

void first()
{
//Set's the pointer to the first element of the connected list

bool last()
{
//Checks if the pointer points to a not allocated element,
//which is represented by the value 0
return m_current == 0;
}

Page 24 / 25
System Design (1010 / MSE) Prof. P. Fromm / Prof. M. Lipp

CContent<T>* operator ++()


{
//prefix operator - set the pointer to the next element
//and return the new pointer value
//Nothing to be added here
}

CContent<T>* operator ++(int)


{
//postfix operator - set the pointer to the next element
//and return the old pointer value

T operator*()
{
//return the content of the list element the pointer points to

}
};

Page 25 / 25

Das könnte Ihnen auch gefallen