Calculator program:


    

1.Resource view->Dialog:


              2.CalculatorDlg.h : headerfile

// Implementation

                public:

                                int oper;

                                      int operand;
3.Double Click each button & type code:
     

void CCalculatorDlg::OnButton1()

{

                UpdateData(TRUE);

                m_text=m_text*10+1;

                UpdateData(FALSE);

}               // same as like this for upto 9,0 buttons..

void CCalculatorDlg::OnButton11()   // clear button

{

UpdateData(TRUE);

m_text=0;

UpdateData(FALSE);      

}

void CCalculatorDlg::OnButton12()                   // = button

{

UpdateData(TRUE);

switch(oper)

 {

                 case 1:

                                 m_text=operand+m_text;

                                 break;

                 case 2:

         m_text=operand-m_text;

                                 break;

                 case 3:

         m_text=operand*m_text;

                                 break;

                 case 4:

                                 if(m_text==0)

                                                 AfxMessageBox(“divide by zero error”);

                                 else

                                                 m_text=operand/m_text;

                                 break;

                 case 5:

                                 m_text=operand*operand;

                                 break;

                 case 6:

                                                 m_text=operand*operand*operand;

                                                 break;

                 case 7:

                                 m_text=operand%m_text;

 }

 UpdateData(FALSE);     

}

void CCalculatorDlg::OnButton13()    //+ button

{

UpdateData(TRUE);

 operand=m_text;

 m_text=0;

 oper=1;

 UpdateData(FALSE);     

}

void CCalculatorDlg::OnButton14()               //- button

{

UpdateData(TRUE);

 operand=m_text;

 m_text=0;

 oper=2;

 UpdateData(FALSE);     

}

void CCalculatorDlg::OnButton15()     // * button

{

UpdateData(TRUE);

 operand=m_text;

 m_text=0;

 oper=3;

 UpdateData(FALSE);     

}

void CCalculatorDlg::OnButton16()   // / button

{

UpdateData(TRUE);

 operand=m_text;

 m_text=0;

 oper=4;

 UpdateData(FALSE);     

}

void CCalculatorDlg::OnButton17()  // X2 button

{

UpdateData(TRUE);

 operand=m_text;

  oper=5;

 UpdateData(FALSE);     

}

void CCalculatorDlg::OnButton18()  // x3 button

{

UpdateData(TRUE);

 operand=m_text;

 oper=6;

 UpdateData(FALSE);     

}

void CCalculatorDlg::OnButton19()  // % button

{

UpdateData(TRUE);

 operand=m_text;

 m_text=0;

 oper=7;

 UpdateData(FALSE);     

}