Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++/CLI

Calculator VC++_2005

1.43/5 (13 votes)
10 Jun 2007 1   956  
A simple calculator based on inheritance class
Screenshot - calculator.png

Introduction

A simple calculator with managed visual c++ in studio 2005.

Background


Using the code

I used a class for items(item.h) . In this class are stored the two number into property and the result:

//
    property double nr1;
    property double nr2;

//

The operations like :asin,cos,power,pi,plu,divide,sqrt etc. are edited into inherited class from items:

//
#pragma once
#include "Items.h"

using namespace System;

public ref class asinus : public Items
{
public:

    asinus(void)
    {
        
    }

    double^ asin(double a)
    {        
        return Math::Asin(a);
    }
    
};


// 

<<>>In the base class i used 6 boolean variable for the precedent operation:
>

bool plus;
bool minus;
bool produs;
bool divide;
bool sin;
bool prec;

For button equal:

private: System::Void btnegal_Click(System::Object^  sender, System::EventArgs^  e)
 {
     prec = false;

     if(plus == true)
     {
         this->txtRes->Text = Convert::ToString(p.aduna(i.nr1,i.nr2));
     }
     else if(minus == true)
     {
        this->txtRes->Text = Convert::ToString(m.scadere(i.nr1,i.nr2));
     }
     else if(produs == true)
     {
        this->txtRes->Text = Convert::ToString(pr.inmultire(i.nr1,i.nr2));
     }
     else if(divide == true)
     {
        this->txtRes->Text = Convert::ToString(d.impartire(i.nr1,i.nr2));
     }
 }

I have a function for operaton click:

private: System::Void Operation_Click(System::Object^  sender, System::EventArgs^  e)
     {
         if(prec == false)
         {
            i.nr1 = Convert::ToDouble(this->txtRes->Text);
         }
         if(prec == true)
         {
            i.nr2 = Convert::ToDouble(this->txtRes->Text);
         }
     }


History

The first version...keeping for future ...

All ze best for all programmers ...:)
The programming no have limits, only limit is imposed by our minds and hidden benefits ...

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here