65.9K
CodeProject 正在变化。 阅读更多。
Home

计算器 VC++_2005

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.43/5 (10投票s)

2007年6月10日

viewsIcon

34717

downloadIcon

975

一个基于继承类的简单计算器。

Screenshot - calculator.png

引言

一个简单的计算器,使用托管 Visual C++ 在 Studio 2005 中实现。

背景


使用代码

我使用一个类来存储项目(item.h)。在这个类中,将两个数字存储在属性中,以及结果。

//
    property double nr1;
    property double nr2;

//

像 asin、cos、power、pi、加、减、除、sqrt 等操作,被编辑到从 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);
    }
    
};


// 

<<>>在基类中,我使用了 6 个布尔变量来存储之前的操作。
>

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

对于等于按钮

        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));
             }
         }


我有一个函数用于操作点击。

    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);        
             }                                   
         }


历史

第一个版本...为将来保留...

祝所有程序员一切顺利...:)
编程没有限制,唯一的限制是由我们的思想和隐藏的利益强加的...

© . All rights reserved.