




已阅读5页,还剩21页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
计算机课程设计论文 题 目:常用功能计算器软件设计学 院:测试与光电工程学院 专业名称:电子科学与技术班级学号:10083129 学生姓名:周炜专 指导教师:黎芳芳 2013年 6月 常用功能计算器软件设计摘要:计算器是我们日常生活中常用的工具之一,计算器使用方法简单,操作方便,便于携带,适用于简单快捷的计算。本设计使用Visual C+语言编写具备常用功能的计算器软件,用Microsoft Visual C+6.0环境编译调试,制作了简洁的应用界面,使用模块化设计和自顶向下的功能实现。本软件可以进行小数量级下的加减乘除计算以及开根号、求比例等计算功能,还可以使用存储器进行多数据求和,还可以用退位、清零的方式修正操作失误,在进行不符合数学规则的非法计算时会报出错误提示。关键词: 计算器 Visual C+ Microsoft Visual C+ 6.0 目录1、 引言(1)2、C+语言简介(1)3、Microsoft Visual C+开发环境简介(1) 4、开发,调试及运行硬件和软件环境(1)5、软件整体设计思路(1)6、 软件运行效果(2)7、 源代码(3)8、 致谢(23)9、 参考文献(23)1、引言计算器是我们日常生活中常用的一种工具,随着电子科学的发展,计算器的功能越来越多样化、复杂化,外观也越来越多样化、轻量化,我们可以用很低的价格在市场上买到很实用很漂亮的计算器。为了巩固和加深对计算机软件设计课程的掌握,本课程设计使用高级语言在Windows环境下实现了具备常用功能的计算器软件的设计。 2、C+语言简介C+是一种使用非常广泛的计算机编程语言。C+是一种静态数据类型检查的、支持多重编程范式的通用程序设计语言。它支持过程化程序设计、数据抽象、面向对象程序设计、泛型程序设计等多种程序设计风格。3、Microsoft Visual C+开发环境简介 Microsoft Visual C+是Microsoft公司推出的开发Win32环境程序,面向对象的可视化集成编程系统。它不但具有程序框架自动生成、灵活方便的类管理、代码编写和界面设计集成交互操作、可开发多种程序等优点,而且通过简单的设置就可使其生成的程序框架支持数据库接口、OLE2,WinSock网络、3D控制界面。 它以拥有“语法高亮”,IntelliSense(自动完成功能)以及高级除错功能而著称。比如,它允许用户进行远程调试,单步执行等。还有允许用户在调试期间重新编译被修改的代码,而不必重新启动正在调试的程序。其编译及建置系统以预编译头文件、最小重建功能及累加连结著称。这些特征明显缩短程式编辑、编译及连结花费的时间,在大型软件计划上尤其显著。4、开发,调试及运行硬件和软件环境 处理器: Intel Pentium Dual-Core CPU T4200 2.00GHz BIOS: Lenovo 内存 : 2GB (金士顿 1066mhz) 显卡: Intel Mobile 4 Series Express Chipest Family (256MB) 操作系统: 32-bit Windows XP 编程语言: Visual C+ 编译环境: Microsoft Visual C+ 6.05、软件整体设计思路 经调查,非科学计算器常用功能主要有以下三个部分: 、运算功能 常用的运算功能有加法计算、减法计算、乘法计算、除法计算、根式计算、比率计算;、存储功能 常用的存储功能有:清除存储器中的数值(MC)、将存于存储器中的数显示在计算器的显示框上(MR)、将显示框的数值存于存储器中(MS)、将显示框的数与存储器中的数相加并进行存储(M+)。如果存储器中有数值将会显示M标志;、清除功能 常用的清除功能有清除输入(CE)、清除键(C)、退格键(BACK)。由于visual c+ 6.0自带了许多强大的数学计算库文件,这为软件的开发省去了不少的工作量,而visual c+6.0优秀的对话框绘制模块也使得这个小软件美观不少,为了方便计算器的使用,开发者特意加入了许多非法计算的错误提示,例如“Can not divide by zero”等。6、软件运行效果 、运用计算器计算:78*80 图一、运用计算器计算:78 *80 图二、在计算器上输入:78* 图三、在计算器上输入:80 图四、输出结果:6240、在计算器中输入2/0图五、非法操作,屏幕会显示错误提示7、源代码aboutdialog.cpp#include #include aboutdialog.h#include #include resource.haboutdialog:aboutdialog( ) : CDialog ( IDD_DIALOG1 )int aboutdialog:OnInitDialog( ):PlaySound ( music.wav, NULL, SND_FILENAME | SND_ASYNC | SND_LOOP ) ;return 1 ;void aboutdialog:OnOK( ) :PlaySound ( NULL, NULL, NULL ) ;CDialog:OnOK( ) ;void aboutdialog:OnCancel( ) :PlaySound ( NULL, NULL, NULL ) ;CDialog:OnCancel( ) ;l aboutdialog.h class aboutdialog : public CDialogpublic :aboutdialog( ) ;int OnInitDialog( ) ;void OnOK( ) ;void OnCancel( ) ;myapp.cpp#include #include myapp.h#include myedit.h#include myframe.hmyapp a ;int myapp:InitInstance( )myframe *p ;p = new myframe ;p - ShowWindow ( 1 ) ;m_pMainWnd = p ;return 1 ;myapp.hclass myapp : public CWinApppublic :int InitInstance( ) ; ;myedit.cpp#include #include myedit.hBEGIN_MESSAGE_MAP ( myedit, CEdit )ON_WM_CREATE( )ON_WM_LBUTTONDOWN( )ON_WM_MOUSEMOVE( )END_MESSAGE_MAP( )int myedit:OnCreate ( LPCREATESTRUCT l ) CEdit:OnCreate ( l ) ;m_cur = AfxGetApp( ) - LoadStandardCursor ( IDC_ARROW ) ;return 0 ;void myedit:OnLButtonDown ( UINT flags, CPoint pt )void myedit:OnMouseMove ( UINT flags, CPoint pt )SetCursor ( m_cur ) ; myedit.hclass myedit : public CEdit private :HCURSOR m_cur ;public :int OnCreate ( LPCREATESTRUCT l ) ;void OnLButtonDown ( UINT flags, CPoint pt ) ;void OnMouseMove ( UINT flags, CPoint pt ) ;DECLARE_MESSAGE_MAP( ) ;myframe.cpp#include #include myedit.h#include myframe.h#include aboutdialog.h#include #include resource.hBEGIN_MESSAGE_MAP ( myframe, CFrameWnd )ON_WM_CREATE( )ON_COMMAND ( 1001, myabout )ON_COMMAND_RANGE ( 1, 10, numbers0to9 ) ON_COMMAND ( 101, back )ON_COMMAND ( 102, ce ) ON_COMMAND ( 103, c ) ON_COMMAND ( 106, memorycancel ) ON_COMMAND ( 107, divide )ON_COMMAND ( 108, squareroot ) ON_COMMAND ( 109, memoryrecall ) ON_COMMAND ( 110, multiply ) ON_COMMAND ( 111, percentage ) ON_COMMAND ( 112, memorystore ) ON_COMMAND ( 113, minus )ON_COMMAND ( 114, onebyx ) ON_COMMAND ( 115, memoryplus ) ON_COMMAND ( 117, plusminus ) ON_COMMAND ( 118, point ) ON_COMMAND ( 119, plus ) ON_COMMAND ( 120, equalto ) ON_WM_PARENTNOTIFY( )ON_WM_KEYDOWN( )END_MESSAGE_MAP()CString myframe:m_helpstrings = No help topic is associated with this item., Delete the last digit of the displayed number.,Clears the displayed number.,Clears the current calculation.,Clears any number stored in memory.,Puts this number in the calculator display.,Puts this number in the calculator display.,Puts this number in the calculator display.,Divdes.,Calculates the square root of the displayed number.,Recalls the number stored in memory. The number remains in the memory.,Puts this number in the calculator display.,Puts this number in the calculator display.,Puts this number in the calculator display.,Multiplies.,Displays the result of the multiplication as percentage.,Stores the displayed number in the memory.,Puts this number in the calculator display.,Puts this number in the calculator display.,Puts this number in the calculator display.,Subracts.,Calculates the reciprocal of the displayed number.,Adds the displayed number to any number already in memory.,Puts this number in the calculator display.,Changes the sign of the displayed number.,Inserts a decimal point.,Adds.,Performs any operation on the previous two numbers. To repeat he last operation click again. ;myframe:myframe( )CString mywindowclass ;CBrush mybrush ;mybrush.CreateStockObject ( LTGRAY_BRUSH ) ;mywindowclass = AfxRegisterWndClass ( CS_HREDRAW | CS_VREDRAW,AfxGetApp( ) - LoadStandardCursor ( IDC_ARROW ),mybrush, AfxGetApp( ) - LoadIcon ( IDI_ICON1 ) ) ;Create ( mywindowclass, Calculator, WS_SYSMENU | WS_MINIMIZEBOX, CRect ( 100, 100, 400, 400 ), 0, MAKEINTRESOURCE ( IDR_MENU1 ) ) ;BOOL myframe:PreCreateWindow ( CREATESTRUCT& cs ) CFrameWnd:PreCreateWindow ( cs ) ;cs.dwExStyle &= WS_EX_CLIENTEDGE ;return TRUE ;int myframe:OnCreate ( LPCREATESTRUCT l )CFrameWnd:OnCreate ( l ) ;struct buttoninfochar m_str5 ;int id ; ;buttoninfo m30 = , 100,Back, 101,CE, 102,C, 103, 104, 105,MC, 106,7, 8,8, 9,9, 10,/, 107,Sqrt, 108, MR, 109,4, 5,5, 6,6, 7,*, 110,%, 111,MS, 112,1, 2,2, 3,3, 4,-, 113,1/x, 114,M+, 115,0, 1,+/-, 117,., 118,+, 119,=, 120 ;m_editrect = CRect ( 10, 10, 275, 35 ) ;m_e.CreateEx ( WS_EX_CLIENTEDGE, EDIT, 0., WS_VISIBLE | WS_CHILD | ES_RIGHT | ES_MULTILINE, m_editrect, this, 30 ) ;int x1 = 10, y1 = 50, x2, y2 ;for ( int i = 0 ; i = 29 ; i+ )x2 = x1 + 40 ;y2 = y1 + 30 ;m_buttonrecti = CRect ( x1, y1, x2, y2 ) ;if ( i != 0 & i != 4 & i != 5 )m_bi.Create ( mi.m_str, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, m_buttonrecti, this, mi.id ) ;if ( i = 0 )m_st.CreateEx ( WS_EX_CLIENTEDGE, STATIC, , WS_VISIBLE | WS_CHILD | SS_NOTIFY, m_buttonrecti, this, mi.id ) ;x1 += 45 ;if ( ( i + 1 ) % 6 = 0 ) x1 = 10 ;y1 = y1 + 40 ;m_oper = ;m_over = true;m_decipoint = false ;m_mem = 0 ;return 0 ;void myframe:myabout( )aboutdialog d ;d.DoModal( ) ;void myframe:back()CString lf, rt ;m_e.GetWindowText ( m_str ) ;lf = m_str.Left ( m_str.GetLength( ) - 1 ) ;rt = m_str.Right ( 1 ) ;if ( rt = . )m_decipoint = false ;if ( m_str = 0. )m_over = true ;elsem_str = lf ;elseif ( lf.Right ( 1 ) = . )m_decipoint = false ;if ( lf = 0. )m_str = 0. ;m_over = true ;elsem_str = lf.Left ( lf.GetLength( ) - 1 ) ;elseif ( lf = )m_str = 0. ;m_over = true ;elsem_str = lf ;m_e.SetWindowText ( m_str ) ;void myframe:c( )m_num1 = m_num2 = 0 ;m_over = true ;m_decipoint = false ;m_str = 0. ;m_e. SetWindowText(m_str) ;void myframe:ce( )if ( m_oper = )m_num1 = 0 ;elsem_num2 = 0 ;m_str= 0. ;m_e. SetWindowText ( m_str ) ;m_over = true ;m_decipoint = false ;void myframe:numbers0to9 ( int id )CString temp ;temp.Format ( %d, id - 1 ) ;if ( m_over = false )m_e.GetWindowText ( m_str ) ;if ( m_str = 0. )return ;if ( m_str.GetLength( ) = 13 ):MessageBeep ( 1 ) ;elsem_str = m_str + temp ;m_e.SetWindowText ( m_str ) ;elsem_e.SetWindowText ( temp ) ;m_over = false ;void myframe:plusminus( )m_e.GetWindowText ( m_str ) ;m_num = atof ( m_str ) ;if ( m_num != 0 )m_num = m_num * -1 ;m_str.Format ( %.8g, m_num ) ;m_e. SetWindowText ( m_str ) ;m_over = true ;void myframe:onebyx( )m_e.GetWindowText ( m_str ) ;m_num = atof ( m_str ) ;if ( m_num != 0 )m_num = 1 / m_num ;m_str.Format ( %.8g, m_num ) ;m_e.SetWindowText ( m_str ) ;m_over = true ;m_decipoint = false ;void myframe:squareroot( )m_e.GetWindowText ( m_str ) ;m_num = atof ( m_str ) ;if ( m_num != 0 )m_num = sqrt ( m_num ) ;m_str.Format( %.8g, m_num ) ;m_e.SetWindowText(m_str) ;m_over = true ;m_decipoint = false ;void myframe:percentage()double num3 ;if ( m_oper != )m_e.GetWindowText ( m_str ) ;m_num2 = atof ( m_str ) ;num3 = m_num2 * m_num1 ;num3 = num3 / 100 ;m_str.Format( %.8g, num3 ) ;m_e.SetWindowText ( m_str ) ;m_over = true ;m_decipoint = false ;m_oper = ;void myframe:point( )if ( m_decipoint = false )if ( m_over = true ) m_e.SetWindowText ( 0. ) ;m_over = false ;elsem_e.GetWindowText ( m_str ) ;if ( m_str = 0. )return ;elsem_str = m_str + . ;m_e. SetWindowText ( m_str ) ;m_decipoint = true ;else:MessageBeep ( 1 ) ;void myframe:plus( )if ( m_oper != )equalto( ) ;m_oper = + ;m_e.GetWindowText ( m_str ) ;m_num1 = atof ( m_str ) ;m_over = true ;m_decipoint = false ;void myframe:minus( )if ( m_oper != )equalto( ) ;m_oper = - ;m_e.GetWindowText ( m_str ) ;m_num1 = atof ( m_str ) ;m_over = true ;m_decipoint = false ;void myframe:multiply( )if ( m_oper != )equalto( ) ;m_oper = * ;m_e.GetWindowText ( m_str ) ;m_num1 = atof ( m_str ) ;m_over = true ;m_decipoint = false ;void myframe:divide( )if ( m_oper != )equalto( ) ;m_oper = / ;m_e.GetWindowText ( m_str ) ;m_num1 = atof ( m_str ) ;m_over = true ;m_decipoint = false ;void myframe:equalto( )if ( m_oper = )return ;double num3 ;m_e.GetWindowText ( m_str ) ;m_num2 = atof ( m_str ) ;switch ( m_oper )case + :num3 = m_num1 + m_num2 ;break ;case - :num3 = m_num1 - m_num2 ;break ;case * :num3 = m_num1 * m_num2 ;break ;case / :if ( m_num2 = 0 )m_over = true ;m_decipoint = false ;m_e.SetWindowText ( Cannot divide by zero. ) ;return ;elsenum3 = m_num1 / m_num2 ;m_str.Format ( %.8g, num3 ) ;if ( m_str = 0 )m_str = 0. ;m_over = true ;m_decipoint = false ;m_oper = ;m_e.SetWindowText ( m_str ) ;void myframe:memorystore( )m_e.GetWindowText ( m_str ) ;m_mem = atof ( m_str ) ;m_st.SetWindowText ( M ) ;m_over = true ;m_decipoint = false ;m_oper = ;void myframe:memoryrecall( )m_str.Format( %.8g, m_mem ) ;m_e.SetWindowText ( m_str ) ;m_over = true ;m_decipoint = false ;m_oper = ;void myframe:memorycancel( )m_mem = 0 ;m_st.SetWindowText ( ) ;void myframe:memoryplus( )m_e.GetWindowText ( m_str ) ;m_num = atof ( m_str ) ; m_mem = m_mem + m_num ; m_st.SetWindowText ( M ) ;m_over = true ;m_decipoint = false ;m_oper = ;void myframe:OnParentNotify ( long int m, unsigned long int p )int mousebutton = LOWORD ( m ) ;if ( mousebutton = WM_RBUTTONDOWN )int x = LOWORD ( p ) ;int y = HIWORD ( p ) ;CPoint pt ( x, y ) ;if ( m_editrect.PtInRect ( pt ) )MessageBox ( Shows the result., Help., MB_OK | MB_ICONQUESTION ) ;for ( int i = 0 ; i = 29 ; i+ )if ( m_buttonrecti.PtInRect ( pt ) )MessageBox ( m_helpstringsi, Help., MB_OK | MB_ICONQUESTION ) ;void myframe:OnKeyDown ( UINT ch, UINT rep, UINT flag )switch ( ch )case VK_BACK :back( );break ;case VK_NUMPAD7 :case 7 :m_b7.SetState ( 1 ) ;numbers0to9 ( 8 ) ;Sleep ( 20 ) ;m_b7.SetState ( 0 ) ;break ;case VK_NUMPAD8 :case 8 :m_b8.SetState ( 1 ) ;numbers0to9 ( 9 ) ;Sleep ( 20 ) ;m_b8.SetState ( 0 ) ;break ;case VK_NUMPAD9 :case 9 :m_b9.SetState ( 1 ) ;numbers0to9 ( 10 ) ;Sleep ( 20 ) ;m_b9.SetState ( 0 ) ;break ;case VK_DIVIDE :m_b10.SetState ( 1 ) ;divide( );Sleep ( 20 ) ;m_b10.SetState ( 0 ) ;break ;case VK_NUMPAD4 :case 4 :m_b13.SetState ( 1 ) ;numbers0to9 ( 5 ) ;Sleep ( 20 ) ;m_b13.SetState ( 0 ) ;break ;case VK_NUMPAD5 :case 5 :m_b14.SetState ( 1 ) ;numbers0to9 ( 6 ) ;Sleep ( 20 ) ;m_b14.SetState ( 0 ) ;break ;case VK_NUMPAD6 :case 6 :m_b15.SetState ( 1 ) ;numbers0to9 ( 7 ) ;Sleep ( 20 ) ;m_b15.SetState ( 0 ) ;break ;case VK_MULTIPLY :m_b16.SetState ( 1 ) ;multiply( ) ;Sleep ( 20 ) ;m_b16.SetState ( 0 ) ;break ;case VK_NUMPAD1 :case 1 :m_b19.SetState ( 1 ) ;numbers0to9 ( 2 ) ;Sleep ( 20 ) ;m_b19.SetState ( 0 ) ;break ;case VK_NUMPAD2 :case 2 :m_b20.SetState ( 1 ) ;numbers0to9 ( 3 ) ;Sleep ( 20 ) ;m_b20.SetState ( 0 ) ;break ;case VK_NUMPAD3 :case 3 :m_b21.SetState ( 1 ) ;numbers0to9 ( 4 ) ;Sleep ( 20 ) ;m_b21.SetState ( 0 ) ;break ;case VK_SUBTRACT :m_b22.SetState ( 1 ) ;minus( );Sleep ( 20 ) ;m_b22.SetState ( 0 ) ;break ;case VK_NUMPAD0 :case 0 :m_b25.SetState ( 1 ) ;numbers0to9 ( 1 ) ;Sleep ( 20 ) ;m_b25.SetState ( 0 ) ;break ;case VK_DECIMAL :m_b27.SetState ( 1 ) ;point( ) ;Sleep ( 20 ) ;m_b27.SetState ( 0 ) ;break ;case VK_ADD :m_b28.SetState ( 1 ) ;plus( ) ;Sleep ( 20 ) ;m_b28.SetState ( 0 ) ;break ;case VK_RETURN :m_b29.SetState ( 1 ) ;equalto( ) ;Sleep ( 20 ) ;m_b29.SetState ( 0 ) ;break ;myframe.hclass myframe : public CFrameWndprivate :myedit m_e ;CRect m_editrect ;CButton m_b30 ;CRect m_buttonrect30 ;CStatic m_st ;CString m_str ;double m_num, m_num1, m_num2, m_mem ;char m_oper ;bo
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 防骗安全测试题及答案解析
- 2025年新能源行业国际合作与“一带一路”倡议研究报告
- 2025年节水知识竞赛试题及答案
- 淄博市安全教育培训试题及答案解析
- 2025年农业绿色发展政策支持下的农业面源污染治理技术市场趋势报告
- 2025闵行七宝镇村(合作社)、镇属公司公开招聘20人模拟试卷及答案详解(考点梳理)
- 2025贵州三都水族自治县人民医院(医共体)总院第二次招聘合同制工作人员51人考前自测高频考点模拟试题及1套参考答案详解
- 2025年新能源行业品牌建设与市场品牌忠诚度研究报告
- 2025福建省高速集团有限公司权属企业招聘若干人考前自测高频考点模拟试题及答案详解(新)
- 2025-2030工业软件云化转型过程中的客户付费意愿迁移报告
- 水库水坝施工方案范本
- 肺康复个案护理
- 人美版美术六年级上册全册教案
- GB/T 21499-2024粮油检验稻谷和糙米潜在出米率测定方法
- (版)科学道德与学风建设题库
- GB/Z 44314-2024生物技术生物样本保藏动物生物样本保藏要求
- 2023年全国职业院校技能大赛-融媒体内容策划与制作赛项规程
- 《电力建设施工企业安全生产标准化实施规范》
- 糖尿病周围神经病变知多少课件
- 儿童肺炎支原体肺炎诊疗指南(2023年版)解读
- 个人履职考核情况表
评论
0/150
提交评论