算法与数据结构程序设计报告Word下载.docx

上传人:b****2 文档编号:4889370 上传时间:2023-05-04 格式:DOCX 页数:23 大小:77.52KB
下载 相关 举报
算法与数据结构程序设计报告Word下载.docx_第1页
第1页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第2页
第2页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第3页
第3页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第4页
第4页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第5页
第5页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第6页
第6页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第7页
第7页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第8页
第8页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第9页
第9页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第10页
第10页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第11页
第11页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第12页
第12页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第13页
第13页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第14页
第14页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第15页
第15页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第16页
第16页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第17页
第17页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第18页
第18页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第19页
第19页 / 共23页
算法与数据结构程序设计报告Word下载.docx_第20页
第20页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

算法与数据结构程序设计报告Word下载.docx

《算法与数据结构程序设计报告Word下载.docx》由会员分享,可在线阅读,更多相关《算法与数据结构程序设计报告Word下载.docx(23页珍藏版)》请在冰点文库上搜索。

算法与数据结构程序设计报告Word下载.docx

优秀、良好、中等、及格、不及格

求解多项式积分

一、课题内容和要求

题目描述:

输入待求函数,积分上下限,求出结果。

基本要求:

(1)能正确求解多项式的单重和双重积分(存在x和y两个积分变量);

(2)能处理用户输入错误以及基本的逻辑错误。

提高要求:

(1)能设计出简捷易操作的窗口界面;

(2)能处理多重积分。

设计提示:

用链表结构描述多项式。

二、数据结构说明

多项式以链表表示,链表中包含:

单项结点info,指向于下一个结点的指针next。

这些封装在结构体PolyNomial中。

单项结点中包含:

单项的系数a,X的指数ex,Y的指数ey,这些封装在结构体PolyNode中。

三、算法设计

本题是一个数学计算题,要求对已知的多项式进行积分,主要思想是首先要设计出对用户输入的多项式表达式进行系数和指数提取的算法,然后利用积分公式分别对该多项式进行一重积分和二重积分,然后再利用简单的多项式相减的方法求解出最后的积分值。

多项式的每项都用简单链表的每个结点表示,每个结点中包含了每项的数据以及指向下一个结点地址的变量,每项数据中包含了多项式的系数和指数。

计算积分时按照节点顺序分别对每个项求积分。

数据结构定义:

//多项式结点

typedefstructpolynode

{

doublea;

intex;

intey;

}PolyNode;

//多项式链表表示存储结构

typedefstructpolynomial

PolyNodeinfo;

polynomial*next;

}PolyNomial;

四、详细设计

求解多项式积分Dlg.h:

//求解多项式积分Dlg.h:

headerfile

//

#if!

defined(AFX_DLG_H__E2838798_3E67_4AC2_A7F1_C26DCD5C42C5__INCLUDED_)

#defineAFX_DLG_H__E2838798_3E67_4AC2_A7F1_C26DCD5C42C5__INCLUDED_

#if_MSC_VER>

1000

#pragmaonce

#endif//_MSC_VER>

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

//CMyDlgdialog

classCMyDlg:

publicCDialog

//Construction

public:

CMyDlg(CWnd*pParent=NULL);

//standardconstructor

//DialogData

//{{AFX_DATA(CMyDlg)

enum{IDD=IDD_MY_DIALOG};

CEditm_cFun;

CEditm_cXmin;

CEditm_cXmax;

CEditm_cYmin;

CEditm_cYmax;

CButtonm_cOk;

CButtonm_cExit;

//NOTE:

theClassWizardwilladddatamembershere

//}}AFX_DATA

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(CMyDlg)

protected:

virtualvoidDoDataExchange(CDataExchange*pDX);

//DDX/DDVsupport

//}}AFX_VIRTUAL

//Implementation

protected:

HICONm_hIcon;

voidfun(char*str,doublea[],intex[],intey[]);

PolyNomial*AddNewItem(PolyNomial*polynomialExpress,PolyNodeitem);

doublejifen(PolyNomialpoly,doublex_min,doublex_max);

doubleerchongjifen(PolyNomialpoly,doublex_min,doublex_max,doubley_min,doubley_max);

//Generatedmessagemapfunctions

//{{AFX_MSG(CMyDlg)

virtualBOOLOnInitDialog();

afx_msgvoidOnPaint();

afx_msgHCURSOROnQueryDragIcon();

afx_msgvoidOnRadio1();

afx_msgvoidOnRadio2();

afx_msgvoidOnOk();

afx_msgvoidOnExit();

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

//{{AFX_INSERT_LOCATION}}

//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.

#endif//!

求解多项式积分Dlg.cpp:

//求解多项式积分Dlg.cpp:

implementationfile

#include"

stdafx.h"

求解多项式积分.h"

求解多项式积分Dlg.h"

#include<

math.h>

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

CMyDlg:

:

CMyDlg(CWnd*pParent/*=NULL*/)

:

CDialog(CMyDlg:

IDD,pParent)

//{{AFX_DATA_INIT(CMyDlg)

theClassWizardwilladdmemberinitializationhere

//}}AFX_DATA_INIT

//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32

m_hIcon=AfxGetApp()->

LoadIcon(IDR_MAINFRAME);

}

voidCMyDlg:

DoDataExchange(CDataExchange*pDX)

CDialog:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(CMyDlg)

theClassWizardwilladdDDXandDDVcallshere

DDX_Control(pDX,IDC_FUN,m_cFun);

DDX_Control(pDX,IDC_EDIT1,m_cXmin);

DDX_Control(pDX,IDC_EDIT2,m_cXmax);

DDX_Control(pDX,IDC_EDIT3,m_cYmin);

DDX_Control(pDX,IDC_EDIT4,m_cYmax);

DDX_Control(pDX,IDOK,m_cOk);

DDX_Control(pDX,IDEXIT,m_cExit);

//}}AFX_DATA_MAP

BEGIN_MESSAGE_MAP(CMyDlg,CDialog)

//{{AFX_MSG_MAP(CMyDlg)

ON_WM_PAINT()

ON_WM_QUERYDRAGICON()

ON_BN_CLICKED(IDOK,OnOk)

ON_BN_CLICKED(IDEXIT,OnExit)

ON_BN_CLICKED(IDC_RADIO1,OnRadio1)

ON_BN_CLICKED(IDC_RADIO2,OnRadio2)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

//CMyDlgmessagehandlers

BOOLCMyDlg:

OnInitDialog()

OnInitDialog();

//Settheiconforthisdialog.Theframeworkdoesthisautomatically

//whentheapplication'

smainwindowisnotadialog

SetIcon(m_hIcon,TRUE);

//Setbigicon

SetIcon(m_hIcon,FALSE);

//Setsmallicon

//TODO:

Addextrainitializationhere

CButton*radio=(CButton*)GetDlgItem(IDC_RADIO1);

radio->

SetCheck

(1);

m_cXmin.EnableWindow();

m_cXmax.EnableWindow();

m_cYmin.EnableWindow(false);

m_cYmax.EnableWindow(false);

returnTRUE;

//returnTRUEunlessyousetthefocustoacontrol

//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow

//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,

//thisisautomaticallydoneforyoubytheframework.

OnPaint()

if(IsIconic())

{

CPaintDCdc(this);

//devicecontextforpainting

SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);

//Centericoninclientrectangle

intcxIcon=GetSystemMetrics(SM_CXICON);

intcyIcon=GetSystemMetrics(SM_CYICON);

CRectrect;

GetClientRect(&

rect);

intx=(rect.Width()-cxIcon+1)/2;

inty=(rect.Height()-cyIcon+1)/2;

//Drawtheicon

dc.DrawIcon(x,y,m_hIcon);

}

else

OnPaint();

//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags

//theminimizedwindow.

HCURSORCMyDlg:

OnQueryDragIcon()

return(HCURSOR)m_hIcon;

OnRadio1()

OnRadio2()

m_cYmin.EnableWindow();

m_cYmax.EnableWindow();

OnOk()

if(((CButton*)GetDlgItem(IDC_RADIO1))->

GetCheck())

CStringtext,x_min,x_max;

m_cFun.GetWindowText(text);

m_cXmin.GetWindowText(x_min);

m_cXmax.GetWindowText(x_max);

char*c_text;

c_text=(LPSTR)(LPCTSTR)text;

doublef_x_min,f_x_max;

f_x_min=atof(x_min);

f_x_max=atof(x_max);

doublea[10]={0.0};

intex[10]={0};

intey[10]={0};

fun(c_text,a,ex,ey);

inti;

PolyNomial*polynomialExpress=NULL;

for(i=0;

i<

10;

i++)

if(a[i]!

=0.0)

PolyNodenode;

node.a=a[i];

node.ex=ex[i];

node.ey=ey[i];

polynomialExpress=AddNewItem(polynomialExpress,node);

doubleresult;

result=jifen(*polynomialExpress,f_x_min,f_x_max);

CStringr;

r.Format(_T("

%lf"

),result);

CStringstr="

积分为:

"

;

str=str+r;

CStatic*pStatic=(CStatic*)GetDlgItem(IDC_STATIC_RESULT);

pStatic->

SetWindowText(str);

if(((CButton*)GetDlgItem(IDC_RADIO2))->

CStringtext,x_min,x_max,y_min,y_max;

m_cYmin.GetWindowText(y_min);

m_cYmax.GetWindowText(y_max);

doublef_x_min,f_x_max,f_y_min,f_y_max;

f_y_min=atof(y_min);

f_y_max=atof(y_max);

result=erchongjifen(*polynomialExpress,f_x_min,f_x_max,f_y_min,f_y_max);

OnExit()

OnCancel();

fun(char*str,doublea[],intex[],intey[])

intindex_a=0;

intindex_ex=0;

intindex_ey=0;

inttmp_a=0;

inttmp_ex=0;

inttmp_ey=0;

intnegative_number=1;

//系数的正负号

boolis_X_front=true;

//判断是系数还是指数,X前面的是系数,X后面是指数

boolis_Y_front=true;

//判断是X的指数还是Y的指数

boolfirst=false;

//判断是否存在"

^"

符号

boolsecond=false;

boolx=false;

booly=false;

int(strlen(str))+1;

charc;

c=str[i];

if(c=='

X'

||c=='

x'

if(tmp_a==0)

tmp_a=1;

a[index_a++]=double(negative_number*tmp_a);

is_X_front=false;

x=true;

Y'

y'

if(is_X_front)

is_Y_front=false;

y=true;

elseif(c=='

^'

if(is_Y_front){

first=true;

}else{

second=true;

+'

-'

\0'

if(x&

&

!

first)

tmp_ex=1;

if(y&

second)

tmp_ey=1;

if(i!

=0)

ex[index_ex++]=tmp_ex;

ey[index_ey++]=tmp_ey;

is_X_front=true;

is_Y_front=true;

tmp_a=0;

tmp_ex=0;

tmp_ey=0;

x=false;

y=false;

first=false;

second=false;

negative_number=1;

negative_number=-1;

elseif('

0'

<

=c&

c<

='

9'

tmp_a=10*tmp_a+(c-'

);

elseif(!

is_X_front&

is_Y_front)

tmp_ex=10*tmp_ex+(c-'

tmp_ey=10*tmp_ey+

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

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2