当前位置:首页 > 工作总结 > 计算器设计报告 简易计算器的设计报告
 

计算器设计报告 简易计算器的设计报告

发布时间:2019-07-18 09:14:35 影响了:

计算器的设计

1概述

1.1 课程设计目的

1、巩固并加深学生对C++语言程序设计知识的理解;

2、培养学生面向对象的程序设计思想,使学生认识面向过程和面向对象两种设计方法的区别;

3、进一步掌握和应用VC++ 6.0集成开发环境;

4、提高运用C++语言解决实际问题的能力;

5、初步掌握开发小型实用软件的基本方法,能独立设计、实现基本的MIS系统;

6、掌握书写程序设计开发文档的能力(书写课程设计实验报告)。

1.2 课程设计内容

课题名称:计算器的实现

说明:实现一个计算器。

要求:

用“计算器”的标准视图执行简单的计算。

3

四则代码如下

void CCALDlg::OnButtonequal()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

num2 =m_str;

if(num2==0&&ope==3)

{

m_str1="除数不能为零";

m_str =0;

num1 = 0;

num2 = 0;

UpdateData(FALSE);

}

else{

// int f = 0;

switch (ope)

{

//加

case 0:

m_str = num1 + num2;

peak;

//减

case 1:

m_str = num1 - num2;

peak;

5

4系统详细设计

4.1 设计步骤

打开Microsoft Visual C++ 6.0,在文件中点击新建,在弹出框内选择MFC AppWizard[exe]工程,输入工程名yeyahui及其所在位置,点击确定,如图4-

1所示。

图4-1 新建MFC AppWizard[exe]工程

将弹出MFC AppWizard-step 1对话框,选择基本对话框,点击完成,如图4-2所示。

7

图4-3新建的对话框

4.2 界面设计

界面设计主要是创建控件,在图4-3所示的Resoure

View选项卡中打开Dialog资源组,双击IDD_ZHOUTONG_DIALOG,在右边的窗口中显示出待编辑的对话框。开始摆放控件,包括编辑框和按钮的创建。按钮的创建以“1”为例进行介绍,其他按钮的创建可参照此进行操作。

1)在图4-

3中Controls的“编辑框”按钮上单击鼠标左键,在对话框编辑窗口上合适的位置按下鼠标左键并拖动鼠标画出一个大小合适的编辑框。在编辑框上单击鼠标右键,在弹出的快捷莱单中选择属性选项,此时弹出Edit属性对话框,如图4-4所示,在该对话框中输入ID属性。

9

图5-1 四则运算,乘法测试结果图

13

附 录

附录1 源程序清单

// 计算器Dlg.cpp : implementation file

//

#include "stdafx.h"

#include "CAL.h"

#include "CALDlg.h"

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog

{

public:

CAboutDlg();

// Dialog Data

//{{AFX_DATA(CAboutDlg)

enum { IDD = IDD_ABOUTBOX };

//}}AFX_DATA

// ClassWizard generated virtual function overrides

//{{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

}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CAboutDlg)

//}}AFX_DATA_MAP

15

// CCALDlg message handlers

BOOL CCALDlg::OnInitDialog()

{

CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.

ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX

CMenu* pSysMenu = GetSystemMenu(FALSE);

if (pSysMenu != NULL)

{

CString strAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if (!strAboutMenu.IsEmpty())

{

pSysMenu->AppendMenu(MF_SEPARATOR);

pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);

}

}

// 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);// Set big icon

SetIcon(m_hIcon, FALSE);// Set small icon

SetWindowText(_T("计算器 V1.0 作者:13级数学与计算机学院第4期 陈菁"));//修改软件名称

// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control

}

void CCALDlg::OnSysCommand(UINT nID, LPARAM lParam)

{

if ((nID & 0xFFF0) == IDM_ABOUTBOX)

{

CAboutDlg dlgAbout;

dlgAbout.DoModal();

}

else

{

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 CCALDlg::OnPaint()

{

if (IsIconic())

{

CPaintDC dc(this); // device context for painting

17

void CCALDlg::OnButton3()

{

// TODO: Add your control notification handler code hereUpdateData(TRUE);

m_str =0;

m_str=m_str+3;

UpdateData(FALSE);

}

void CCALDlg::OnButton4()

{

// TODO: Add your control notification handler code hereUpdateData(TRUE);

m_str =0;

m_str=m_str+4;

UpdateData(FALSE);

}

void CCALDlg::OnButton5()

{

// TODO: Add your control notification handler code hereUpdateData(TRUE);

m_str =0;

m_str=m_str+5;

UpdateData(FALSE);

}

void CCALDlg::OnButton6()

{

// TODO: Add your control notification handler code hereUpdateData(TRUE);

m_str =0;

m_str=m_str+6;

UpdateData(FALSE);

}

void CCALDlg::OnButton7()

{

// TODO: Add your control notification handler code hereUpdateData(TRUE);

m_str =0;

m_str=m_str+7;

UpdateData(FALSE);

}

void CCALDlg::OnButton8()

{

// TODO: Add your control notification handler code hereUpdateData(TRUE);

m_str =0;

19

else{

// int f = 0;

switch (ope)

{

//加

case 0:

m_str = num1 + num2;

peak;

//减

case 1:

m_str = num1 - num2;

peak;

case 2:

m_str = num1 * num2;

peak;

case 3:

m_str = num1 / num2;

peak;

case 4:

m_str = num1 * num1;

}

UpdateData(FALSE);

}

}

void CCALDlg::OnButtonmul()

{

// TODO: Add your control notification handler code hereSaveValue1();

ope=2;

}

void CCALDlg::OnButtondiv()

{

// TODO: Add your control notification handler code hereSaveValue1();

ope=3;

}

void CCALDlg::OnButton10()

{

// TODO: Add your control notification handler code herenum1=m_str;

ope=4;

}

21

猜你想看
相关文章

Copyright © 2008 - 2022 版权所有 职场范文网

工业和信息化部 备案号:沪ICP备18009755号-3