You are on page 1of 3

MECB 440 - Klausur Informatik II

UMP project Feb_21, deadline Friday 18. of March


chapter 1: CVectorQueue
For the following project-chapter, we shall reuse the known and implemented classes CQueue_h of a
half dynamic queue.
Now a new class CVectorQueue shall be implemented, that can add a CMessage into a half dynamic
queue. The special feature now is, that if the Queue is full, it creates a new Queue of a double size,
copies all Messages, writes the new Message and finally deletes the old smaller Queue.
To get a message from the Queue is standard.
Please don’t invent the CQueue_h again, reuse it in a composition.

CQueue_h.cpp and CQueue.h are given.


#include "CMessage.h"
class CQueue_halbdyn
{
public:
CQueue_halbdyn(int pSize); // ctor mit size
~CQueue_halbdyn();
bool add(const CMessage& pmsg); // add Message into the queue
bool get(CMessage& pmsg); // get a Message from the queue
private:
int mSize;
int mCurrentSize; // Füllstand
int mHeadIndex; // readIndex
int mTailIndex; // writeIndex
CMessage* mQueuePtr;
};

a) Declare the class CVectorQueue. The class has methods like the CQueue_h. As attributes, two
pointers are used, one points to the actual Queue, one to the newly created Queue. Additio-
nally, the actual size has to be stored.

b) Implement the ctor of the class CQueueVector.

c) Implement the add function of the class CQueueVector. If the function cannot write the pMsg
into the Queue, because it is full, than:
a. A new Queue of double size is created
b. All Messages from the old Queue are copied into the new Queue
c. The Message pMsg is written
d. The old Queue is deleted.

d) Implement the get-Function. This function does not change the size of the actual Queue.

Prof. Dr. J. Wietzke, HsKA Karlsruhe Fak. MMT, Informatik, Moltkestr. 30, 76133 Karlsruhe;
Seite 1
MECB 440 - Klausur Informatik II

chapter 2: CMotor

A class CMotor shall be designed, to control a Motor.


There is a given POSIX device “Motor”, that can be opened, read, written and closed.
By writing an integer, the RPM (number of revolutions) is controlled, by reading an integer, you can
read the temperature of the Motor.
The class CMotor has a ctor and a setget function with 2 parameters, a requested rpm and the cur-
rent temperature.
The Motor must not overheat, so whenever the setget function is called, first the temperature is read
and checked. If it exceeds a maximum (const double Attribute), then the function switches off the
Motor and returns false and the actual temperature value.
If a change of rpm is written, the Motor is set in rpm steps of 100. For example, if the Motor spins
with 1000 rpm and shall change to -200 rpm, the function sets steps 900, 800 …0. -100, -200 and re-
turns only then with true. After each step, the function should sleep for 50 msecs.

1. Declare the class CMotor with all methods and attributes.


2. Implement the ctor of the class and initialize all attributes and open the Motor device.
3. Implement the dtor of the class.
4. Implement the setget method.

Prof. Dr. J. Wietzke, HsKA Karlsruhe Fak. MMT, Informatik, Moltkestr. 30, 76133 Karlsruhe;
Seite 2
MECB 440 - Klausur Informatik II
chapter 3: The main system, combination of chapter 1 and 2

Our main program creates an object of CVectorQueue of size 2 and then splits up a child/son thread.
The father thread writes every second a random rpm value between -1000 and 1000 rpm into a mes-
sage and writes this message into the Queue. This should repeat for 120 seconds, then the program
exits.

The son thread creates an object of CMotor, reads from the Queue and uses the values to control the
Motor. After 120 seconds, the son exits.

Send in your program as a zipped project. Make sure it runs and does, what is specified. Use your de-
bugger.
You might show the rpm steps on the display as well as the Queuesize changes, if you like.

Prof. Dr. J. Wietzke, HsKA Karlsruhe Fak. MMT, Informatik, Moltkestr. 30, 76133 Karlsruhe;
Seite 3

You might also like