Practice - ClassTest2023
Practice - ClassTest2023
INSTRUCTIONS:
QUESTION 1
Show all workings when making the conversions which follow (Answer in the provided answer
booklet):
a) Convert 145010 to binary and hence to hexadecimal (4 marks)
b) Without first converting to decimal, add 10101102 and 10101112.
Convert the result to hexadecimal and then directly from hexadecimal to decimal. (6 marks)
c) *Without first converting to decimal, add the tetradecimal (base 14) numbers 3B914 and
8D414, where the characters A, B, C, D and E are used to represent register values of 10, 11,
12, 13 and 14 respectively. (1 mark)
QUESTION 2
Using the MCQ cards provided, please answer the following questions:
II. Which of the following statements is true about the ‘clear’ function as seen below in MatLab:
III. Which of the following statements about the ‘SWITCH-CASE’ algorithm is false:
a. It only tests a single variable for equality
b. If none of the case conditions are met, the logical value 0 is returned
c. It is a branching algorithm that tests against a list of possible discrete values
d. Only one case can be valid
0 50 0 5
⎡ 10 30 ⎤ ⎡2 3⎤
⎢ ⎥ ⎢ ⎥
Forces= ⎢ 20 15 ⎥ Positions= ⎢ 4 1⎥
⎢30 −20⎥ ⎢6 2⎥
⎢40 −40⎥ ⎢2 1⎥
⎣50 0⎦ ⎣ 10 3⎦
V. Select the line of code that will produce the following command line output:
20 15
𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆 = � �
30 −20
VI. Select the line of code that will produce the following command line output:
0 250
⎡ 20 90 ⎤
⎢ ⎥
Moments= ⎢ 80 15 ⎥
⎢ 180 −40 ⎥
⎢ 80 −40 ⎥
⎣ 500 0 ⎦
a. Moments = Forces*Positions
b. Moments = Forces x Positions
c. Moments = [Forces(:,1)*Positions(:,1) Forces(:,2)*Positions(:,2)]
d. Moments = Forces·*Positions
VII. Select the matrix that is produced by the following line of code:
30 −20
a. Merged = �40 −40�
50 0
b. Merged = �30 −20 50�
40 −40 0
30 −20
c. Merged = �40 −40�
50 5
d. Merged = �30 −20 50�
40 −40 5
5 3 9 6 3 8
𝐴𝐴 = �2 8 2� 𝐵𝐵 = �9 8 2�
6 4 1 3 5 1
VIII. Given matrices A and B, which logical array is true for the following logical statement A | B
0 0 0
a. ans = �0 0 0�
0 0 0
1 1 1
b. ans = �1 1 1�
1 1 1
0 1 0
c. ans = �0 1 1�
0 0 1
1 0 1
d. ans = �1 0 0�
1 1 0
3 APRIL 2023 Page 4 of 11 MECN2012
IX. Given matrices A and B, which logical array is true for the following logical statement A>=2
1 1 1
a. ans = �0 1 0�
1 1 0
0 0 0
b. ans = �1 0 1�
0 0 1
1 0 0
c. ans = �0 0 0�
0 0 0
1 1 1
d. ans = �1 1 1�
1 1 0
X. Select the matrix that is produced by the following line of code:
B (end) = 3;
6 3 8
a. 𝐵𝐵 = �9 8 2�
3 3 3
6 3 8
b. 𝐵𝐵 = �9 8 2�
3 5 3
c. 𝐵𝐵 = �6 3 8�
9 8 2
d. None of the above, the matrix sizes are incompatible
XI. *If the shaded area represents the Inclusive set, which of the following Boolean Operators is
equivalent to the Venn diagram:
a. A AND B
b. NOT B
c. NOT A
d. A NOR B
QUESTION 3
a. All questions refers to the program below called Factorial.m that displays all factorials from
1 to n. Where a factorial, n!, is defined as the product of all integers from 1 to n.
Entries in the matrix are the results of 1!, 2!, 3!, 4! and 5!. Complete the value table given on
page 8 for the program called Factorial.
QUESTION 4
Use the answer sheets on Page 9 of this question paper to answer this question. Please ensure that you
answer all questions as required and carefully read the instructions related to each question.
All questions refers to the program below called Common_Multiples.m, which displays the first n
common multiples of two numbers, for example the first 5 common multiples of 2 and 3 are:
There are five errors in the code shown, some of which may be terminal. Any errors in the code are
syntax and not arithmetic errors.
a. Below is a list of these five errors. For each of the lines listed below: select the error from the
list provided (1 mark); select the effect it would have on the functioning of the code (1 mark);
and provide the corrected syntax (1mark):
i. Line 1 (3 marks)
ii. Line 9 (3 marks)
iii. Line 16 (3 marks)
iv. Line 18 (3 marks)
v. Line 23 (3 marks)
3 APRIL 2023 Page 7 of 11 MECN2012
b. *What is the function of a break point in error checking and debugging? (1 Marks)
QUESTION 5
a. The following questions relate to flowcharting. Question i should be answered in the provided
answer booklet on the answer sheet at the end of this question paper.
Consider Pascal’s Triangle used to determine binomial coefficients, where each row begins and ends
with the number 1, and every entry in the row is the sum of the 2 adjacent elements in the preceding
row (i.e. 𝑃𝑃𝑛𝑛𝑘𝑘+1 = 𝑃𝑃𝑛𝑛−1𝑘𝑘 + 𝑃𝑃𝑛𝑛−1𝑘𝑘+1 ):
Where;
Draw a flow chart for a program to calculate the binomial coefficients in the nth row given the starting
vector [1 1] which represents the binomial coefficients in the 1st row.
(Total: 15 Marks)
[TOTAL: 60 Marks]
3 APRIL 2023 Page 8 of 11 MECN2012
Please clearly circle ONLY the answer that you wish to give for each question. Do not circle more
than one answer as such questions will be disregarded. Students are encouraged to first mark their
answers in pencil so that only the final answer circled in pen is graded. You do not have to answer
every question.
I. A B C D
II. A B C D
III. A B C D
IV. A B C D
V. A B C D
VI. A B C D
VII. A B C D
VIII. A B C D
IX. A B C D
X. A B C D
XI. *A B C D
3 APRIL 2023 Page 9 of 11 MECN2012
Please enter the values in the given value table. Circle or highlight the value which changes in each line
of the table. You may use as many or as few lines as needed but may not exceed the number of lines
provided. Please draw a line through any unused lines. Lines that contain only an “end ” must not be
included in the value table.
a. For each question, first circle the error type, then circle the effect on the code, and finally provide
the corrected line of code by writing it neatly in the provided space.
Multiple circled options, unless one is explicitly clear, will result in a mark of zero for that question.
Note that only one of these errors occurs per line given.
When selecting the effect type, please circle the option corresponding to one of these descriptions:
A - Compilation error
B - Runtime error
C - Infinite loop - Program starts execution but becomes stuck in an infinite loop due to error
code
D - Output value error - Program completes execution but output is of unexpected or incorrect
value
E - Output format error - Program completes execution but output is of unexpected or
incorrect format
i. Line 1 – Error 1
Fix:
3 APRIL 2023 Page 11 of 11 MECN2012
v. Line 23 – Error 5
b. *_____________________________________________________________
______________________________________________________________
______________________________________________________________
Student Number:____________