Lab #2

Lab #2 - Book Sale Calculator

Submit Assignment Download Work file Download Runtime

  • Be sure to include comments at the top of each procedure and at the top of the file.
  • Be sure to use meaningful names for all buttons and labels.
  1. In this project, R 'n R Refreshment needs to expand the book sale project done previously.  In addition to calculating individual sales and discounts, management wants to know the total number of books sold, the total number of discounts given, the total discounted amount, and the average discount per sale.

    Add error handling to the program, so that missing or nonnumeric data will not cause a run-time error.

  2. Planning the Form

      

  3. Planning Objects and Properties

    ObjectPropertySetting
    Main FormNameBookSaleForm
    TextR 'n R - For Reading and Refreshment
    StartPositionCenterScreen
    AcceptButtonCalculateButton
    CancelButtonClearButton
    Label1TextBook Sales
    FontBold, 12 point
    GroupBox1Textblank
    Label2Text&Quantity
    QuantityTextBoxNameQuantityTextBox
    Textblank
    Label3Text&Title
    TitleTextBoxNameTitleTextBox
    Textblank
    Label4Text&Price
    PriceTextBoxNamePriceTextBox
    Textblank
    GroupBox2NameGroupBox2
    Textblank
    Label5TextExtended Price
    ExtendedPriceTextBoxNameExtendedPriceTextBox
    Textblank
    ReadOnlytrue
    TextAlignRight
    Label6Text15% Discount
    DiscountTextBoxNameDiscountTextBox
    Textblank
    ReadOnlytrue
    TextAlignRight
    Label7TextDiscounted Price
    DiscountedPriceTextBoxNameDiscountedPriceTextBox
    Textblank
    TextAlignRight
    ReadOnlytrue
    Calculate ButtonNameCalculateButton
    Text&Calculate
    ClearButtonNameClearButton
    TextClear &Sale
    ExitButtonNameExitButton
    TextE&xit
    GroupBox3NameGroupBox3
    TextSummary
    Label8TextTotal Number of Books
    QuantitySumTextBoxNameQuantitySumTextBox
    Textblank
    ReadOnlytrue
    TextAlignRight
    Label9TextTotal Discounts Given
    DiscountSumTextBoxNameDiscountSumTextBox
    Textblank
    ReadOnlyTrue
    TextAlignRight
    Label10TextTotal Discounted Amounts
    DiscountedAmountSumTextBoxNameDiscountedAmountSumTextBox
    Textblank
    ReadOnlytrue
    TextAlignRight
    Label11TextAverageDiscount
    AverageDiscountTextBoxNameAverageDiscountTextBox
    Textblank
    ReadOnlytrue
    TextAlignRight
  4. Planning Event Procedures

    ProcedureActions - Pseudocode
    ExitButton_ClickEnd the project
    ClearButton_ClickClear each text box except Summary fields
    Set the focus in the first text box
    CalculateButton_ClickDeclare the variables
    Try
      Convert the input Quantity to number.
      Try
        Convert the input Price to numeric
        Calculate Extended Price = Quantity * Price
        Calculate Discount = Extended Price * Discount Rate
        Calculate Discounted Price = Extended Price - Discount
        Calculate the summary values:
        Add Quantity to Quantity Sum
        Add Discount to Discount Sum
        Add Discounted Price to Discounted Price Sum
        Add 1 to Sale Count
        Calculate Average Discount = Discount Sum / Sale Count
        Format and display sale output
        Format and display summary values
      Catch any Price exception
        Display error message and reset the focus to Price
      Catch any Quantity Exception
        Display error message and reset the focus to Quantity
    Catch any generic exception
      Display error message