Professional Documents
Culture Documents
h file
// standard constructor
// Dialog Data
enum { IDD = IDD_CALCULATORPROJECT_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
// Implementation
protected:
HICON m_hIcon;
public:
// DDX/DDV support
Dlg.cpp File
"stdafx.h"
"CalculatorProject.h"
"CalculatorProjectDlg.h"
"math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
// DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CCalculatorProjectDlg dialog
{
}
, m_button(0)
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
END_MESSAGE_MAP()
// CCalculatorProjectDlg message handlers
BOOL CCalculatorProjectDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE);
// Set big icon
SetIcon(m_hIcon, FALSE);
// Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CCalculatorProjectDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCalculatorProjectDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND,
reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
}
CDialogEx::OnPaint();
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCalculatorProjectDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
// Operations
void CCalculatorProjectDlg::OnBnClickedBtnClean()
{
// TODO: Add your control notification handler code here
m_display = _T("");
m_data = 0.0;
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedRadio1()
{
// TODO: Add your control notification handler code here
m_mode = 0;
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedRadio2()
{
// TODO: Add your control notification handler code here
m_mode = 1;
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedChkInv()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_inv == 1)
{
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
}
else
{
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
SetDlgItemText
}
(IDC_BTN_SIN,L"asin");
(IDC_BTN_COS,L"acos");
(IDC_BTN_TAN,L"atan");
(IDC_BTN_SINH,L"asinh");
(IDC_BTN_COSH,L"acosh");
(IDC_BTN_TANH,L"atanh");
(IDC_BTN_X3RD,L"3rtx");
(IDC_BTN_XSQUARED,L"sqrt");
(IDC_BTN_XTOY,L"yrtx");
(IDC_BTN_LN,L"e^x");
(IDC_BTN_LOG,L"10^x");
(IDC_BTN_SIN,L"sin");
(IDC_BTN_COS,L"cos");
(IDC_BTN_TAN,L"tan");
(IDC_BTN_SINH,L"sinh");
(IDC_BTN_COSH,L"cosh");
(IDC_BTN_TANH,L"tanh");
(IDC_BTN_X3RD,L"x^3");
(IDC_BTN_XSQUARED,L"x^2");
(IDC_BTN_XTOY,L"x^y");
(IDC_BTN_LN,L"ln");
(IDC_BTN_LOG,L"log");
UpdateData(false);
}
// Addition subtraction multiplication division mod
void CCalculatorProjectDlg::OnBnClickedBtnAdd()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data = _tstof(m_display);
m_display = _T("");
m_operation = 1;
}
void CCalculatorProjectDlg::OnBnClickedBtnSub()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data = _tstof(m_display);
m_display = _T("");
m_operation = 2;
}
void CCalculatorProjectDlg::OnBnClickedBtnMult()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data = _tstof(m_display);
m_display = _T("");
m_operation = 3;
void CCalculatorProjectDlg::OnBnClickedBtnDiv()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data = _tstof(m_display);
m_display = _T("");
m_operation = 4;
}
void CCalculatorProjectDlg::OnBnClickedBtnEqual()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data2 = _tstof(m_display);
switch(m_operation)
{
case 1:
m_data2 += m_data;
break;
case 2:
m_data2 = m_data - m_data2;
break;
case 3:
m_data2 *= m_data;
break;
case 4:
m_data2 = m_data/m_data2;
break;
case 5:
m_data2 = pow(m_data,(1/m_data2));
break;
case 6:
m_data2 = pow(m_data,m_data2);
break;
case 7:
{
m_data = m_data/m_data2;
m_data2 = ((m_data - floor(m_data))*m_data2);
}
break;
default:
break;
}
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnMod()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data = _tstof(m_display);
m_display = _T("");
m_operation = 7;
}
// Numbers
void CCalculatorProjectDlg::OnBnClickedBtn0()
{
// TODO: Add your control notification handler code here
m_display += _T("0");
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtn1()
{
// TODO: Add your control notification handler code here
m_display += _T("1");
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtn2()
{
// TODO: Add your control notification handler code here
m_display += _T("2");
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtn3()
{
// TODO: Add your control notification handler code here
m_display += _T("3");
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtn4()
{
// TODO: Add your control notification handler code here
m_display += _T("4");
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtn5()
{
// TODO: Add your control notification handler code here
m_display += _T("5");
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtn6()
{
// TODO: Add your control notification handler code here
m_display += _T("6");
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtn7()
{
// TODO: Add your control notification handler code here
m_display += _T("7");
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtn8()
{
// TODO: Add your control notification handler code here
m_display += _T("8");
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtn9()
{
// TODO: Add your control notification handler code here
m_display += _T("9");
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnPi()
{
// TODO: Add your control notification handler code here
m_data2 = acos(-1.0);
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnDot()
{
// TODO: Add your control notification handler code here
m_display += _T(".");
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnNeg()
{
// TODO: Add your control notification handler code here
m_data2 = _tstof(m_display);
m_data2 = -m_data2;
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
//Powers Roots Log Factorial
void CCalculatorProjectDlg::OnBnClickedBtn1ox()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data2 = _tstof(m_display);
m_data2 = 1/m_data2;
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnX3rd()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data2 = _tstof(m_display);
if(m_inv == 0)
m_data2 = pow(m_data2,3);
else
m_data2 = pow(m_data2,0.33333333);
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnXtoy()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data = _tstof(m_display);
m_display = _T("");
if(m_inv == 0)
m_operation = 6;
else
m_operation = 5;
}
void CCalculatorProjectDlg::OnBnClickedBtnXsquared()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data2 = _tstof(m_display);
if(m_inv == 0)
m_data2 = pow(m_data2,2);
else
m_data2 = sqrt(m_data2);
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnLog()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data2 = _tstof(m_display);
if(m_inv == 0)
m_data2 = log10(m_data2);
else
m_data2 = pow(10,m_data2);
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnLn()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data2 = _tstof(m_display);
if(m_inv == 0)
m_data2 = log(m_data2);
else
m_data2 = exp(m_data2);
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnNfact()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data2 = _tstof(m_display);
i = m_data2;
while(i >= 2)
{
m_data2 *= (i-1);
i--;
}
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
// Triganometric
void CCalculatorProjectDlg::OnBnClickedBtnSin()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data2 = _tstof(m_display);
switch(m_mode)
{
case 0:
if(m_inv == 1)
m_data2 = asin(m_data2);
else
m_data2 = sin(m_data2);
break;
case 1:
if(m_inv == 1)
{
m_data2 = asin(m_data2);
m_data2 *= (180/pi);
}
else
{
m_data2 *= (pi/180);
m_data2 = sin(m_data2);
}
break;
default:
break;
}
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnCos()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data2 = _tstof(m_display);
switch(m_mode)
{
case 0:
case 1:
if(m_inv == 1)
m_data2 = acos(m_data2);
else
m_data2 = cos(m_data2);
break;
if(m_inv == 1)
{
m_data2 = acos(m_data2);
m_data2 *= (180/pi);
}
else
{
m_data2 *= (pi/180);
m_data2 = cos(m_data2);
}
break;
default:
break;
}
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnTan()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data2 = _tstof(m_display);
switch(m_mode)
{
case 0:
if(m_inv == 1)
m_data2 = atan(m_data2);
else
m_data2 = tan(m_data2);
break;
case 1:
if(m_inv == 1)
{
m_data2 = atan(m_data2);
m_data2 *= (180/pi);
}
else
{
m_data2 *= (pi/180);
m_data2 = tan(m_data2);
}
break;
default:
break;
}
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnSinh()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data2 = _tstof(m_display);
if(m_inv == 1)
m_data2 = asinh(m_data2);
else
m_data2 = sinh(m_data2);
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
void CCalculatorProjectDlg::OnBnClickedBtnCosh()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data2 = _tstof(m_display);
if(m_inv == 1)
m_data2 = acosh(m_data2);
else
m_data2 = cosh(m_data2);
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnTanh()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_data2 = _tstof(m_display);
if(m_inv == 1)
m_data2 = atanh(m_data2);
else
m_data2 = tanh(m_data2);
m_display.Format(_T("%.6f"), m_data2);
UpdateData(false);
}
double asinh(double x)
{
return log(x + sqrt(x * x + 1));
}
double acosh(double x)
{
return log(x +sqrt(x-1)*sqrt(x+1));
}
double atanh(double x)
{
return ((log(1+x) - log(1-x))/2);
}
//M Functions
void CCalculatorProjectDlg::OnBnClickedBtnMs()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_button = _tstof(m_display);
}
void CCalculatorProjectDlg::OnBnClickedBtnMr()
{
// TODO: Add your control notification handler code here
m_display.Format(_T("%.6f"), m_button);
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnMc()
{
// TODO: Add your control notification handler code here
m_button = 0;
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnMplus()
{
// TODO: Add your control notification handler code here
m_button += _tstof(m_display);
UpdateData(false);
}
void CCalculatorProjectDlg::OnBnClickedBtnMminus()
{
// TODO: Add your control notification handler code here
m_button -= _tstof(m_display);
UpdateData(false);
}