Net Price Calculation

Introduction

Items in a department store or any other store usually display the price of an item. Customers take such an item to the cashier who rings it, applies the tax rate and present the total price to the customer.

The marked price, the price presented on an item, is in currency value. An example would be $120.95

The tax rate is expressed as a percentage value. An example would be 5.75%

The computer used to evaluate the price use a formula such as:

Tax Amount = Marked Price / Tax Rate

The net price, the actual price a customer should pay, is calculated as:

Net Price = Marked Price + Tax Amount

In this exercise, we will simulate such a calculation

Starting the Application

  1. Start Borland C++ Builder.
  2. Save the Project as NetPrice in a new folder named Net Price
  3. Save the unit as Main
 

Designing the Application

  1. Design the dialog box as follows:
     
  2. Set the Names of the Edit and Button controls to
     
    Edit Button
    edtMarkedPrice btnCalculate
    edtTaxRate btnClose
    edtTaxAmount  
    edtNetPrice  
  3. Save your application.

Programming the Application

  1. On the form, double-click the Calculate button and implement its event as follows:
     
    //---------------------------------------------------------------------------
    void __fastcall TForm1::btnCloseClick(TObject *Sender)
    {
        Close();
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::btnCalculateClick(TObject *Sender)
    {
        double MarkedPrice, TaxRate, TaxAmount, NetPrice;
    
    	MarkedPrice = StrToFloat(edtMarkedPrice->Text);
    	TaxRate		= StrToFloat(edtTaxRate->Text) / 100;
    
    	TaxAmount	= MarkedPrice * TaxRate;
    	NetPrice	= MarkedPrice + TaxAmount;
    
    	edtTaxAmount->Text = FloatToStrF(TaxAmount, ffCurrency, 6, 2);
    	edtNetPrice->Text  = FloatToStrF(NetPrice, ffCurrency, 6, 2);
    }
    //---------------------------------------------------------------------------
  2. Test your program.

 

Home Copyright © 2003-2007 FunctionX, Inc. FunctionX