Docsity

Programming - First mid-term exam October 2017 with solutions, Exámenes de Programación Informática

Toggle sidebar
bg1
Programming
Bachelor in Aerospace Engineering
First mid-term exam. Oct 23rd 2017
TEST (2.5 points)- 25 minutes
Please return this sheet with your resolutions, and any other sheet for draft or notes, thanks!
SURNAME, NAME:
NIU/NIA: 100
The test consists of 10 multiple-choice questions. Each question has only one right answer.
Right answer gets +0.25 points. Wrong answers get - (0.25/3) points; no answer gets 0
points.
Mark your answers in this sheet.
1. What is the decimal representation of the binary number 1010 1101 0101?
a. 2883
b. 2783
c. 2773
d. 2873
2. What is the binary representation and the octal representation of the decimal number 1457?
a. 010 110 110 001 2771
b. 010 111 111 001 2771
c. 010 111 111 001 2661
d. 010 110 110 001 2661
3. Boolean expressions. Which one is always false
a. (a > 7) && (a < 10)
b. (a < 7) && (a > 10)
c. (a > 7) || (a < 10)
d. (a < 7) || (a > 10)
4. Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is
negative but leave x alone if x is 0?
If (x > 0)
x = x +1;
else
x = x -1;
end
(a)
If (x > 0)
x = x +1;
elseif (x < 0)
x = x -1;
end
(b)
If (x == 0)
x = 0;
else
x = x +1;
x = x -1;
end
(c)
x = x + 1;
x = x – 1;
(d)
pf3
pf4
pf5

Vista previa parcial del texto

¡Descarga Programming - First mid-term exam October 2017 with solutions y más Exámenes en PDF de Programación Informática solo en Docsity!

Programming

Bachelor in Aerospace Engineering

First mid-term exam. Oct 23rd^2017

TEST ( 2 .5 points)- 25 minutes

Please return this sheet with your resolutions, and any other sheet for draft or notes, thanks!

SURNAME, NAME:

NIU/NIA: 100

The test consists of 10 multiple-choice questions. Each question has only one right answer.

Right answer gets +0. 25 points. Wrong answers get - (0. 25 /3) points; no answer gets 0

points.

Mark your answers in this sheet.

1. What is the decimal representation of the binary number 1010 1101 0101?

a. 2883

b. 2783

c. 2773

d. 2873

2. What is the binary representation and the octal representation of the decimal number 1457?

a. 010 110 110 001 2771

b. 010 111 111 001 2771

c. 010 111 111 001 2661

d. 010 110 110 001 2661

3. Boolean expressions. Which one is always false

a. (a > 7) && (a < 10)

b. (a < 7) && (a > 10)

c. (a > 7) || (a < 10)

d. (a < 7) || (a > 10)

4. Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is

negative but leave x alone if x is 0?

If (x > 0)

x = x +1;

else

x = x - 1;

end

(a)

If (x > 0)

x = x +1;

elseif (x < 0)

x = x - 1 ;

end

(b)

If (x == 0)

x = 0;

else

x = x +1;

x = x - 1 ;

end

(c)

x = x + 1;

x = x – 1;

(d)

5. Select the right assertion:

a. switch statements require each case to end with break b. in a switch statement, when no case is true, the otherwise block (if defined) is executed c. switch statements are always more convenient than if statements d. switch statements can replace for statements

6. The flow diagram below represents the instruction …

a. while

b. for

c. if-else

d. switch

7. Selects the right option. The while loop will repeat a block of statements.

a. ... based on a counter.

b. ...until a conditional or boolean expression turns to false.

c. ... every time the enter key is pressed.

d. ... indefinitely.

condition true false statements

10. What is the output of the program below (i.e., what is printed on the screen)?

v = zeros(1,10);

% first loop

for i = 0:

v(i+1) = i;

end

% second loop

for k = 1:

i = randi([1,10],1,1);

fprintf('%d ',v( v(i) ) );

end

a. any sequence of digits

b. there will always be an execution error in the first loop for

c. there could be an execution error in the second loop for

d. there will always be an execution error in the second loop for

Programming

Bachelor in Aerospace Engineering

First mid-term exam. Oct 23rd^2017

Exercises (total: 7.5 points) 6 0 minutes.

Please return this sheet together with your resolutions and any sheet for draft or notes, thanks!

SURNAME, NAME:

NIU/NIA: 100

Exercise 1 (3.5 points)

Write a MATLAB® program that gets two random positive integer numbers and compute their

Greatest Common Divisor. Of course you cannot call the MATLAB® built-in function

gcd(a,b). Some examples of the output of the program:

The GCD of 845 and 195 is 65 The GCD of 39 and 26 is 13 The GCD of 36 and 91 is 1 The GCD of 23 and 11 is 1

Exercise 2 (4. 0 points)

Write the source code for the SECOND SECTION of the source code shown below. The second section

must check if the sum of the elements of each row and each column of the matrix is just the same

value or not.

Figure 1 Two examples of matrices: the right one is compliant with the condition; the left one is not. Table 1. Source Code: first section not asked. Complete the section two clear; clc; nR = random([2,10],1,1); nC = random([2,10],1,1); matrix = zeros(nR, nC) %% FIRST section % Get the elements of the matrix % This section is not requested (do not write any instruction) ... %% SECTION TWO – COMPLETE THIS SECTION % CHECK IF the sum of the elements of each row and each column % is just the same value or not. ??

Programming Bachelor in Aerospace Engineering First mid-term exam. Oct 23rd^2017 Figure 3 Exercise 0 2 - resolution