chapter four selected exercises with solutions. 4.2

33
Chapter four selected exercises with solutions

Upload: doreen-kelley

Post on 16-Jan-2016

230 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter four selected exercises with solutions. 4.2

Chapter four selected exercises with solutions

Page 2: Chapter four selected exercises with solutions. 4.2

4.2

Page 3: Chapter four selected exercises with solutions. 4.2

4. 1 3

2 5

2 3

1 4

2 3

Page 4: Chapter four selected exercises with solutions. 4.2
Page 5: Chapter four selected exercises with solutions. 4.2

6. NE

Page 6: Chapter four selected exercises with solutions. 4.2
Page 7: Chapter four selected exercises with solutions. 4.2

8. Approximate Annual Wage: $20,000.00

Page 8: Chapter four selected exercises with solutions. 4.2
Page 9: Chapter four selected exercises with solutions. 4.2

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

Page 10: Chapter four selected exercises with solutions. 4.2
Page 11: Chapter four selected exercises with solutions. 4.2

14. Hello Ray and Bob

and Bob

Page 12: Chapter four selected exercises with solutions. 4.2
Page 13: Chapter four selected exercises with solutions. 4.2
Page 14: Chapter four selected exercises with solutions. 4.2

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

Page 15: Chapter four selected exercises with solutions. 4.2

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

Page 16: Chapter four selected exercises with solutions. 4.2

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

Page 17: Chapter four selected exercises with solutions. 4.2
Page 18: Chapter four selected exercises with solutions. 4.2
Page 19: Chapter four selected exercises with solutions. 4.2

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.SetFocusEnd Sub

Page 20: Chapter four selected exercises with solutions. 4.2

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

Page 21: Chapter four selected exercises with solutions. 4.2

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

Page 22: Chapter four selected exercises with solutions. 4.2

4.3

Page 23: Chapter four selected exercises with solutions. 4.2

4. 400

Page 24: Chapter four selected exercises with solutions. 4.2
Page 25: Chapter four selected exercises with solutions. 4.2

6. The day is Wed

Page 26: Chapter four selected exercises with solutions. 4.2
Page 27: Chapter four selected exercises with solutions. 4.2

8. 15 5

Page 28: Chapter four selected exercises with solutions. 4.2
Page 29: Chapter four selected exercises with solutions. 4.2
Page 30: Chapter four selected exercises with solutions. 4.2

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

Page 31: Chapter four selected exercises with solutions. 4.2
Page 32: Chapter four selected exercises with solutions. 4.2
Page 33: Chapter four selected exercises with solutions. 4.2

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