⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calculator.cpp

📁 PocketPC下的计算器
💻 CPP
字号:
// Calculator.cpp: implementation of the CCalculator class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Calculator.h"

#include <math.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

//##ModelId=3FEBDE950247
CCalculator::CCalculator(CWnd *pWnd)
{
	m_pNotifyWnd=pWnd;

	Clear();
}

//##ModelId=3FEBDE950252
CCalculator::~CCalculator()
{
}

void CCalculator::Point()
{
	if(m_nPoint == 0)
		m_nPoint=1;
}

//##ModelId=3FEBDE950254
double CCalculator::Digit(int d)
{
	if(m_nPoint == 0)
		m_fOP2=m_fOP2*10.0+(double)d;
	else
	{
		m_fOP2=m_fOP2+(double)d/pow(10.0,m_nPoint);
		m_nPoint++;
	}

	Notify(1,m_fOP2);

	return m_fOP2;
}

double CCalculator::Operator(CCalculator::OP op)
{
	m_nPoint=0;

	if(op < OP_OPERATOR1)
	{
		m_fDisp=Operator2(op);
	}
	else
	{
		m_fDisp=Operator1(op);
	}

	Notify(0,m_fDisp);

	return m_fDisp;
}

double CCalculator::Operator1(CCalculator::OP op)
{
	Operator2(m_op);

	switch(op)
	{
	case OP_EXP:
		m_fOP1=exp(m_fOP1);
		break;
	case OP_SQRT:
		m_fOP1=sqrt(m_fOP1);
		break;
	case OP_INV:
		m_fOP1=-1.0*m_fOP1;
		break;
	case OP_DIV2:
		m_fOP1=1.0/m_fOP1;
		break;
	case OP_LOG:
		m_fOP1=log(m_fOP1);
		break;
	case OP_SIN:
		m_fOP1=sin(m_fOP1);
		break;
	case OP_COS:
		m_fOP1=cos(m_fOP1);
		break;
	case OP_TAN:
		m_fOP1=tan(m_fOP1);
		break;
	case OP_CTAN:
		m_fOP1=1.0/tan(m_fOP1);
		break;
	}

	m_fOP2=0.0f;
	m_op=OP_PLUS;

	return m_fOP1;
}

double CCalculator::Operator2(CCalculator::OP op)
{
	switch(m_op)
	{
	case OP_PLUS:
		m_fOP1=m_fOP1+m_fOP2;
		break;
	case OP_MINUS:
		m_fOP1=m_fOP1-m_fOP2;
		break;
	case OP_MUL:
		m_fOP1=m_fOP1*m_fOP2;
		break;
	case OP_DIV:
		m_fOP1=m_fOP1/m_fOP2;
		break;
	}
	m_fOP2=0.0f;
	m_op=op;

	return m_fOP1;
}

//##ModelId=3FEBDE950281
void CCalculator::Clear()
{
	m_fDisp=m_fOP2=m_fOP1=0.0;
	m_op=OP_PLUS;
	m_nPoint=0;

	Notify(1,m_fOP2);
}

//##ModelId=3FEBDE950282
void CCalculator::LocalClear()
{
	m_fOP2=0.0;
	m_nPoint=0;

	Notify(1,m_fOP2);
}

//##ModelId=3FEBDE950290
double CCalculator::Equal()
{
	Notify(0,Operator2(OP_PLUS));

	return m_fOP1;
}

//##ModelId=3FEBDE950291
void CCalculator::Notify(int type,double val)
{
	if(m_pNotifyWnd != NULL)
	{
		m_fDisp=val;
		switch(type)
		{
		case 1:
			m_pNotifyWnd->PostMessage(CALC_UPDATE);
		case 0:
			m_pNotifyWnd->PostMessage(CALC_RESULT);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -