Department of Engineering Science
Department of Engineering Science
Department of Engineering Science
Value Prediction (50 pts.). Determine the values of the variables at the end of each algorithm.
A. R Programming. Determine the value of x after each set of code. Note that the following codes are
continuous (i.e. the result of the previous problem stored in a variable can be used in the succeeding problem).
x<-0 x<-sum(vectA)%%y
vectA<-c(0:6) y<-mean(vectA)
for (counter in vectA){ print(x)
x = x + counter print(y)
y = x%%2 #mod operation 3.
if (y==0) {
x = x-counter x<- y + 3. / 5. - x
} y<- y^2*3-5
} print(x)
print(x) print(y)
print(y) 4.
1.
y<-x%%3 x<-sum(c(TRUE,x,y))
print(y) y<-vectA[1]
if(y==0){ print(x)
while(y>-2){ print(y)
5.
x = x+1
y = y-2
}
} else if(y==1) {
while(x>y){
x = x-1
y = y+1
}
} else {
while(y>-2){
x = x+3
y = y-2
}
}
print(x)
print(y)
2.
Code # 1. 2. 3. 4. 5.
Y
B. Excel Prediction. Determine the resultant values at the specified cells after the calculate button is clicked.
Sub Calculate()
intN = Range("B8").Value
sngcase = intN + 3 * 2 \ 5
Range("B9").Value = sngcase
Case 1 To 3
intRow = 2
Cells(10, 2).Formula = "=Average(A3:E3)"
Case Is < 5
intRow = 4
Cells(10, 2).Value = Cells(4, 2).Value + Cells(3, 2).Value Mod Cells(2, 5).Value
Case Else
intRow = 5
Cells(10, 2).Formula = "=SUM(B3:C6)"
End Select
End Sub
If intX>= 0 Then
intY = i
Else
intY = 3 * i + 2 * intX
End If
e.Graphics.DrawRectangle(Pens.Green, intY, i, 2, 2)
e.Graphics.FillRectangle(Brushes.Red, intY + 1, i + 1, 1, 1)
intX -= 1
Next
e.Graphics.FillRectangle(Brushes.Blue, 7, 12, 3, 2)
e.Graphics.FillRectangle(Brushes.Red, 12, 12, 3, 2)
End Sub
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
0
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24