The source code of a calculator class is very simple. Don't laugh!

Source: Internet
Author: User


// Namespace MyCalClass
// Class Name: CalClass
// The constructor CalClass () without Parameters ()
// 6 private variables used
// Void PointClick () by decimal point
// String CE () is used for resetting the calculator. The clear Function
// String BackSpace (string Txt) regressing key. The parameter is the calculation result displayed during calculation.
// String NumClick (string Txt, int NumKey) 0-9 numeric key press response, Txt is the calculation result, and NumKey is the numeric value pressed
// String OpClick (string Txt, int OpKey) +,-, *,/, = processing when several keys are pressed. Txt is the current calculation result, opKey is the numeric ID for pressing the operation key.
Namespace MyCalClass
{
Public class CalClass
{
Private string ResultTxt; // Get and Show The Result of the TextBox in application
Private bool PointIsDown; // If the radix point was clicked;
Private double MidResult; // To Store middle results
Private double Results; // To store finally result
Private int LastClick; // To sign last clicking button class, is number (1) or operator (2)
Private int LastOperator; // To sign last clicked button of operator is who? 0 is Null, 1 is +, 2 is-, 3 is *, 4 is/, 5 is =;
Public CalClass ()
{
ResultTxt = "0 .";
PointIsDown = false;
MidResult = 0;
Results = 0;
LastClick = 0;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.