1 / 33

Chapter four selected exercises with solutions

Chapter four selected exercises with solutions. 4.2. 4. 1 3 2 5 2 3 1 4 2 3. 6. NE. 8. Approximate Annual Wage: $20,000.00. 10. If you fail to plan then you plan to fail. 14. Hello Ray and Bob and Bob. Private Sub cmdDisplay_Click()

Download Presentation

Chapter four selected exercises with solutions

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. Chapter four selected exercises with solutions

  2. 4.2

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

  4. 6. NE

  5. 8. Approximate Annual Wage: $20,000.00

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

  7. 14. Hello Ray and Bob • and Bob

  8. 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

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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

  14. 4.3

  15. 4. 400

  16. 6. The day is Wed

  17. 8. 15 5

  18. 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

  19. 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

More Related