银行ATM自动取款机模拟系统实验报告(共9页).doc
精选优质文档-倾情为你奉上西安科技大学VC+语言程序设计实验报告 题 目 _科学计算器的实现_ 院、系(部) 计算机科学与技术学院 专业及班级 软件工程1102班 姓 名 赵文杰 日 期 2012/11/9 1.题目:科学计算器2.功能需求:这是计算器,在满足用户需求方面应有以下功能:1)进行简单的加、减、乘、除;2)进行函数运算如sin、cos、tan函数;3)可进行进制转换、及弧度运算;3.总体设计计算器基本运算函数运算进制转化几弧度4.详细设计以下是详细的分部:1>基于MFC创建一个基本对话框Calculator2>实现基本运算的代码:void CCalculatorDlg:OnNumberKey(UINT nID)CString n;switch(nID)case IDC_NUMBER1:n="1"break;case IDC_NUMBER2:n="2"break;case IDC_NUMBER3:n="3"break;case IDC_NUMBER4:n="4"break;case IDC_NUMBER5:n="5"break;case IDC_NUMBER6:n="6"break;case IDC_NUMBER7:n="7"break;case IDC_NUMBER8:n="8"break;case IDC_NUMBER9:n="9"break;case IDC_NUMBER0:n="0"break;case IDC_NUMBER_Point:n="."if(Point=TRUE)m_Point.ShowWindow(SW_HIDE);Point=FALSE;break;if(NumberState=1)m_Cnumber=m_Cnumber+n;number1=atof(m_Cnumber);UpdateData(FALSE);else m_Cnumber=m_Cnumber+n;number2=atof(m_Cnumber);UpdateData(FALSE);if(Zero=FALSE)Zero=TRUE;m_Zero.ShowWindow(SW_SHOW);void CCalculatorDlg:OnOperationKey(UINT nID)m_number=atof(m_Cnumber);switch(nID)case IDC_NUMBER_PlusMinus:m_number=m_number;if(NumberState=1)number1=m_number;elsenumber2=m_number;m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_BackSpace:int n;n=m_Cnumber.GetLength();m_Cnumber=m_Cnumber.Left(n-1);UpdateData(FALSE);break;case IDC_NUMBER_Divide:cal();if(Zero=TRUE)m_Zero.ShowWindow(SW_HIDE);Zero=FALSE;OperationState=1;m_number=0;m_Cnumber=""NumberState=2;break;case IDC_NUMBER_Multiply:cal(); OperationState=2;m_number=0;m_Cnumber=""NumberState=2;break;case IDC_NUMBER_Add:cal(); OperationState=3;m_number=0;m_Cnumber=""NumberState=2;break;case IDC_NUMBER_Subtract:cal(); OperationState=4;m_number=0;m_Cnumber=""NumberState=2;break;case IDC_NUMBER_Clear:number1=number2=m_number=0;m_Cnumber.Format("%g",m_number);UpdateData(FALSE);m_Cnumber=""NumberState=1;break;case IDC_NUMBER_Sqrt:number1=m_number=sqrt(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Sin:number1=m_number=sin(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Cos:number1=m_number=cos(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Tan:number1=m_number=tan(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Log:number1=m_number=log(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Log10:number1=m_number=log10(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Exp:number1=m_number=exp(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Derivative:number1=m_number=(double)1/number1;m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Equal:cal();break;if(Point=FALSE)Point=TRUE;m_Point.ShowWindow(SW_SHOW);3>函数的实现代码:void CCalculatorDlg:OnOperationKey(UINT nID)m_number=atof(m_Cnumber);switch(nID)case IDC_NUMBER_PlusMinus:m_number=m_number;if(NumberState=1)number1=m_number;elsenumber2=m_number;m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_BackSpace:int n;n=m_Cnumber.GetLength();m_Cnumber=m_Cnumber.Left(n-1);UpdateData(FALSE);break;case IDC_NUMBER_Divide:cal();if(Zero=TRUE)m_Zero.ShowWindow(SW_HIDE);Zero=FALSE;OperationState=1;m_number=0;m_Cnumber=""NumberState=2;break;case IDC_NUMBER_Multiply:cal(); OperationState=2;m_number=0;m_Cnumber=""NumberState=2;break;case IDC_NUMBER_Add:cal(); OperationState=3;m_number=0;m_Cnumber=""NumberState=2;break;case IDC_NUMBER_Subtract:cal(); OperationState=4;m_number=0;m_Cnumber=""NumberState=2;break;case IDC_NUMBER_Clear:number1=number2=m_number=0;m_Cnumber.Format("%g",m_number);UpdateData(FALSE);m_Cnumber=""NumberState=1;break;case IDC_NUMBER_Sqrt:number1=m_number=sqrt(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Sin:number1=m_number=sin(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Cos:number1=m_number=cos(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Tan:number1=m_number=tan(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Log:number1=m_number=log(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Log10:number1=m_number=log10(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Exp:number1=m_number=exp(number1);m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Derivative:number1=m_number=(double)1/number1;m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case IDC_NUMBER_Equal:cal();break;if(Point=FALSE)Point=TRUE;m_Point.ShowWindow(SW_SHOW);CCalculatorDlg:cal()m_number=atof(m_Cnumber);switch(OperationState)case 1:m_number=(double)number1/number2;NumberState=1;m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case 2:m_number=(double)number1*number2;NumberState=1;m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case 3:m_number=(double)number1+number2;NumberState=1;m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;case 4:m_number=(double)number1-number2;NumberState=1;m_Cnumber.Format("%g",m_number);UpdateData(FALSE);break;number1=m_number;OperationState=0;4>进制转换,弧度:实现时有问题5.测试及实现6.总结这是一个科学计算器,只能实现基本运算和函数运算。在进制转换及弧度上的实现有问题,通过这次科学计算器的编写,我认为自己在vc+方面有很大的问题,比如进制转化和弧度运算的算法不能熟练掌握,不能熟知整个程序的整体框架,所以以后要认真学习。专心-专注-专业