Study Case in Computer Fundamentals and Programming: Submitted By: G5
Study Case in Computer Fundamentals and Programming: Submitted By: G5
Study Case in Computer Fundamentals and Programming: Submitted By: G5
Study Case in
Computer Fundamentals
and Programming
Submitted By: G5
Allan Bernard Dela Vega
(BSCE-II)
Jerome Laudeza
(BSEE-II)
Submitted To:
Mr. Ferdinand Rabina
(Instructor)
Source Code:
// VCPP_11Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "VCPP_11.h"
#include "VCPP_11Dlg.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVCPP_11Dlg dialog
BEGIN_MESSAGE_MAP(CVCPP_11Dlg, CDialog)
//{{AFX_MSG_MAP(CVCPP_11Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_ONE, OnBtnOne)
ON_BN_CLICKED(IDC_BTN_TWO, OnBtnTwo)
ON_BN_CLICKED(IDC_BTN_THREE, OnBtnThree)
ON_BN_CLICKED(IDC_BTN_FOUR, OnBtnFour)
ON_BN_CLICKED(IDC_BTN_FIVE, OnBtnFive)
ON_BN_CLICKED(IDC_BTN_SIX, OnBtnSix)
ON_BN_CLICKED(IDC_BTN_SEVEN, OnBtnSeven)
ON_BN_CLICKED(IDC_BTN_EIGHT, OnBtnEight)
ON_BN_CLICKED(IDC_BTN_NINE, OnBtnNine)
ON_BN_CLICKED(IDC_BTN_ZERO, OnBtnZero)
ON_BN_CLICKED(IDC_BTN_POINT, OnBtnPoint)
ON_BN_CLICKED(IDC_BTN_PLUS, OnBtnPlus)
ON_COMMAND(IDR_HELP_ABOUT, OnHelpAbout)
ON_BN_CLICKED(IDC_BTN_EQUAL, OnBtnEqual)
ON_BN_CLICKED(IDC_BTN_ON, OnBtnOn)
ON_BN_CLICKED(IDC_BTN_CE, OnBtnCe)
ON_BN_CLICKED(IDC_BTN_BACKSPACE, OnBtnBackspace)
ON_COMMAND(IDR_FILE_EXIT, OnFileExit)
ON_BN_CLICKED(IDC_BTN_DIVIDE, OnBtnDivide)
ON_BN_CLICKED(IDC_BTN_MULTIPLY, OnBtnMultiply)
ON_BN_CLICKED(IDC_BTN_MINUS, OnBtnMinus)
ON_BN_CLICKED(IDC_BTN_REMAINDER, OnBtnRemainder)
ON_BN_CLICKED(IDC_BTN_PLUSMINUS, OnBtnPlusminus)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVCPP_11Dlg message handlers
BOOL CVCPP_11Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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);
SetIcon(m_hIcon, FALSE);
m_strValue="0";
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
}
CDialog::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 CVCPP_11Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CVCPP_11Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CVCPP_11Dlg::OnBtnOne()
{
// TODO: Add your control notification handler code here
UpdateData( );
if(m_bFlag==true)
{
m_strValue="";
m_bFlag=false;
}
if(m_nFlag==1 || m_nFlag==3)
m_nFlag=2;
if(m_strValue=="0")
m_strValue="1";
else
m_strValue+="1";
UpdateData(false);
}
void CVCPP_11Dlg::OnBtnTwo()
{
// TODO: Add your control notification handler code here
UpdateData( );
if(m_bFlag==true)
{
m_strValue="";
m_bFlag=false;
}
if(m_nFlag==1 || m_nFlag==3)
m_nFlag=2;
if(m_strValue=="0")
m_strValue="2";
else
m_strValue+="2";
UpdateData(false);
}
void CVCPP_11Dlg::OnBtnThree()
{
// TODO: Add your control notification handler code here
UpdateData( );
if(m_bFlag==true)
{
m_strValue="";
m_bFlag=false;
}
if(m_nFlag==1 || m_nFlag==3)
m_nFlag=2;
if(m_strValue=="0")
m_strValue="3";
else
m_strValue+="3";
UpdateData(false);
}
void CVCPP_11Dlg::OnBtnFour()
{
// TODO: Add your control notification handler code here
UpdateData( );
if(m_bFlag==true)
{
m_strValue="";
m_bFlag=false;
}
if(m_nFlag==1 || m_nFlag==3)
m_nFlag=2;
if(m_strValue=="0")
m_strValue="4";
else
m_strValue+="4";
UpdateData(false);
}
void CVCPP_11Dlg::OnBtnFive()
{
// TODO: Add your control notification handler code here
UpdateData( );
if(m_bFlag==true)
{
m_strValue="";
m_bFlag=false;
}
if(m_nFlag==1 || m_nFlag==3)
m_nFlag=2;
if(m_strValue=="0")
m_strValue="5";
else
m_strValue+="5";
UpdateData(false);
}
void CVCPP_11Dlg::OnBtnSix()
{
// TODO: Add your control notification handler code here
UpdateData( );
if(m_bFlag==true)
{
m_strValue="";
m_bFlag=false;
}
if(m_nFlag==1 || m_nFlag==3)
m_nFlag=2;
if(m_strValue=="0")
m_strValue="6";
else
m_strValue+="6";
UpdateData(false);
}
void CVCPP_11Dlg::OnBtnSeven()
{
// TODO: Add your control notification handler code here
UpdateData( );
if(m_bFlag==true)
{
m_strValue="";
m_bFlag=false;
}
if(m_nFlag==1 || m_nFlag==3)
m_nFlag=2;
if(m_strValue=="0")
m_strValue="7";
else
m_strValue+="7";
UpdateData(false);
}
void CVCPP_11Dlg::OnBtnEight()
{
// TODO: Add your control notification handler code here
UpdateData( );
if(m_bFlag==true)
{
m_strValue="";
m_bFlag=false;
}
if(m_nFlag==1 || m_nFlag==3)
m_nFlag=2;
if(m_strValue=="0")
m_strValue="8";
else
m_strValue+="8";
UpdateData(false);
}
void CVCPP_11Dlg::OnBtnNine()
{
// TODO: Add your control notification handler code here
UpdateData( );
if(m_bFlag==true)
{
m_strValue="";
m_bFlag=false;
}
if(m_nFlag==1 || m_nFlag==3)
m_nFlag=2;
if(m_strValue=="0")
m_strValue="9";
else
m_strValue+="9";
UpdateData(false);
}
void CVCPP_11Dlg::OnBtnZero()
{
// TODO: Add your control notification handler code here
UpdateData( );
if(m_bFlag==true)
{
m_strValue="";
m_bFlag=false;
}
if(m_nFlag==1 || m_nFlag==3)
m_nFlag=2;
if(m_strValue=="0")
m_strValue="0";
else
m_strValue+="0";
UpdateData(false);
}
void CVCPP_11Dlg::OnBtnPoint()
{
// TODO: Add your control notification handler code here
UpdateData( );
if(m_bFlag==true)
{
m_strValue="";
m_bFlag=false;
}
if(m_nFlag==1 || m_nFlag==3)
m_nFlag=2;
int length=m_strValue.GetLength();
int flag=0;
for(int count=0;count<length;count++)
{
if(m_strValue.GetAt(count)=='.')
flag++;
}
if(flag==0)
m_strValue+=".";
UpdateData(false);
void CVCPP_11Dlg::OnBtnPlus()
{
// TODO: Add your control notification handler code here
UpdateData( );
m_bFlag=true;
if(m_nFlag==0 || m_nFlag==3)
{
char *Ptr;
m_dOperand_1=strtod(m_strValue,&Ptr);
m_nFlag=1;
}
else if(m_nFlag==2)
{
char *Ptr;
m_dOperand_2=strtod(m_strValue,&Ptr);
double result=(m_dOperand_1+m_dOperand_2);
char aValue[50]={NULL};
gcvt(result,25,aValue);
m_strValue=aValue;
m_dOperand_1=result;
m_nFlag=3;
}
m_cOperator='+';
UpdateData(false);
GetDlgItem(IDC_SCREEN)->SetFocus( );
}
void CVCPP_11Dlg::OnHelpAbout()
{
// TODO: Add your command handler code here
CAboutDlg dlgAbout;
dlgAbout.DoModal( );
}
void CVCPP_11Dlg::OnBtnEqual()
{
// TODO: Add your control notification handler code here
if((m_nFlag==2 || m_nFlag==3) && m_cOperator!='|')
{
UpdateData( );
char *ptr=NULL;
double temp=m_dOperand_1;
else
m_dOperand_2=strtod(m_strValue,&ptr);
double result=0;
switch(m_cOperator)
{
case '+' : result=(m_dOperand_1+m_dOperand_2);
break;
char Buffer[50]={NULL};
gcvt(result,25,Buffer);
m_strValue=Buffer;
else if(m_nFlag==2)
m_dOperand_1=m_dOperand_2;
else
m_nFlag=3;
m_bFlag=true;
UpdateData(false);
GetDlgItem(IDC_SCREEN)->SetFocus( );
}
}
void CVCPP_11Dlg::OnBtnOn()
{
// TODO: Add your control notification handler code here
m_nFlag=0;
m_bFlag=false;
m_strValue="0";
m_cOperator=NULL;
m_dOperand_1=0;
m_dOperand_2=0;
UpdateData(false);
}
void CVCPP_11Dlg::OnBtnCe()
{
// TODO: Add your control notification handler code here
if(m_nFlag==0 || m_nFlag==2)
m_strValue="0";
UpdateData(false);
}
void CVCPP_11Dlg::OnBtnBackspace()
{
// TODO: Add your control notification handler code here
return true;
}
else if(pMsg->wParam==107)
{
OnBtnPlus( );
return true;
}
else if(pMsg->wParam==96)
{
OnBtnZero( );
return true;
}
else if(pMsg->wParam==97)
{
OnBtnOne( );
return true;
}
else if(pMsg->wParam==98)
{
OnBtnTwo( );
return true;
}
else if(pMsg->wParam==99)
{
OnBtnThree( );
return true;
}
else if(pMsg->wParam==100)
{
OnBtnFour( );
return true;
}
else if(pMsg->wParam==101)
{
OnBtnFive( );
return true;
}
else if(pMsg->wParam==102)
{
OnBtnSix( );
return true;
}
else if(pMsg->wParam==103)
{
OnBtnSeven( );
return true;
}
else if(pMsg->wParam==104)
{
OnBtnEight( );
return true;
}
else if(pMsg->wParam==105)
{
OnBtnNine( );
return true;
}
else if(pMsg->wParam==110)
{
OnBtnPoint( );
return true;
}
else if(pMsg->wParam==106)
{
OnBtnMultiply( );
return true;
}
else if(pMsg->wParam==109)
{
OnBtnMinus( );
return true;
}
else if(pMsg->wParam==111)
{
OnBtnDivide( );
return true;
}
else if(pMsg->wParam==53)
{
OnBtnRemainder( );
return true;
}
else if(pMsg->wParam==120)
{
OnBtnPlusminus( );
return true;
}
else if(pMsg->wParam==8)
{
OnBtnBackspace( );
return true;
}
else if(pMsg->wParam==27)
{
OnBtnOn( );
return true;
}
else if(pMsg->wParam==46)
{
OnBtnCe( );
return true;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CVCPP_11Dlg::OnFileExit()
{
// TODO: Add your command handler code here
SendMessage(WM_CLOSE);
}
void CVCPP_11Dlg::OnBtnDivide()
{
// TODO: Add your control notification handler code here
UpdateData( );
m_bFlag=true;
if(m_nFlag==0 || m_nFlag==3)
{
char *Ptr;
m_dOperand_1=strtod(m_strValue,&Ptr);
m_nFlag=1;
}
else if(m_nFlag==2)
{
char *Ptr;
m_dOperand_2=strtod(m_strValue,&Ptr);
double result=(m_dOperand_2/m_dOperand_1);
char aValue[50]={NULL};
gcvt(result,25,aValue);
m_strValue=aValue;
m_dOperand_1=result;
m_nFlag=3;
}
m_cOperator='/';
UpdateData(false);
GetDlgItem(IDC_SCREEN)->SetFocus( );
}
void CVCPP_11Dlg::OnBtnMultiply()
{
// TODO: Add your control notification handler code here
UpdateData( );
m_bFlag=true;
if(m_nFlag==0 || m_nFlag==3)
{
char *Ptr;
m_dOperand_1=strtod(m_strValue,&Ptr);
m_nFlag=1;
}
else if(m_nFlag==2)
{
char *Ptr;
m_dOperand_2=strtod(m_strValue,&Ptr);
double result=(m_dOperand_1*m_dOperand_2);
char aValue[50]={NULL};
gcvt(result,25,aValue);
m_strValue=aValue;
m_dOperand_1=result;
m_nFlag=3;
}
m_cOperator='*';
UpdateData(false);
GetDlgItem(IDC_SCREEN)->SetFocus( );
}
void CVCPP_11Dlg::OnBtnMinus()
{
// TODO: Add your control notification handler code here
UpdateData( );
m_bFlag=true;
if(m_nFlag==0 || m_nFlag==3)
{
char *Ptr;
m_dOperand_1=strtod(m_strValue,&Ptr);
m_nFlag=1;
}
else if(m_nFlag==2)
{
char *Ptr;
m_dOperand_2=strtod(m_strValue,&Ptr);
double result=(m_dOperand_1-m_dOperand_2);
char aValue[50]={NULL};
gcvt(result,25,aValue);
m_strValue=aValue;
m_dOperand_1=result;
m_nFlag=3;
}
m_cOperator='-';
UpdateData(false);
GetDlgItem(IDC_SCREEN)->SetFocus( );
}
void CVCPP_11Dlg::OnBtnRemainder()
{
// TODO: Add your control notification handler code here
UpdateData( );
m_bFlag=true;
if(m_nFlag==0 || m_nFlag==3)
{
char *Ptr;
m_dOperand_1=strtod(m_strValue,&Ptr);
m_nFlag=1;
}
else if(m_nFlag==2)
{
char *Ptr;
m_dOperand_2=strtod(m_strValue,&Ptr);
double result=fmod(m_dOperand_1,m_dOperand_2);
char aValue[50]={NULL};
gcvt(result,25,aValue);
m_strValue=aValue;
m_dOperand_1=result;
if(result==0)
m_nFlag=0;
else
m_nFlag=3;
}
m_cOperator='%';
UpdateData(false);
GetDlgItem(IDC_SCREEN)->SetFocus( );
}
void CVCPP_11Dlg::OnBtnPlusminus()
{
// TODO: Add your control notification handler code here
UpdateData( );
m_bFlag=true;
char *Ptr;
m_dOperand_1=strtod(m_strValue,&Ptr);
double result=(m_dOperand_1*(-1));
char aValue[50]={NULL};
gcvt(result,25,aValue);
m_strValue=aValue;
m_nFlag=0;
m_cOperator='|';
UpdateData(false);
GetDlgItem(IDC_SCREEN)->SetFocus( );
}
Output: