Vous êtes sur la page 1sur 10

Final Examination Software Engineering/C++

Summer Semester 2013, 05.04.13

Duration: 90 Minutes

Expedients: Script and lecture notes

Last name:.....

First name:

Evaluation:

Problem

total

Marks available

14

14

12

12

18

30

100

Marks awarded

Professors Signature:___________________________________

www.vgu.edu.vn
MSST Mechatronics and Sensor System Technology
Prof. Dr.-Ing. Hans-Werner Dorschner

25.10.2012
Seite 1/10

1.

Problem

(14 P)

How does the output of the program look like?


#include<iostream>
#include<cstdlib>
using namespace std;
void main()
{
float x[6]={0,1,2,3,4,5};

Solution:

float *pointer=x+1;
cout<<pointer<<endl;
cout<<*(pointer +2)<<endl;
for(int i=0;i<3;i++)
{ pointer +=i;
x[i]=pow(*pointer*1.0,2);
cout<<x[i]<<endl;
};
system("PAUSE");
}

www.vgu.edu.vn
MSST Mechatronics and Sensor System Technology
Prof. Dr.-Ing. Hans-Werner Dorschner

25.10.2012
Seite 2/10

2.

Problem: Recursion

(14 P)

Write a program in C++ for the evaluation of the so called Ulam function in a recursive way (separate function!). In a main program use this function to calculate
the first 10 values of the function and store these values on in a dynamic array on
the heap called *ulamValues.

Ulam funktion c : 0 :
c(1) = 0

n
1 + c ,
c ( n) =
2
1 c(3 n + 1),

n even
n odd

Solution:

www.vgu.edu.vn
MSST Mechatronics and Sensor System Technology
Prof. Dr.-Ing. Hans-Werner Dorschner

25.10.2012
Seite 3/10

3.

Problem: Iteration

(12 P)

A digital filter has the following representation in time:

yk =0.7 yk 2 + 0.21 yk 4 + 0.16 xk 1


=
yk 0

for k 0

=
with
: xk 0 for k < 0
xk =
x(k T )

for k 0, T sampling time

3.1. Implement the filter algorithm as an iterative algorithm in a function.

(8 P)

double filter(int k, double xk)

Solution:

www.vgu.edu.vn
MSST Mechatronics and Sensor System Technology
Prof. Dr.-Ing. Hans-Werner Dorschner

25.10.2012
Seite 4/10

3.2. Which is the stable state value of the filter?

(4 P)

Derive your answer from the filter equation!


Solution:

www.vgu.edu.vn
MSST Mechatronics and Sensor System Technology
Prof. Dr.-Ing. Hans-Werner Dorschner

25.10.2012
Seite 5/10

4.

Problem: Loops and arrays

(12 P)

A six digit pass word is listed as Ca7%j( and stored in an array. A user has to enter in the program each element of the pass word. The pass word gets compared
with the stored pass word. If he enters a wrong password a counter will be incremented. After 3 false attempts the input is shut down.
Implement the pass word input process in a main module.
Solution:

www.vgu.edu.vn
MSST Mechatronics and Sensor System Technology
Prof. Dr.-Ing. Hans-Werner Dorschner

25.10.2012
Seite 6/10

5.

Problem: Pointer

(18 Pkte)

A set of n points in a Cartesian coordinate system should be entered in a program


by help of an input function
void inputVal(int n, float *points)

and stored to the heap.


The function stores the coordinates in an array which has the following form:

points = {x1 , y1 ,............., xn , yn } .


A second function
void transformPolar(int n, float *points, float *results)

should transform the coordinates to polar representation and store these polar coordinates in another array results of the form:

results = {r1 , 1 ,.......rn , n }. The ri are the radius and i the respective angle of each
coordinate.
5.1.

Implement the function inputVal.

(4 P)

5.2.

Implement the function transformPolar.

(4 P)

5.3.

Implement a function

(3 P)

void flushVal(float *points, float *results),

which deletes all data on the heap.


5.4.

Program an application which reads n points from the console converts


the points to polar representation and prints them on the screen.
At the end all data should be erased.

(4 P)

www.vgu.edu.vn
MSST Mechatronics and Sensor System Technology
Prof. Dr.-Ing. Hans-Werner Dorschner

25.10.2012
Seite 7/10

Solution:

www.vgu.edu.vn
MSST Mechatronics and Sensor System Technology
Prof. Dr.-Ing. Hans-Werner Dorschner

25.10.2012
Seite 8/10

6.

Problem: class quadrangle

(30P)

A quadrangle is defined by 4 points which are clockwise specified and set by the
user.

Quadrangle

Parallelogram

6.1. Implement a class of quadrangles

(15 P)

=
x1 , x2 , x3 , x4 } and yko { y1 , y2 , y3 , y4 }
With the following
attributes xko {=
(4P)
as an array with coordinates values of type double.
Implement the following methods:
double getCircumference(),

(3 P)

bool isParallelogram()

(6 P)

and a constructor which initializes a quadrangle with the coordinates


xko and yko.

(2 P)

A parallelogram does exist if the opposite sides are parallel. Parallelism implies
equal angles to the x- and y-axis. Because of rounding errors equality is never obtained even if the sides are parallel. Take this into account and accept a tolerance
for the parallelism detection.
6.2. Derive from the class of the quadrangles a new class of rectangles withe the
attributes:
(10 P)
double area, a, b;

(3P)

The parameters a and b define the length of each side of the rectangle.
Implement also a constructor which initializes a rectangle with the coordinates
xko and yko.
Implement the following methods:

www.vgu.edu.vn

MSST Mechatronics and Sensor System Technology


Prof. Dr.-Ing. Hans-Werner Dorschner

25.10.2012
Seite 9/10

bool isRectangle() and

(5 P)

double getArea()

(2 P)

A rectangle is given if the object is a parallelogram and the sides are perpendicular
to each other. That means and are equal and have a value of /4!
6.3. Write a main program which defines a rectangle and a quadrangle. (5 P)
For the quadrangle the program should check for parallelogram and return a result
on the screen. For the rectangle it tests also if the object is a rectangle and if so
calculates the area and prints it to the screen.

www.vgu.edu.vn
MSST Mechatronics and Sensor System Technology
Prof. Dr.-Ing. Hans-Werner Dorschner

25.10.2012
Seite 10/10

Vous aimerez peut-être aussi