Docsity

Programming - Mid-term test October: 10 multiple-choice questions, Exámenes de Programación Informática

Toggle sidebar
bg1
Programming
Bachelor in Aerospace Engineering
TEST
Anonymous
The test consists of 10 multiple-choice questions. Max GRADE 3 points. Time 20 minutes.
Each question has only one right answer. Right answer gets + 0.3 points.
Wrong answers get – 0.1 points; no answer gets 0 points.
1. What is the decimal representation of the binary number 10110?
a. 29
b. 22
c. 20
d. 28
2. What is the binary representation of the decimal number 138?
a. 11100001
b. 11100100
c. 11111000
d. 10001010
3. Let be a = 0, b = 0, c = 0, which of the following boolean expression is false?
a. (a || b) && c
b. ~( (b && c) || a )
c. ~( ~(b || c) && a )
d. (b && c) || ~a
4. Which message is printed when the following expression is executed:
fprintf('max temp is %.2f degree', 100.2345)
a. 'max temp is %.2f degree', 100.2345
b. max temp is %.2f degree 100.2345
c. max temp is 100.23 degree
d. Invalid syntax
pf3
pf4

Vista previa parcial del texto

¡Descarga Programming - Mid-term test October: 10 multiple-choice questions y más Exámenes en PDF de Programación Informática solo en Docsity!

Bachelor in Aerospace Engineering

TEST

Anonymous

The test consists of 10 multiple-choice questions. Max GRADE 3 points. Time 2 0 minutes.

Each question has only one right answer. Right answer gets + 0. 3 points.

Wrong answers get – 0. 1 points; no answer gets 0 points.

1. What is the decimal representation of the binary number 10110?

a. 29

b. 22

c. 20

d. 28

2. What is the binary representation of the decimal number 138?

a. 11100001

b. 11100100

c. 11111000

d. 10001010

3. Let be a = 0 , b = 0 , c = 0, which of the following boolean expression is false?

a. (a || b) && c

b. ~( (b && c) || a )

c. ~( ~(b || c) && a )

d. (b && c) || ~a

4. Which message is printed when the following expression is executed:

fprintf('max temp is %.2f degree', 100.2345)

a. 'max temp is %.2f degree', 100.

b. max temp is %.2f degree 100.

c. max temp is 100.23 degree

d. Invalid syntax

Bachelor in Aerospace Engineering

5. The flow diagram below represents the instruction...

a. while

b. if-else

c. if

d. switch

6. Which values of the variables a, b make the snippet of code below print on the screen the

message Option4?

if (a>7) && (b>5) fprintf ('Option1'); elseif (a>7) && (b<5) fprintf ('Option2'); else (a<7) && (b>5) fprintf ('Option3'); else fprintf ('Option4');

a. a = 2; b = 2

b. a =2; b = 12

c. a =12;, b = 2

d. None of the previous answers is right, because there are errors in the code

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

for i = 0: for j = 0: r = i+j; if mod(r,2)== 0 fprintf('%d ',r); end end end

a. Nothing

b. 0, 2, 4, 6

c. 0, 2, 2

d. 0, 2, 4

Bachelor in Aerospace Engineering

Exercise 1

Write the source code in Matlab to compute if a positive integer number is a prime

number. The program must show the result (“prime” or “composite”) and then request a

new number to check if it is prime. The program stops when 1 or 0 is typed. You can

assume that the number typed by the user will be always an integer, but check the range

(i.e. negative or positive) and ask again if necessary.

Exercise 2

Develop a MATLAB program for analysing specific features of a matrix. The matrix to be

processed in this problem are 30 × 30 arrays of black (1) and white (0) pixels. Complete the

source code of following table:

clear; clc; % DATA ------------------ nRows = 30; nColumns = 30; qrMatrix = zeros(nRows,nColumns); for i = 1:nRows for j = 1:nColums qrMatrix(i,j) = randi([0,1],1,1); end; end; % CHECK THE FEATURES ---- [complete this source code].

to test if the matrix is compliant with the following features

1. feature 1: In row 7 column 2, and row 9 column 25 must contain both black pixels.

2. feature 2: the code has a 7 × 7 section at the top left corner; this section must to include

an odd number of black pixels.

3. feature 3: the matrix has a 7 × 7 section at the top right corner which includes at least

25 black pixels (in any arrangement). For this item, you only get all the points if the

source code executes the smallest number of steps, so use while(s) instructions.

4. Feature 4: the last column and the last row are all white pixels.

Before the end of the program, the result, compliant or not for each feature, must be shown on

the screen. Additionally, show on the screen if the matrix is compliant for all the features at the

same time.