Home

Example Application: Simple Interest

   

Introduction

This application shows how to calculate the interest accumulated on a loan and the total value that will paid at the end of the loan.

Practical LearningPractical Learning: Creating the Application

  1. To start a new application, on the main menu, click File -> New -> Project
  2. In the middle list, click Windows Application and change the Name to SimpleInterest1
  3. Click OK
  4. If the Resource View is not visible, on the main menu, click View -> Other Windows -> Resource View.
    In the Resource View, right-click the name of the project -> Add -> Resource...
  5. In the Add Resource dialog box, click Icon
     
    Add Resource
  6. Click New
  7. Design the icon as follows:
     
    Calculator
  8. Right-click 32x32, 4 bit, BMP and click Delete Image Type
  9. Design the icon as follows:
     
    Exit
  10. Right-click 32x32, 4 bit, BMP and click Delete Image Type
  11. Save all
  12. Access the form and design it as follows:
     
    Simple Interest
    Control Text Name Other Properties
    GroupBox GroupBox &Loan Preparation    
    Label Label &Principal    
    TextBox TextBox 0.00 txtPrincipal TextAlign: Right
    Label Label Interest &Rate:    
    TextBox TextBox 0.00 txtInterestRate TextAlign: Right
    Label Label %    
    Label Label Perio&ds:    
    TextBox TextBox 1 txtPeriods TextAlign: Right
    Label Label Months    
    Button Button C&alculate btnCalculate ImageAlign: TopCenter
    TextAlign: BottomCenter
    Button Button &Close btnClose ImageAlign: TopCenter
    TextAlign: BottomCenter
    GroupBox GroupBox &Results    
    Label Label Interest &Earned:    
    TextBox TextBox 0.00 txtInterestEarned TextAlign: Right
    Label Label &Future Value    
    TextBox TextBox 0.00 txtFutureValue TextAlign: Right
  13. On the form, click the Calculate button
  14. In the Properties window, click Image and click its ellipsis button
  15. In the open dialog box, locate the SimpleInterest sub-folder inside the SimpleInterest folder of the current project
  16. Select the icon that represents a calculator
     
    Open
  17. Click Open
  18. On the form, click the Close button
  19. In the Properties window, click Image and click its ellipsis button
  20. As done for the Calculate button, locate and select the other icon
  21. Click Open
  22. On the form, double-click the Calculate button and implement its Click event as follows:
    System::Void btnCalculate_Click(System::Object^  sender,
    				System::EventArgs^  e)
    {
        double Principal    = 0.00,
               InterestRate = 0.00,
               InterestEarned,
               FutureValue;
        double Periods = 0.00;
    
        try {
            Principal = double::Parse(txtPrincipal->Text);
        }
        catch(FormatException ^)
        {
            MessageBox::Show(L"The value you entered for the "
                             L"principal is not valid");
        }
    
        try {
            InterestRate = double::Parse(txtInterestRate->Text);
        }
        catch(FormatException ^)
        {
            MessageBox::Show(L"Wrong Value: The interest rate must "
                             L"be a value between 0 and 100");
        }
    
        try {
            Periods = double::Parse(txtPeriods->Text);
        }
        catch(FormatException ^)
        {
            MessageBox::Show(L"You entered an invalid value for the periods");
        }
    
        double I = InterestRate / 100;
        double p = Periods / 12;
        
    	InterestEarned = Principal * I  * p;
        FutureValue    = Principal + InterestEarned;
    
        txtInterestEarned->Text = InterestEarned.ToString(L"F");
        txtFutureValue->Text = FutureValue.ToString(L"F");
    }
  23. Return to the form and double-click the Close button
  24. Implement its Click event as follows:
    System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
    {
    	Close();
    }
  25. To execute the application, press F5
  26. Enter 22580 for the principal, 12.75 for the interest rate, and 60 for the periods
     
    Simple Interest
  27. Click Calculate
     
    Simple Interest
  28. Close the form and return to your programming environment
 
 
     
 

Home Copyright © 2011 FunctionX, Inc.