0% found this document useful (0 votes)
71 views

Department of Engineering Science

1) The document is a quiz for a computer applications in engineering course containing 3 programming problems to determine the values of variables at different steps of the code. 2) Problem A involves R programming code calculating values of variables x and y through a for loop and if/else statements. 3) Problem B involves VBA code in Excel to calculate cell values based on input values and using select case statements. 4) Problem C involves drawing the output of Visual Basic code on a 25x25 pixel grid provided on the answer sheet.

Uploaded by

Karen Lovedorial
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Department of Engineering Science

1) The document is a quiz for a computer applications in engineering course containing 3 programming problems to determine the values of variables at different steps of the code. 2) Problem A involves R programming code calculating values of variables x and y through a for loop and if/else statements. 3) Problem B involves VBA code in Excel to calculate cell values based on input values and using select case statements. 4) Problem C involves drawing the output of Visual Basic code on a 25x25 pixel grid provided on the answer sheet.

Uploaded by

Karen Lovedorial
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DEPARTMENT OF ENGINEERING SCIENCE

College of Engineering and Agro-Industrial Technology


University of the Philippines Los Baños

ENSC 26 Computer Applications in Engineering


Long Quiz #3 (November14, 2017)

Name: ____________________________________________ Signature: __________________ Section: __________

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()

Dim sngcase As Single


Dim intX(3) As Integer
Dim intN As Integer
Dim intCounter As Integer

intN = Range("B8").Value
sngcase = intN + 3 * 2 \ 5
Range("B9").Value = sngcase

Select Case (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

For intCounter = 0 To UBound(intX)


intX(intCounter) = Cells(intRow, intCounter + 1)
Next

Range("B11").Value = intX(1) + intX(2) - intX(3) * sngcase


Range("B12").Value = Range("B10").Value + intX(0) * sngcase

End Sub

intN sngCase Output1 Output2 Output3


4.2 (1) (2) (3) (4)

1.5 (5) (6) (7) (8)

-10 (9) (10) (11) (12)


C. Graphics/Computer Vision. Draw the following code on the space (25 x 25 pixels) provided on your
answer sheet. Follow the specified legends as illustrated below. STRICTLY, NO ERASURES.

Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs)_


Handles Me.Paint

e.Graphics.DrawLine(Pens.Blue, 3, 3, 20, 20)

Dim intX As Integer = 2


Dim intY As Integer

For i As Integer = 1 To 10 Step 1.5

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy