Académique Documents
Professionnel Documents
Culture Documents
Duration: 90 Minutes
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)
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)
for k 0
=
with
: xk 0 for k < 0
xk =
x(k T )
(8 P)
Solution:
www.vgu.edu.vn
MSST Mechatronics and Sensor System Technology
Prof. Dr.-Ing. Hans-Werner Dorschner
25.10.2012
Seite 4/10
(4 P)
www.vgu.edu.vn
MSST Mechatronics and Sensor System Technology
Prof. Dr.-Ing. Hans-Werner Dorschner
25.10.2012
Seite 5/10
4.
(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)
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.
(4 P)
5.2.
(4 P)
5.3.
Implement a function
(3 P)
(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.
(30P)
A quadrangle is defined by 4 points which are clockwise specified and set by the
user.
Quadrangle
Parallelogram
(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)
(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
25.10.2012
Seite 9/10
(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