VC语言综合实训.docx
《VC语言综合实训.docx》由会员分享,可在线阅读,更多相关《VC语言综合实训.docx(12页珍藏版)》请在冰豆网上搜索。
VC语言综合实训
VC++程序设计
综合实训开发报告
设计题目计算器
专业班级计科1001班
日期2012年12月1日
开发小组成员
组长:
袁军
组员:
王超雷洁林良杰
王浪高雨欣袁军
一、题目要求
设计计算器
二、题目分析
设计一个计算器,要能实现计算器的基本功能:
+-*/.
画出计算器的界面,显示界面,以及各个按钮,并且实现每个按钮的功能。
三、核心程序代码
CMyDlg:
:
CMyDlg(CWnd*pParent/*=NULL*/)
:
CDialog(CMyDlg:
:
IDD,pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
//}}AFX_DATA_INIT
//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32
m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_lNum="";
m_rNum="";
m_bIsLNum=true;
m_ilNumber=0;
m_irNumber=0;
m_operand='';
m_bIslFirstTime=true;
m_bIsrFirstTime=true;
}
voidCMyDlg:
:
OnButton1()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(m_bIsLNum)
{
m_lNum+="1";
m_result.SetWindowText(m_lNum);
}
else
{
m_rNum+="1";
m_result.SetWindowText(m_rNum);
}
}
voidCMyDlg:
:
OnButtonAdd()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
m_result.SetWindowText(_T("+"));
m_bIsLNum=false;
m_operand='+';
}
voidCMyDlg:
:
OnButtonDiv()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
m_result.SetWindowText(_T("/"));
m_bIsLNum=false;
m_operand='/';
}
voidCMyDlg:
:
OnButtonEqu()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
doubleresult=0;
CStringstrResult="";
switch(m_operand)
{
case'+':
m_ilNumber=atof(m_lNum);
m_irNumber=atof(m_rNum);
result=m_ilNumber+m_irNumber;
strResult.Format("%lf",result);
break;
case'-':
m_ilNumber=atof(m_lNum);
m_irNumber=atof(m_rNum);
result=m_ilNumber-m_irNumber;
strResult.Format("%lf",result);
break;
case'*':
m_ilNumber=atof(m_lNum);
m_irNumber=atof(m_rNum);
result=m_ilNumber*m_irNumber;
strResult.Format("%lf",result);
break;
case'/':
m_ilNumber=atof(m_lNum);
m_irNumber=atof(m_rNum);
result=m_ilNumber/m_irNumber;
strResult.Format("%lf",result);
break;
}
m_result.SetWindowText(strResult);
m_bIsLNum=true;
m_rNum="";
m_lNum="";
m_ilNumber=0;
m_irNumber=0;
}
voidCMyDlg:
:
OnButtonMul()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
m_result.SetWindowText(_T("*"));
m_bIsLNum=false;
m_operand='*';
}
voidCMyDlg:
:
OnButtonSub()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
m_result.SetWindowText(_T("—"));
m_bIsLNum=false;
m_operand='-';
}
voidCMyDlg:
:
OnButton2()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(m_bIsLNum)
{
m_lNum+="2";
m_result.SetWindowText(m_lNum);
}
else
{
m_rNum+="2";
m_result.SetWindowText(m_rNum);
}
}
voidCMyDlg:
:
OnButton3()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(m_bIsLNum)
{
m_lNum+="3";
m_result.SetWindowText(m_lNum);
}
else
{
m_rNum+="3";
m_result.SetWindowText(m_rNum);
}
}
voidCMyDlg:
:
OnButton4()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(m_bIsLNum)
{
m_lNum+="4";
m_result.SetWindowText(m_lNum);
}
else
{
m_rNum+="4";
m_result.SetWindowText(m_rNum);
}
}
voidCMyDlg:
:
OnButton5()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(m_bIsLNum)
{
m_lNum+="5";
m_result.SetWindowText(m_lNum);
}
else
{
m_rNum+="5";
m_result.SetWindowText(m_rNum);
}
}
voidCMyDlg:
:
OnButton6()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(m_bIsLNum)
{
m_lNum+="6";
m_result.SetWindowText(m_lNum);
}
else
{
m_rNum+="6";
m_result.SetWindowText(m_rNum);
}
}
voidCMyDlg:
:
OnButton7()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(m_bIsLNum)
{
m_lNum+="7";
m_result.SetWindowText(m_lNum);
}
else
{
m_rNum+="7";
m_result.SetWindowText(m_rNum);
}
}
voidCMyDlg:
:
OnButton8()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(m_bIsLNum)
{
m_lNum+="8";
m_result.SetWindowText(m_lNum);
}
else
{
m_rNum+="8";
m_result.SetWindowText(m_rNum);
}
}
voidCMyDlg:
:
OnButton9()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(m_bIsLNum)
{
m_lNum+="9";
m_result.SetWindowText(m_lNum);
}
else
{
m_rNum+="9";
m_result.SetWindowText(m_rNum);
}
}
voidCMyDlg:
:
OnButton0()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(m_bIsLNum)
{
m_lNum+="0";
m_result.SetWindowText(m_lNum);
}
else
{
m_rNum+="0";
m_result.SetWindowText(m_rNum);
}
}
voidCMyDlg:
:
Init()
{
m_result.SetWindowText(_T("0"));
}
voidCMyDlg:
:
OnButtonClear()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(m_bIsLNum)
{
m_lNum="";
m_ilNumber=0;
m_result.SetWindowText(_T("0"));
}
else
{
m_rNum="";
m_irNumber=0;
m_result.SetWindowText(_T("0"));
}
}
voidCMyDlg:
:
OnButtonFloat()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
if(m_bIsLNum&m_bIslFirstTime)
{
m_lNum+=".";
m_ilNumber=atof(m_lNum);
m_result.SetWindowText(m_lNum);
m_bIslFirstTime=false;
}
elseif(!
m_bIsLNum&m_bIsrFirstTime)
{
m_rNum+=".";
m_irNumber=atof(m_rNum);
m_result.SetWindowText(m_rNum);
m_bIsrFirstTime=false;
}
}
4、运行结果
例:
4*5=20
例20/10=2
5、总结
通过这次做项目,使我们懂得了很多知识。
在做项目过程中,虽然我们遇到很多问题,但一起查资料,经过团队的合作商讨,最重分工做出满意的结果,我们深刻的认识到了团队合作的重要性,在此过程中,大家各自分工,各抒己见,但最后得出统一的结果,我们应该遇到困难不气馁,最后成功了,这次实践让我们受益匪浅!
在此感谢老师对我们的辛勤的付出。
小组成员签名:
年月日