1 / 16

Quiz 1

Quiz 1. What is the Output of this code fragment when N = 85 (3 Marks) [5 Minutes] A = N 10 B = N Mod 10 C = 0 If (N Mod 2 = 0) Then C = C + 1 Else C = C + 2 End If If (A > 5) And (B > 5) Then C = C + 3 ElseIf (A > 5) Or (B > 5) Then C = C + 5 Else C = C + 6

benard
Télécharger la présentation

Quiz 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Quiz 1

  2. What is the Output of this code fragment when N = 85 (3 Marks) [5 Minutes] A = N \ 10 B = N Mod 10 C = 0 If (N Mod 2 = 0) Then C = C + 1 Else C = C + 2 End If If (A > 5) And (B > 5) Then C = C + 3 ElseIf (A > 5) Or (B > 5) Then C = C + 5 Else C = C + 6 End If N = B * 100 + C * 10 + A MsgBox ("N = " & N)

  3. Example 1 Cones and Cylinders

  4. Problem 1 • Find the surface area of a cylinder with a given radius and height • Area of top and bottom is a circle • Area Top = Area Bottom = r2 • Area of side Circumference * Height • Area Side = 2rh • Total Area • Area = 2r2 + 2rh = 2r (r + h)

  5. Name : Cylinder Given : r h Results : A Intermediate : None Definition A := Cylinder(r, h) Get r Get h A = 2r(r + h) Give A Algorithm Cylinder

  6. Problem 2 • Find the surface area of a cone, of given radius and height • Area = r (r + s) • Where s = (r2 + h2) • This came from an internet research

  7. Name : Cone Given : r, h Results : A Intermediate: S Definition A := Cone (r, h) Get r Get h s = sqrt(r^2 + h^2) A = r (r + s) Give A Cone Algorithm

  8. Problem 3 • You are in charge of ordering supplies for Fennell Funnel Co. • You need to order the plastic pellets for the manufacturing process. • Calculate the volume of plastic needed if you know, • the diameter of the top, and bottom • the length of the cone, and the spout • the thickness of the walls • You may assume the “extra” is needed in the manufacturing process

  9. Name: Funnel Given: Dtop, Htop, Dbot, Hbot, t Results : Vol Intermediates: Acone, Acyl Definition Vol :=Funnel(Dtop, Htop, Dbot, Hbot, t) Get Dtop, Htop Get Dbot, Hbot Get t Acone: = Cone(Dtop/2, Htop) Acyl := Cylinder(Dbot/2, Hbot) Vol = t * (Acone + Acyl) Give Vol Funnel Algorithm

  10. Write these three algorithms using Subroutines

  11. Get r (from a SUB) Get h (from a SUB) A = 2r(r + h) Give A Sub Cylinder (ByVal r as Single, ByVal h as Single Cylinder

  12. Get r (from a SUB) Get h (from a SUB) A = 2r(r + h) Give A (to a SUB) Sub Cylinder (ByVal r as Single, ByVal h as Single, ByRef A as Single) Const Pi = 3.14159 A = 2*Pi*r * (r + h) End Sub Cylinder

  13. Get r (from SUB) Get h (from SUB) s = sqrt(r^2 + h^2) A = r (r + s) Give A SUB Cone (ByVal r as Single, ByVal h as Single, Cone

  14. Get r (from SUB) Get h (from SUB) s = sqrt(r^2 + h^2) A = r (r + s) Give A (to SUB) Sub Cone (ByVal r as Single, ByVal h as Single, ByRef A as Single) Const Pi = 3.14159 Dim s as Single s = (r^2 + h^2)^(1/2) A = pi * r * (r + s) End Sub Cone

  15. Get Dtop, Htop Get Dbot, Hbot Get t Acone: = Cone(Dtop/2, Htop) Acyl := Cylinder(Dbot/2, Hbot) Vol = t * (Acone + Acyl) Give Vol Sub Funnel ( ) Dim Dtop as Single Dim Htop as Single Dim Dbot as Single Dim Hbot as Single Dim t as Single Dim Acone as Single Dim Acyl as Single Dim Vol as Single Dtop = InputBox(“Dtop”) Htop = InputBox (“Htop”) Dbot = InputBox(“Dbot”) Htop = InputBox (“Hbot”) t = InputBox(“t”) Call Cone(Dtop/2, Htop, Acone) Call Cylinder(Dbot/2, Hbot, Acyl) Vol = t * (Acone + Acyl) MsgBox (“Vol = “ & Format(Vol,0)) End Sub Funnel

  16. Tools Macro Run Funnel • View • ToolBars • Command • Add Button • do a Call Funnel() • Change caption to Run Macro Funnel • This is not as direct as Excel

More Related