Next: , Up: (dir)

Scripting Languages G22.3033-002 Summer 2008


Previous: Top, Up: Top

Scripting Languages G22.3033-002 Summer 2008 Example solutions for hw01

Assigned Th 5/22/2008, due Fr 5/30 at 4pm. 50 points.

http://www.cs.nyu.edu/courses/summer08/G22.3033-002/


Next: , Up: solutions-hw01

Instructions for example solutions

These are example solutions. Please keep in mind that often, there is not just one correct solution to a question. If you come up with different answers, then it may be that both your answers and these answers here are correct. Of course, these answers here may also contain mistakes. If you spot a mistake, please let me know so I can correct it.


Previous: Instructions, Up: solutions-hw01

Example solutions for Homework 1


Next: , Up: Solutions-hw01

solutions-hw01-1 Dynamic typing

  1.           Sub PrintArray(Arr() As String)
                Debug.Print "PrintArray:"
                For I% = 0 To UBound(Arr)
                  Debug.Print "  " & I & " " & Arr(I)
                Next I
              End Sub
              Sub Main()
                Dim fruits(2) As String
                fruits(0) = "apple"
                PrintArray fruits
                fruits(1) = "orange"
                fruits(2) = "banana"
                PrintArray fruits
              End Sub
         


Next: , Previous: solutions-hw01-1, Up: Solutions-hw01

solutions-hw01-2 Precedence and associativity

  1. 2 - (2 - 2 - 2 * 2)


Next: , Previous: solutions-hw01-2, Up: Solutions-hw01

solutions-hw01-3 Euclidian distance (VBA)

     Function EuclidDistance(A() As Double, B() As Double) As Double
       EuclidDistance = 0
       Dim I As Integer
       For I = LBound(A) To UBound(A)
         EuclidDistance = EuclidDistance + (A(I) - B(I)) ^ 2
       Next I
       EuclidDistance = EuclidDistance ^ 0.5
     End Function


Previous: solutions-hw01-3, Up: Solutions-hw01

solutions-hw01-4 Average rows (VBA)

     Sub AverageRows(Result() As Double, Rows() As Double)
       Dim I As Integer, J As Integer
       For I = LBound(Rows, 1) To UBound(Rows, 1)
         Result(I) = 0
         For J = LBound(Rows, 2) To UBound(Rows, 2)
           Result(I) = Result(I) + Rows(I, J)
         Next J
         Result(I) = Result(I) / (1 + UBound(Rows, 2) - LBound(Rows, 2))
       Next I
     End Sub