Professional Documents
Culture Documents
Fundamentals of Programming Problemsonarray: Typedef Int
Fundamentals of Programming Problemsonarray: Typedef Int
UMA-LCC
problems on a r r a y < >
prof. Dr. Juan Falgueras
1 Suppose (N is a previous declared constant) to interchange the contents of the two variables a and
typedef array<int,N> TVec; b, build the procedure
Build the next subprograms: void reversarr ( TVector & a ) ;
(a) void printArr(TVec a); to print it that reverses the contents of the array a
(b) void readArr(TVec& a); to read it from the user
10 Build a function to return the index in which the pair of
keyboard
numbers 1, 2, appear consecutively in an array TVector
(c) TVec readArr(); to read it from the user keyboard a. For example, in [−2, 3, 1, 2, 0, 1, 2] it would return:
but as a function that returns the local TVec array 2. If they did not appear return −1
returned
NOTA: Be careful accessing the components of the array,
From the main program, try them all declaring a TVec not reading values out of the range of it.
a;, then printArr(a);, to see the values an uninitialize 11 Let’s suppose we have the type typedef array<float
array has, then test readArr(a); and a = readArr(); ,3> TPos; an array to hold the cartesian coordinates
reading the vector in each form, modifying the parame- of a point in the 3D space. Given the positions of two
ter by reference and getting it as the returned value from points, r1 and r2, build a function to compute (and
a function, and again print the vector in each case. return) the distance between these 2 points. The dis-
~ ~
2 Given TVec from 1 build qP between 2 points ~a and b is defined as: d(~a, b) =
tance
3 2
(a) a subprogram void printrra(TVec a); to print i=1 (bi − ai )
Print these two values in the main program after calling It should print: 14, -208