Janani Ragothaman and Isaac Almquist 1.
Sub pingpong() ' ' pingpong Macro ' ' Dim diameter(1 To 100) As Single, thickness(1 To 100) As Single, mass(1 To 100) As Single, height(1 To 100) As Single, maxh As Single Dim averaged As Single, averaget As Single, averagem As Single, averageh As Single, i As Single, sumd As Single, sumt As Single, summ As Single, sumh As Single Open ("I:\ENGR 160 class folders\Stiehl_J1\InClass by Date\Ping.dat") For Input As 1 Open ("U:\ping pong") For Output As 2 sumd = 0 sumt = 0 summ = 0 sumh = 0 maxh = 0 For i = 1 To 100 Input #1, diameter(i) Input #1, thickness(i) Input #1, mass(i) Input #1, height(i) If i = 1 Then maxh = height(1) If height(i) > maxh Then maxh = height(i) sumd = sumd + diameter(i) sumt = sumt + thickness(i) summ = summ + mass(i) sumh = sumh + height(i) Next i averaged = sumd / 100 averaget = sumt / 100 averagem = summ / 100 averageh = sumh / 100 Print #2, "the average of the diameters = "; averaged; "inches" Print #2, "the average of the wall thickness = "; averaget; "inches" Print #2, "the average of the mass = "; averagem; "grams" Print #2, "the average of the height = "; averageh; "feet" Print #2, "the largest rebound height = "; maxh; "feet" Close End Sub ANSWER: the average of the diameters = 1.28345 inches the average of the wall thickness = 7.041002E-02 inches the average of the mass = 0.6151003 grams the average of the height = 6.725002 feet the largest rebound height = 9.8 feet
2. Sub bolt() Dim bolt(1 To 200) As Single, i As Single, n As Integer, sum As Single, sumx As Single, average As Single, stdev As Single Open ("I:\ENGR 160 class folders\Stiehl_J1\InClass by Date\BoltIn.dat") For Input As 1 Open ("U:\BoltOut.txt") For Output As 2 sum = 0 Input #1, n For i = 1 To n Input #1, bolt(i) sum = sum + bolt(i) Next i average = sum / n sumx = 0 For i = 1 To n sumx = (bolt(i) - average) ^ 2 + sumx Next i stdev = (sumx / (n - 1)) ^ (1 / 2) Print #2, "the calculated mean = "; average Print #2, "the standard deviation ="; stdev Close End Sub
ANSWER: the calculated mean = 0.235 the standard deviation = 5.114479E-02
3. Sub Scores() Dim students As Single, name(1 To 36) As String, ID(1 To 36) As Single, Exam1(1 To 36) As Single, Exam2(1 To 36) As Single, mean(1 To 36) As Single Dim sum1 As Single, sum2 As Single, average1 As Single, average2 As Single Open ("I:\ENGR 160 class folders\Stiehl_J1\InClass by Date\DataInput.dat") For Input As 1 Open ("U:\DataOutput.txt") For Output As 2 students = InputBox("enter how many students are in the file") sum1 = 0 sum2 = 0 For i = 1 To students Input #1, name(i) Input #1, ID(i)
Input #1, Exam1(i) Input #1, Exam2(i) sum1 = Exam1(i) + sum1 sum2 = Exam2(i) + sum2 mean(i) = (Exam1(i) + Exam2(i)) / 2 Next i average1 = sum1 / students average2 = sum2 / students
Print #2, "the class mean for exam 1 = "; average1 Print #2, "the class mean for exam2 = "; average2 For i = 1 To students Print #2, "student's name ="; name(i); Tab(15); "student's ID number ="; ID(i); Tab(15); "student score on exam 1 ="; Exam1(i); Tab(15); "student score on exam 2 ="; Exam2(i); Tab(15); "student's exam average ="; mean(i) Next i Close End Sub
the class mean for exam 1 = 84.66666 the class mean for exam2 = 78.26667 student's name =Mary student's ID number = 7853 student score on exam 1 = 92 student score on exam 2 = 84 student's exam average = 88 student's name =Sam student's ID number = 3019 student score on exam 1 = 83 student score on exam 2 = 81 student's exam average = 82 student's name =Harry student's ID number = 5219 student score on exam 1 = 92 student score on exam 2 = 82 student's exam average = 87 student's name =Tabitha student's ID number = 9630 student score on exam 1 = 89 student score on exam 2 = 75 student's exam average = 82 student's name =Rollie student's ID number = 127 student score on exam 1 = 69 student score on exam 2 = 60 student's exam average = 64.5 student's name =Martin student's ID number = 985 student score on exam 1 = 99
student score on exam 2 = 85 student's exam average = 92 student's name =Larry student's ID number = 4729 student score on exam 1 = 69 student score on exam 2 = 70 student's exam average = 69.5 student's name =Bion student's ID number = 7829 student score on exam 1 = 92 student score on exam 2 = 87 student's exam average = 89.5 student's name =Rees student's ID number = 5297 student score on exam 1 = 82 student score on exam 2 = 82 student's exam average = 82 student's name =Amanda student's ID number = 3782 student score on exam 1 = 90 student score on exam 2 = 76 student's exam average = 83 student's name =Judith student's ID number = 8294 student score on exam 1 = 84 student score on exam 2 = 73 student's exam average = 78.5 student's name =Steven student's ID number = 5207 student score on exam 1 = 73 student score on exam 2 = 75 student's exam average = 74 student's name =Verlin student's ID number = 2539 student score on exam 1 = 86 student score on exam 2 = 90 student's exam average = 88 student's name =Tamara student's ID number = 7692 student score on exam 1 = 88 student score on exam 2 = 80 student's exam average = 84 student's name =Clint student's ID number = 4829 student score on exam 1 = 82 student score on exam 2 = 74 student's exam average = 78