Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I actually wrote this code for a calculator in visual studio 2017, under MFC application. I need help creating the code for the memory

Hello, I actually wrote this code for a calculator in visual studio 2017, under MFC application. I need help creating the code for the memory buttons (MC, MR, MS, M+, M-)

Please advise.

void Ccalculatorproject1Dlg::OnEnChangeEdtDisplay()

{

// TODO: If this is a RICHEDIT control, the control will not

// send this notification unless you override the CDialogEx::OnInitDialog()

// function and call CRichEditCtrl().SetEventMask()

// with the ENM_CHANGE flag ORed into the mask.

// TODO: Add your control notification handler code here

}

void Ccalculatorproject1Dlg::OnBnClickedBtn1()

{

// TODO: Add your control notification handler code here

m_display += _T("1");

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtnClean()

{

// TODO: Add your control notification handler code here

m_display = _T("");

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtnPi()

{

// TODO: Add your control notification handler code here

m_pi = acos(-1.);

m_display.Format(_T("%.9f"), m_pi);

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtnAdd()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

m_output = m_input;

m_display = _T("");

m_operation =0.;

}

void Ccalculatorproject1Dlg::OnBnClickedBtnEqual()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

switch (m_operation)

{

case 0:

m_output += m_input;

break;

case 1:

m_output = m_output - m_input;

break;

case 3:

m_output = m_output * m_input;

break;

case 4:

m_output = m_output / m_input;

break;

case 5:

m_output = 1 /( m_input);

break;

case 6:

m_output = (-m_input);

break;

case 7:

m_output = m_output / m_input;

break;

case 8:

m_output = pow(m_output,m_input);

break;

case 9:

m_output = pow(m_output, (1. / m_input));

break;

}

m_display.Format(_T("%.4f"), m_output);

UpdateData(false);

m_display = _T("");

}

void Ccalculatorproject1Dlg::OnBnClickedBtnSub()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

m_output = m_input;

m_display = _T("");

m_operation = 1.;

}

void Ccalculatorproject1Dlg::OnBnClickedBtnLn()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

if (m_inv == false)

{

m_output = log(m_input);

}

else

{

m_output = exp(m_input);

}

m_display.Format(_T("%.4f"), m_output);

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedChkInv()

{

// TODO: Add your control notification handler code here

UpdateData(true);

if(m_inv == false)

{

m_ln.SetWindowTextW(_T("ln(x)"));

m_sin.SetWindowTextW(_T("sin(x)"));

m_cos.SetWindowTextW(_T("cos(x)"));

m_tan.SetWindowTextW(_T("tan(x)"));

m_log.SetWindowTextW(_T("log(x)"));

m_sqrt.SetWindowTextW(_T("x^2"));

m_sqrt3.SetWindowTextW(_T("x^3"));

m_sqrty.SetWindowTextW(_T("x^y"));

}

else

{

m_ln.SetWindowTextW(_T("e^(x)"));

m_sin.SetWindowTextW(_T("arcsin(x)"));

m_cos.SetWindowTextW(_T("arccos(x)"));

m_tan.SetWindowTextW(_T("arctan(x)"));

m_log.SetWindowTextW(_T("10^(x)"));

m_sqrt.SetWindowTextW(_T("2^sqrt(x)"));

m_sqrt3.SetWindowTextW(_T("3^sqrt(x)"));

m_sqrty.SetWindowTextW(_T("y^sqrt(x)"));

}

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtnZero()

{

// TODO: Add your control notification handler code here

m_display += _T("0");

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtn2()

{

// TODO: Add your control notification handler code here

m_display += _T("2");

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtn3()

{

// TODO: Add your control notification handler code here

m_display += _T("3");

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtn4()

{

// TODO: Add your control notification handler code here

m_display += _T("4");

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtn5()

{

// TODO: Add your control notification handler code here

m_display += _T("5");

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtn6()

{

// TODO: Add your control notification handler code here

m_display += _T("6");

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtnDot()

{

// TODO: Add your control notification handler code here

m_display += _T(".");

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtn7()

{

// TODO: Add your control notification handler code here

m_display += _T("7");

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtn8()

{

// TODO: Add your control notification handler code here

m_display += _T("8");

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtn9()

{

// TODO: Add your control notification handler code here

m_display += _T("9");

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtnDiv()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

m_output = m_input;

m_display = _T("");

m_operation = 4.;

}

void Ccalculatorproject1Dlg::OnBnClickedBtnProd()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

m_output = m_input;

m_display = _T("");

m_operation = 3.;

}

void Ccalculatorproject1Dlg::OnBnClickedBtnSin()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

if (m_inv == false)

{

m_output = sin(m_input);

}

else

{

m_output = asin(m_input);

}

m_display.Format(_T("%.4f"), m_output);

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtnCos()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

if (m_inv == false)

{

m_output = cos(m_input);

}

else

{

m_output = acos(m_input);

}

m_display.Format(_T("%.4f"), m_output);

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtnTan()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

if (m_inv == false)

{

m_output = tan(m_input);

}

else

{

m_output = atan(m_input);

}

m_display.Format(_T("%.4f"), m_output);

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtnOver()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

m_output = m_input;

m_display = _T("");

m_operation = 5.;

}

void Ccalculatorproject1Dlg::OnBnClickedBtnNeg()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

m_output = m_input;

m_display = _T("");

m_operation = 6.;

}

void Ccalculatorproject1Dlg::OnBnClickedBtnLog()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

if (m_inv == false)

{

m_output = log10(m_input);

}

else

{

m_output = pow(10,m_input);

}

m_display.Format(_T("%.4f"), m_output);

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtnMod()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

m_output = m_input;

m_display = _T("");

m_operation = 7.;

}

void Ccalculatorproject1Dlg::OnBnClickedBtnSqrt2()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

if (m_inv == false)

{

m_output = pow(m_input,2);

}

else

{

m_output = sqrt(m_input);

}

m_display.Format(_T("%.4f"), m_output);

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtnSqrt3()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

if (m_inv == false)

{

m_output = pow(m_input, 3);

}

else

{

m_output = cbrt(m_input);

}

m_display.Format(_T("%.4f"), m_output);

UpdateData(false);

}

void Ccalculatorproject1Dlg::OnBnClickedBtnSqrty()

{

// TODO: Add your control notification handler code here

UpdateData(true);

m_input = _tstof(m_display);

if (m_inv == false)

{

m_output = m_input;

m_display = _T("");

m_operation = 8.;

}

else

{

m_output = m_input;

m_display = _T("");

m_operation = 9.;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago