Commander: 1) get r and h values from cells(1, 1) and cells(1, 2) from the works
ID: 3838794 • Letter: C
Question
Commander: 1) get r and h values from cells(1, 1) and cells(1, 2) from the worksheet; 2) call the volume procedure to calculate the volume by passing r and h to that procedure; 3) show the volume in cells (1, 3); 4) call the area procedure to calculate the area by passing r and h to that procedure; 5) show the area in cells (1, 4) Volume procedure: 1) receive the values of r and h; 2) calculate the volume (according to the formula given by the textbook on page 19); 3) return the volume value to the commander. Area procedure: 1) receive the values of r and h; 2) calculate s; 3) calculate area (according to the formula given by the textbook on page 19); 4) return the area value to the commander No need to use Excel to design your code. Please write the code on the paper. Use for-loops to calculate the summation of: -0.1, 0.2, -0.3, 0.4, 0.5, 0.6, -0, 7, 0.8, -0.9, 1.0, -1.1, ...., 99.8, -99.9, 100.Explanation / Answer
/* for r and h value you can submit the values by filling the cell, and then call the volume and area functions to get the results
Dim i As Integer
Dim r As Integer
Dim h As Integer
Dim vol As Double
Dim ar As Double
Dim TxtRng As Range
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Sheet1")
For i = 1 To 2
Cells(1, i).Value = 100
Next i
r = Cells(1, 1).Value
h = Cells(1, 2).Value
vol = volume(r,h)
ar = volume(r,h)
Set TxtRng = ws.Range("C1")
TxtRng.Value = vol
Set TxtRng = ws.Range("D1")
TxtRng.Value = ar
Function volume(r as integer,h as integer) AS Double
/* Put your formula here given to you to calculate volume
End Function
Function area(r as integer,h as integer) AS Double
/* Put your formula here given to you to calculate area
End Function
/*** for sum of numbers , you can try something like that, if your values are in A range in excel sheet*/
Dim s As Integer
For j = 1 To end
s = s + Range("A" & i)
Next j