Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question{21}: Given the following, what is wrong with the code? Balance = 100; I

ID: 3865488 • Letter: Q

Question

Question{21}: Given the following, what is wrong with the code?

Balance = 100;

IAmBroke = false;

while (IAmBroke == false)

Bill = randi( 10 );

if (Balance > 0)

disp('Keep paying the bills!');

Balance = Balance - Bill;

else

disp('Time to call for help!');

IAmBroke = true;

end;

end;

A. The Balance never changes.

B. The IAmBroke never changes.

C. It works correctly to me.

D. It only runs once.

E. The Balance can become less than zero.

Answer{21}='';

Reason{21}='';

Question{22}: How many times will the disp(...) run?

Introduction = fileread('Introduction.txt');

for Letter = Introduction

disp( Letter );

end;

Answer{22}='';

Reason{22}='';

Question{23}: How many times will the disp(...) run?

for DistanceCM = ( 0 : (1/100) : 5 )

DistanceInches = DistanceCM / 2.54;

disp( DistanceInches );

end;

Answer{23}='';

Reason{23}='';

Question{24}: How many times will the disp(...) run?

Sample = imread('Sample.jpg','JPEG');

[Rows, Columns, Colors ] = size( Sample );

for RowIndex = 1 : 1 : Rows

for ColumnIndex = 1 : 1 : Columns

% Please remember to comment out the following lines when done.

disp(sprintf('Red: %d, Green: %d, Blue: %d',...

Sample(RowIndex, ColumnIndex, 1),...

Sample(RowIndex, ColumnIndex, 2),...

Sample(RowIndex, ColumnIndex, 3)));

end;

end;

Answer{24}='';

Reason{24}='';

Question{25}: Given the following, how many times does the while...end

run?

APR = .08;

Balance = 1000;

Payment = 25;

while (Balance > Payment)

% This combines the two steps from the lecture examples into one.

Balance = Balance * ( 1 + (APR / 12) );

Balance = Balance - Payment;

end;

Answer{25}='';

Reason{25}='';

Explanation / Answer

Question{21}:
output:
Keep paying the bills!
Keep paying the bills!
Keep paying the bills!
Keep paying the bills!
Keep paying the bills!
Keep paying the bills!
Keep paying the bills!
Keep paying the bills!
Keep paying the bills!
Keep paying the bills!
Keep paying the bills!
Keep paying the bills!
Keep paying the bills!
Time to call for help!

Answer:
C. It works correctly to me.



Question{22}:
for loop will run infinite times as there is no termination condition in for loop

Question{23}:
DistanceCM ranges from 0 to 5 with increments of 0.01
total 501 times for loop runs



Question{24}:
there are rows*columns iterations in sample
hence disp is implemented rows*columns times


Question{25}:
WHile loop runs until Balance in greater than payment
there will be 46 iteration