1. Consider the array: s( 0 ) = 7 s( 1 ) = 0 s( 2 ) = -12 s( 3 ) = 9 s( 4 ) = 10
ID: 3534845 • Letter: 1
Question
1. Consider the array:
s( 0 ) = 7
s( 1 ) = 0
s( 2 ) = -12
s( 3 ) = 9
s( 4 ) = 10
s( 5 ) = 3
s( 6 ) = 6
The value of s( s( 6 ) - s( 5 ) ) is:
a. 0.
b. 3.
c. 9.
d. 0.
2. Consider the program below:
a = [ ];
for i=1:10
a( i ) = i + 2;
end
result = 0;
for i=1:length(a)
result = result + a( i );
end
fprintf( ‘Result is: %d ’, result );
The output of this program will be:
a. Result is: 62.
b. Result is: 64.
c. Result is: 65.
d. Result is: 67.Analyze the following code (This is tricky!):
Main Program
radius1 = 3;
radius2 = 1;
[result1 result2] = twoCircles(radius1, radius2);
fprintf(‘The area of circle 1 with radius %.1f is %.1f’, radius1, result1);
fprintf(‘The area of circle 2 with radius %.1f is %.1f’, radius2, result2);
Function
function [res1 res2] = twoCircles(radius2, radius1)
radius1 = radius1 + 1;
radius2 = radius2 * radius1;
res1 = pi* radius1^2;
res2 = pi* radius2^2;
fprintf(‘The area of circle 1 with radius %.1f is %.1f’, radius1, res1);
fprintf(‘The area of circle 2 with radius %.1f is %.1f’, radius2, res2);
3. What radius1 is output in the main program?
a. 1
b. 2
c. 3
d. 4
e. none of the above
4. What radius2 is output in the main program?
a. 1
b. 2
c. 3
d. 4
e. none of the above
5. What radius1 is output in the function?
a. 1
b. 2
c. 3
d. 4
e. none of the above
6. What radius2 is output in the function?
a. 1
b. 2
c. 3d. 4
e. none of the above
7. Analyze the following code:
x = 2:2:10
plot(x, (2 .* x -1),’g^:’); %Remember order of precedence!
xlim([0 15]);
ylim([0 20]);
Multiple Choice questions would be asked on how this would exactly display in Matlab’s
figure window:
a. What are the tick marks on the x-axis
b. What are the tick marks on the y-axis
c. What style line?
d. What style markers?
e. What color is the line? What color are the markers?
f. How would I place a legend in the upper middle position?
8. If you had the following input file:
myInput.txt
Analyze the following code:
inFile = fopen(‘myInput.txt’);
oneLine1 = fgets(inFile);
oneLine2 = fgetl(inFile);
result = length(oneLine2) – length(oneLine1);
What is result?
a. 0
b. 1
c. 2
d. 3
Explanation / Answer
1. Consider the array: s( 0 ) = 7 %%%Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.