📄 083007_naview.cpp
字号:
// 083007_NAView.cpp : implementation of the CMy083007_NAView class
//
#include "stdafx.h"
#include "083007_NA.h"
#include "083007_NADoc.h"
#include "083007_NAView.h"
#include "Input.h"
#include "NumAnalysis.h"
#include "iostream.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMy083007_NAView
IMPLEMENT_DYNCREATE(CMy083007_NAView, CView)
BEGIN_MESSAGE_MAP(CMy083007_NAView, CView)
//{{AFX_MSG_MAP(CMy083007_NAView)
ON_COMMAND(ID_Newton, OnNewton)
ON_COMMAND(ID_SEARCH, OnSearch)
ON_COMMAND(ID_DIEDAI, OnDiedai)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy083007_NAView construction/destruction
CMy083007_NAView::CMy083007_NAView()
{
// TODO: add construction code here
}
CMy083007_NAView::~CMy083007_NAView()
{
}
BOOL CMy083007_NAView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMy083007_NAView drawing
void CMy083007_NAView::OnDraw(CDC* pDC)
{
CMy083007_NADoc* pDoc = GetDocument();
//pDC->TextOut()
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMy083007_NAView printing
BOOL CMy083007_NAView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMy083007_NAView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMy083007_NAView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMy083007_NAView diagnostics
#ifdef _DEBUG
void CMy083007_NAView::AssertValid() const
{
CView::AssertValid();
}
void CMy083007_NAView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMy083007_NADoc* CMy083007_NAView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy083007_NADoc)));
return (CMy083007_NADoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMy083007_NAView message handlers
void CMy083007_NAView::showans(float ans,int L)
{
int a,b[4];
char st2[10];
char st1[]="The answer x~ = ";
char st3[]=" *10-4\n";
char stL1[]="迭代次数为:";
char stL2[5];
if(ans==100) AfxMessageBox("牛顿迭代公式发散");
else
{
if(ans<0)st2[0]='-';
else st2[0]='+';
a=(int) (ans*10000);
a=abs(a);
b[0]=a/1000;
a=a%1000;
b[1]=a/100;
a=a%100;
b[2]=a/10;
a=a%10;
b[3]=a;
for(int i=1;i<5;i++){
st2[i]=b[i-1]+48;
}
st2[i]='\0';
strcat(st1,st2);
strcat(st1,st3);
strcat(st1,stL1);
stL2[0]=L/10+48;
if(stL2[0]=='0')stL2[0]=' ';
L=L%10;
stL2[1]=L+48;
stL2[2]='\0';
strcat(st1,stL2);
AfxMessageBox(st1,MB_OK);
}
}
void CMy083007_NAView::OnNewton()
{
int A,B;
float C;
double D;
CInput myDlg;
if(myDlg.DoModal()!=IDOK){
return;
}
A=myDlg.m_A1;
B=myDlg.m_B1;
C=myDlg.m_CHUZHI;
D=myDlg.m_WUCHA;
ans=naly.Newton(A,B,C,D);
DL=naly.NL;
showans(ans,DL);
}
void CMy083007_NAView::tansform(float A, UINT B)
{
}
void CMy083007_NAView::OnSearch()
{
float delta;
CSERCHDLG mySDlg;
if(mySDlg.DoModal()!=IDOK){
return;
}
// TODO: Add your command handler code here
//ans=naly.newton(0.77459);
delta=searchf();
showsf(delta);
}
float CMy083007_NAView::searchf()
{
float d,ans;
double d1;
d1=0.5000;
ans=0.001;
while(ans<1.730){
ans=naly.newton(d1);
d1+=0.0001;
}
d=(float)d1-0.0001;
return d;
}
void CMy083007_NAView::showsf(float dlt)
{
int a,b[4];
char st2[10];
char st1[]="The max value of δ = ";
st2[0]='0';
st2[1]='.';
a=(int) (dlt*10000);
a=abs(a);
b[0]=a/1000;
a=a%1000;
b[1]=a/100;
a=a%100;
b[2]=a/10;
a=a%10;
b[3]=a;
for(int i=2;i<6;i++){
st2[i]=b[i-2]+48;
}
st2[i]='\0';
strcat(st1,st2);
AfxMessageBox(st1,MB_OK);
}
void CMy083007_NAView::OnDiedai()
{
float S,W,ans;
int R;
CJUDGEDLG myJDlg;
if(myJDlg.DoModal()!=IDOK){
return;
}
S=myJDlg.m_start;
W=myJDlg.m_wucha;
R=myJDlg.range;
if(R>5||R<1){
AfxMessageBox("请选择X的范围!");
goto ss1;
}
if((R==1&&S<-1)||(R==2&&S>-1&&S<-0.7748)||(R==3&&S>-0.7748&&S<0.7748)||
(R==4&&S>0.7748&&S<1)||(R==5&&S>1)){
ans=naly.Shoulian(S,W);
showshoulian(ans,R);
}
else AfxMessageBox("请按照选择的X的范围,正确输入初值!");
ss1:
ans=0;
}
void CMy083007_NAView::showshoulian(float ans,int R)
{
int a,b[4];
char st1[]="Newton序列收敛!\n";
char st2[10];
char st3[]="收敛于根:";
// char stL1[]="迭代次数为:";
// char stL2[5];
if(ans==100) AfxMessageBox("Newton序列发散");
else
{
if(ans<0)st2[0]='-';
else st2[0]='+';
a=(int) (ans*10000);
a=abs(a);
if(a<10000){
st2[1]='0';
st2[2]='.';
b[0]=a/1000;
a=a%1000;
b[1]=a/100;
a=a%100;
b[2]=a/10;
a=a%10;
b[3]=a;
}
else{
st2[1]='1';
st2[2]='.';
b[0]=a/1000-10;
a=a%1000;
b[1]=a/100;
a=a%100;
b[2]=a/10;
a=a%10;
b[3]=a;
}
for(int i=3;i<7;i++){
st2[i]=b[i-3]+48;
}
st2[i]='\0';
strcat(st3,st2);
strcat(st1,st3);
/* strcat(st1,stL1);
stL2[0]=L/10+48;
if(stL2[0]=='0')stL2[0]=' ';
L=L%10;
stL2[1]=L+48;
stL2[2]='\0';
strcat(st1,stL2);*/
AfxMessageBox(st1,MB_OK);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -