Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter four selected exercises with solutions. 4.2.

Similar presentations


Presentation on theme: "Chapter four selected exercises with solutions. 4.2."— Presentation transcript:

1 Chapter four selected exercises with solutions

2 4.2

3 4. 1 3 2 5 2 3 1 4 2 3

4

5 6. NE

6

7 8. Approximate Annual Wage: $20,000.00

8

9 10. If you fail to plan then you plan to fail

10

11 14. Hello Ray and Bob and Bob

12

13

14 Private Sub cmdDisplay_Click() Dim first As String, last As String, fInit As String, lInit As String 'Display initials picOutput.Cls Call InputNames(first, last) Call ExtractInitials(first, last, fInit, lInit) Call DisplayInitials(fInit, lInit) End Sub Private Sub InputNames(first As String, last As String) 'Get the persons first and last name first = InputBox("Enter your first name:") last = InputBox("Enter your last name:") End Sub

15 Private Sub ExtractInitials(first As String, last As String, fInit As String, lInit As String) 'Determine the initials of the first and last names fInit = Left(first, 1) lInit = Left(last, 1) End Sub Private Sub DisplayInitials(fInit As String, lInit As String) 'Display the initials picOutput.Print "Your initials are "; fInit; "."; lInit; "." End Sub

16 Or without calls to sub procedures Private Sub cmdDisplay_Click() Dim first As String, last As String, fInit As String, lInit As String 'Display initials picOutput.Cls first = InputBox("Enter your first name:") last = InputBox("Enter your last name:") fInit = Left(first, 1) lInit = Left(last, 1) picOutput.Print "Your initials are "; fInit; "."; lInit; "." End Sub

17

18

19 Dim total As Single 'In (Declarations) section of (General) Private Sub cmdProcessItem_Click() Dim item As String, price As Single 'Process item; display part of sales receipt Call InputData(item, price) total = total + price Call ShowData(item, price) txtItem.Text = "" txtPrice.Text = "" txtItem.SetFocus End Sub

20 Private Sub InputData(item As String, price As Single) 'Input item name and price item = txtItem.Text price = Val(txtPrice.Text) End Sub Private Sub ShowData(strItem As String, numItem As Single) 'Display data on specified line picReceipt.Print strItem; Tab(15); FormatNumber(numItem) End Sub

21 Private Sub cmdDisplay_Click() Dim tax As Single 'Display sum, tax, and total tax = total * 0.05 tax = Round(tax, 2) picReceipt.Print Tab(15); "-------" Call ShowData("Sum", total) Call ShowData("Tax", tax) Call ShowData("Total", total + tax) End Sub

22 4.3

23 4. 400

24

25 6. The day is Wed

26

27 8. 15 5

28

29

30 Private Sub cmdCalcIdealAge_Click() Dim manAge As Integer 'Calculate ideal age for wife, according to Plato picIdealAge.Cls Call InputManAge(manAge) Call ShowWifeAge(manAge) End Sub Private Sub InputManAge(manAge As Integer) manAge = Val(InputBox("Enter your age: ")) End Sub Private Sub ShowWifeAge(manAge As Integer) picIdealAge.Print "The ideal age of your wife is"; Int(manAge / 2 + 7) End Sub

31

32

33 Private Sub cmdCalculate_Click() picResult.Cls picResult.Print "Your BMI is"; BMI(Val(txtWeight), Val(txtHeight)) End Sub Private Function BMI(w As Single, h As Single) As Single 'Calculute body mass index BMI = Round(703 * w / h ^ 2) End Function


Download ppt "Chapter four selected exercises with solutions. 4.2."

Similar presentations


Ads by Google