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
- Start Borland C++ Builder.
- Save the Project as NetPrice
in a new folder named Net Price
- Save the unit as Main
|
Designing the Application |
|
- Design the dialog box as follows:
- Set the Names of the Edit and Button controls to
Edit |
Button |
edtMarkedPrice |
btnCalculate |
edtTaxRate |
btnClose |
edtTaxAmount |
|
edtNetPrice |
|
-
Save your application.
|
Programming the Application |
|
- 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);
}
//---------------------------------------------------------------------------
|
- Test your program.
|
|
|