基于vc++mfc的科学计算器程序实验报告.docx

上传人:b****3 文档编号:24784982 上传时间:2023-06-01 格式:DOCX 页数:43 大小:1.28MB
下载 相关 举报
基于vc++mfc的科学计算器程序实验报告.docx_第1页
第1页 / 共43页
基于vc++mfc的科学计算器程序实验报告.docx_第2页
第2页 / 共43页
基于vc++mfc的科学计算器程序实验报告.docx_第3页
第3页 / 共43页
基于vc++mfc的科学计算器程序实验报告.docx_第4页
第4页 / 共43页
基于vc++mfc的科学计算器程序实验报告.docx_第5页
第5页 / 共43页
点击查看更多>>
下载资源
资源描述

基于vc++mfc的科学计算器程序实验报告.docx

《基于vc++mfc的科学计算器程序实验报告.docx》由会员分享,可在线阅读,更多相关《基于vc++mfc的科学计算器程序实验报告.docx(43页珍藏版)》请在冰豆网上搜索。

基于vc++mfc的科学计算器程序实验报告.docx

基于vc++mfc的科学计算器程序实验报告

.

 

实验报告

 

课程名称:

windows 软件开发实习

 

实验项目:

科学计算器

 

Word 资料

.

 

工业大学实验报告

 

(适用计算机程序设计类)

专业班级:

软件 1006学号:

101201622姓名:

 鑫可

实验名称:

 

1.实验目的:

本程序设计实践是采用 C++语言,在 VC 平台下设计。

本课程设

计为学生提供了一个既动手又动脑,独立实践的机会,将课本上的理论知识和实际有机的结

合起来,锻炼学生的分析解决实际问题的能力。

提高学生适应实际,实践编程的能力。

 序

设计实践主要是培养学生利用系统综合 C++语言进行程序设计的能力。

1.进一步巩固和复习 C++程序设计的基础知识。

2.培养学生结构化程序、模块化程序设计的方法和能力。

3.了解软件的编制过程及各环节的具体容。

4.提高学生程序调试技巧、软件设计能力和代码规化等素质。

5.提高学生分析问题、解决问题以及实际运用能力。

2.实验容:

设计一个简单的计算器。

要求能实现整数、小数算数运算。

程序带

清零按钮。

 

3. 实验方案(程序设计说明)

见附件

 

4. 实验步骤或程序(经调试后正确的源程序)

(填写主要步骤与程序代码等。

见附件 A)

 

5.出现的问题及解决方法

 

Word 资料

.

 

附件 A工业大学实验报告

 

(适用计算机程序设计类)

专业班级:

软件 1006学号:

 101201622姓名:

鑫可

实验步骤或程序:

 

一、关于 Visual C++:

 

Visual C++6.0 由 Microsoft 开发, 它不仅是一个 C++ 编译器,而且是一个基于 Windows

操作系统的可视化集成开发环境(integrated development environment,IDE)。

Visual C++6.0

由许多组件组成,包括编辑器、调试器以及程序向导 AppWizard、类向导 Class Wizard 等开

发工具。

这些组件通过过一个名为Developer Studio 的组件集成为和谐的开发环境。

Microsoft 的主力软件产品。

Visual C++是一个功能强大的可视化软件开发工具。

自 1993 年

Microsoft 公司推出 Visual C++1.0 后,随着其新版本的不断问世,Visual C++已成为专业程

序员进行软件开发的

首选工具。

虽然微软公司推出了 Visual C++.NET(Visual C++7.0),但它的应用的很大的局限

性,只适用于 Windows 2000,Windows XP 和 Windows NT4.0。

所以实际中,更多的是以 Visual

C++6.0 为 6 平台。

Visual C++6.0 以拥有“语法高亮”,自动编译功能以及高级除错功能而著称。

比如,它允

许用户进行远程调试,单步执行等。

还有允许用户在调试期间重新编译被修改的代码,而不

必重新启动正在调试的程序。

其编译及创建预编译头文件(stdafx.h)、最小重建功能及累加连

结(link)著称。

这些特征明显缩短程序编辑、编译及连结的时间花费,在大型软件计划上尤其

显著。

二、设计要点

 

1、基本要求:

设计的系统界面要美观大方,操作合理,有必要的

提示。

 

2、创新要求:

在基本要求达到后,进行创新设计。

 

Word 资料

.

 

3、对系统进行功能模块分析、控制流程分析正确。

 

4、系统设计要实用,编程简练,可用,功能全面,并有一定的容错

能力。

 

5、说明书、流程图要清楚

 

6、要求程序设计合理,用户界面良好,如采用菜单工作方式。

 

三、实验步骤:

 

1、首先利用 MFC AppWinzard 生成计算器应用程序框架具体步骤如下:

 

执行 VC 程序,选择 File|New 命令,弹出 New 对话框.单击 Projects 标签,

 

转到 Projects 选项卡,选择 MFC AppWizard(exe)选项,然后在 Project name

 

文本框中输入 cyyJSQ 。

Lacation 文本框是指项目的本地路径。

 

2、界面设计

 

在界面中添加按钮,编辑框等相应控件,并合理摆放,使用户能更加方便的

 

使用。

具体设计如下图所示:

 

Word 资料

.

 

3、绑定控件

通过如下方式绑定控件。

 

具体绑定如下表所示:

 

按钮名称

 

按钮控件资源清单

 

按钮 ID

 

用途

 

0

 

1

 

2

 

3

 

4

 

5

IDC_ZERO

 

IDC_1

 

IDC_2

 

IDC_3

 

IDC_4

 

IDC_5

按键 0

 

按键 1

 

按键 2

 

按键 3

 

按键 4

 

按键 5

 

Word 资料

 

6

 

7

 

8

 

9

 

.

 

=

 

+

 

-

 

*

 

/

 

CE

 

Sqrt

 

1/x

 

-/+

 

MC

 

MR

 

MS

.

 

IDC_6

 

IDC_7

 

IDC_8

 

IDC_9

 

IDC _DOT

 

IDC _Equal

 

IDC _ADD

 

IDC _SUB

 

IDC _MUL

 

IDC _DIV

 

IDC _CE

 

IDC _Sqrt

 

IDC _Daoshu

 

IDC _ ZHengfu

 

IDC _Mc

 

IDC _Mr

 

IDC _Ms

 

按键 6

 

按键 7

 

按键 8

 

按键 9

 

小数点

 

等于

 

加号

 

减号

 

乘号

 

除号

 

清屏

 

开方

 

倒数

 

正负

 

清除存记录数据

 

存中保存的数据

 

数据存入存储器中,

将原有的数据冲走

M+IDC _Madd当前记录数据与存数

据相加

%

 

C

 

CE

IDC _Per

 

IDC _C

 

IDC _CE

百分号

 

清零(清除全部)

 

清除上一步数据

 

Word 资料

.

 

BackspaceIDC _Backspace从后向前删除

 

4、逐步实现代码

①按钮 1-9 的实现

文本编辑框的类型为 string 型,所以若按下数字 1 按钮时只需在数组尾部添加“1”即可

其他代码如此类推,具体代码如下:

void CMyDlg:

:

OnButton0()

{

// 数字 0

this->check() ;

CString tmp = num_buffer ;

// 当为小数点后或其前面有不为零的数时允许输入零

if ( tmp.ReverseFind('.') !

= -1 || tmp.FindOneOf( "123456789" ) !

= -1 )

{

num_buffer += "0" ;

}

else

{

num_buffer = "0" ;

}

GetDlgItem( IDC_EDIT_SHOW )->SetWindowText( num_buffer ) ;

}

void CMyDlg:

:

OnButton1()

{

// 数字 1

this->check() ;

num_buffer += "1" ;

GetDlgItem( IDC_EDIT_SHOW )->SetWindowText( num_buffer ) ;

}

 

void CMyDlg:

:

OnButton2()

{

// 数字 2

this->check() ;

num_buffer += "2" ;

GetDlgItem( IDC_EDIT_SHOW )->SetWindowText( num_buffer ) ;

}

 

void CMyDlg:

:

OnButton3()

{

// 数字 3

this->check() ;

num_buffer += "3" ;

 

Word 资料

.

 

GetDlgItem( IDC_EDIT_SHOW )->SetWindowText( num_buffer ) ;

}

void CMyDlg:

:

OnButton4()

{

// 数字 4

this->check() ;

num_buffer += "4" ;

GetDlgItem( IDC_EDIT_SHOW )->SetWindowText( num_buffer ) ;

}

void CMyDlg:

:

OnButton5()

{

// 数字 5

this->check() ;

num_buffer += "5" ;

GetDlgItem( IDC_EDIT_SHOW )->SetWindowText( num_buffer ) ;

}

void CMyDlg:

:

OnButton6()

{

// 数字 6

this->check() ;

num_buffer += "6" ;

GetDlgItem( IDC_EDIT_SHOW )->SetWindowText( num_buffer ) ;

}

void CMyDlg:

:

OnButton7()

{

// 数字 7

this->check() ;

num_buffer += "7" ;

GetDlgItem( IDC_EDIT_SHOW )->SetWindowText( num_buffer ) ;

}

void CMyDlg:

:

OnButton8()

{

// 数字 8

this->check() ;

num_buffer += "8" ;

GetDlgItem( IDC_EDIT_SHOW )->SetWindowText( num_buffer ) ;

}

 

void CMyDlg:

:

OnButton9()

{

// 数字 9

this->check() ;

num_buffer += "9" ;

GetDlgItem( IDC_EDIT_SHOW )->SetWindowText( num_buffer ) ;

 

Word 资料

.

 

}

 

void CMyDlg:

:

OnButtonDot()

{

// 小数点

if ( num_buffer.IsEmpty() )

{

num_buffer = "0." ;

}

else if ( num_buffer.ReverseFind('.') == -1 )

{

num_buffer += "." ;

}

GetDlgItem( IDC_EDIT_SHOW )->SetWindowText( num_buffer ) ;

}

// 求相反数

 

void CMyDlg:

:

OnButtonNI()

{

// 正负处理

m_num = - atof( num_buffer ) ;

// 转化为字符串

num_buffer.Format( _T("%lf"), m_num );

GetDlgItem( IDC_EDIT_SHOW )->SetWindowText( num_buffer ) ;

}

 

运行结果如下:

 

Word 资料

.

 

②加减乘除代码的实现:

通过控件的绑定以及传值函数,以指针调用的方式进行赋值,并将结果保存在num_buffer

中,与下一次输入的 num2 进行新的一元运算并给 result 赋值,通过 Updatedata()函数

反应到文本编辑框中,具体代码如下:

//加

void CMyDlg:

:

OnButtonAdd()

{

this->num1 = atof( num_buffer ) ;

this->num_buffer.Empty() ;

this->operation_type = ADD ;

}

// 减

void CMyDlg:

:

OnButtonSub() {

this->num1 = atof( num_buffer ) ;

this->num_buffer.Empty() ;

this->operation_type = SUB ;}

// 乘

void CMyDlg:

:

OnButtonMul() {

this->num1 = atof( num_buffer ) ;

this->num_buffer.Empty() ;

this->operation_type = MUL ;}

// 除

void CMyDlg:

:

OnButtonDiv()

{

this->num1 = atof( num_buffer ) ;

this->num_buffer.Empty() ;

this->operation_type = DIV ;

}

void CMyDlg:

:

OnButtonRes() {

 

const double EPSINON = 0.00001 ;

bool error = false ;

this->num2 = atof( num_buffer ) ;

this->num_buffer.Empty() ;

 

switch( this->operation_type )

{

case ADD :

this->m_num = num1 + num2 ;

break;

case SUB :

 

Word 资料

.

 

this->m_num = num1 - num2 ;

break;

case MUL :

this->m_num = num1 * num2 ;

break;

case DIV :

if ( (num2 > -EPSINON ) && (num2 <= EPSINON) ){

num_buffer = "除数不能为零" ;

error = true ;}

else{

this->m_num = num1 / num2 ;

}break;

default:

this->m_num = this->num2 ;

break;}

 

结果如下图所示

 

③科学性运算按钮的处理:

 

只需根据数值分析等为按钮进行算法的合理设计,正确赋值即可,具体代码如下:

 

// 自然底数 e

void CScience:

:

OnButtonEConst()

{

this->check() ;

num_buffer.Format(_T("%lf") , M_E) ;

fresh() ;

}

 

Word 资料

.

 

// 圆周率 ∏

void CScience:

:

OnButtonPai()

{

this->check() ;

num_buffer.Format(_T("%lf") , M_PI) ;

fresh() ;

}

 

void CScience:

:

OnButtonNi()

{

// 正负处理

m_result = - atof( num_buffer ) ;

// 转化为字符串

num_buffer.Format( _T("%lf"), m_result );

fresh() ;

}

 

void CScience:

:

OnButtonMutInv()

{

this->unary_operation = true ;

 

const double EPSINON = 0.00001 ;

this->m_result = atof( num_buffer ) ;

if ( (this->m_result >= - EPSINON) && (this->m_result <= EPSINON) )

{

GetDlgItem(IDC_EDIT_SHOW)->SetWindowText("0 的倒数没有定义\n") ;

}

else

{

this->m_result = 1.0 / m_result ;

num_buffer.Format( _T("%lf"), m_result );

fresh() ;

this->unary_operation = false ;

}

}

 

void CScience:

:

OnButtonPercent()

{

this->unary_operation = true ;

CString tmp = num_buffer ;

this->m_result = atof(num_buffer) ;

tmp.Format(_T("%lf") , this->m_result * 100 ) ;

tmp += "%" ;

 

Word 资料

.

 

fresh(tmp) ;

this->unary_operation = false ;

}

 

void CScience:

:

OnButtonSqr()

{

this->unary_operation = true ;

this->m_result = atof(num_buffer) ;

this->m_result = sqrt(m_result) ;

num_buffer.Format(_T("%lf") , this->m_result) ;

fresh() ;

this->unary_operation = false ;

}

 

void CScience:

:

OnButtonSin()

{

CString tmp ;

this->unary_operation = true ;

this->m_result = atof(num_buffer) ;

num_buffer.Format(_T("%lf") , this->m_result) ;

tmp = "Sin(" + num_buffer + ") =" ;

this->m_result = sin(m_result) ;

num_buffer.Format(_T("%lf") , this->m_result) ;

tmp += num_buffer ;

fresh(tmp) ;

this->unary_operation = false ;

}

 

void CScience:

:

OnButtonCos()

{

CString tmp ;

this->unary_operation = true ;

this->m_result = atof(num_buffer) ;

num_buffer.Format(_T("%lf") , this->m_result) ;

tmp = "Cos(" + num_buffer + ") =" ;

this->m_result = cos(m_result) ;

num_buffer.Format(_T("%lf") , this->m_result) ;

tmp += num_buffer ;

fresh(tmp) ;

this->unary_operation = false ;

}

 

void CScience:

:

OnButtonTan()

{

 

Word 资料

.

 

CString tmp ;

const double EPSINON = 0.00001 ;

 

this->unary_operation = true ;

this->m_result = atof(num_buffer) ;

 

num_buffer.Format(_T("%lf") , this->m_result) ;

tmp = "tan(" + num_buffer + ") =" ;

 

if ( (cos(m_result) >= -EPSINON) && (cos(m_result) <= EPSINON) )

{

error() ;

}

else

{

this->m_result = tan(m_result) ;

num_buffer.Format(_T("%lf") , this->m_result) ;

tmp += num_buffer ;

fresh(tmp) ;

this->unary_operation = false ;

}

}

 

void CScience:

:

OnButtonCot()

{

CString tmp ;

const double EPSINON = 0.00001 ;

 

this->unary_operation = true ;

this->m_result = atof(num_buffer) ;

 

num_buffer.Format(_T("%lf") , this->m_result) ;

tmp = "cot(" + num_buffer + ") =" ;

 

if ( (sin(m_result) >= -EPSINON) && (sin(m_result) <= EPSINON) )

{

error() ;

}

else

{

this->m_result = cos(m_result)/sin(m_result) ;

num_buffer.Format(_T("%lf") , this->m_result) ;

tmp += num_buffer ;

fresh(tmp) ;

 

Word 资料

.

 

this->unary_operation = false ;

}

}

 

void CScience:

:

OnButtonLn()

{

CString tmp ;

const double EPSINON = 0.00001 ;

 

this->unary_operation = true ;

this->m_result = atof(num_buffer) ;

 

num_buffer.Format(_T("%lf") , this->m_result) ;

tmp = "ln(" + num_buffer + ") =" ;

 

if ( m_result <= EPSINON )

{

error("参数必须大于 0") ;

}

else

{

this->m_result = log(m_result) ;

num_buffer.Format(_T("%lf") , this->m_result) ;

tmp += num_buffer ;

fresh(tmp) ;

this->unary_operation = false ;

}

}

运行结果如下:

 

④进制间的转换:

 

Word 资料

.

 

1.按钮 A-F 的实现与,进制运算时,按钮条件的设置。

 

在进行16进制运算时,需定义 A-F 按键,而在10进制时,A-F 按键设置为不可使用,以及8

进制时8、9按钮禁止使用。

具体代码如下:

void CScience:

:

OnButtonA()

{

// 数字 A(

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 军事政治

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1