⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlg_sort.cpp

📁 bayes分类的数值实现
💻 CPP
字号:
// DLG_SORT.cpp : implementation file
//

#include "stdafx.h"
#include "第一次作业.h"
#include "DLG_SORT.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// DLG_SORT dialog


DLG_SORT::DLG_SORT(CWnd* pParent /*=NULL*/)
	: CDialog(DLG_SORT::IDD, pParent)
{

	//{{AFX_DATA_INIT(DLG_SORT)
	G_X = _T("");
	m_Gx = _T("");
	//}}AFX_DATA_INIT
}


void DLG_SORT::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DLG_SORT)
	DDX_Text(pDX, IDC_STATIC_Result, G_X);
	DDX_Text(pDX, IDC_STATIC_Gx, m_Gx);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(DLG_SORT, CDialog)
	//{{AFX_MSG_MAP(DLG_SORT)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// DLG_SORT message handlers

void DLG_SORT::OnPaint() 
{
	//	UpdateData(true);
	CPaintDC dc(this); // device context for painting	
	// TODO: Add your message handler code here
	CRect rect;
	dc.SetBkMode(TRANSPARENT);	
	GetClientRect(rect);	
	dc.FillSolidRect(rect,RGB(255,255,255)); //设置为白色背景

	CPoint p;
	float g;
	float x,y;
	for(int i=20;i<rect.Width()-20;i++)
		for(int j=20;j<rect.Height()-20;j++)
		{	
			x=float(i-rect.Width()/2)/20;//相对坐标
			y=float(rect.Height()/2-j)/20;//相对坐标
			g=a[0]*x*x+a[1]*y*y+a[2]*x+a[3]*y+a[4]*x*y+a[5];//判别函数
			p.x=i;
			p.y=j;

			if(g<0)
				dc.SetPixel(p,RGB(137,215,228));//蓝色属于ω1类
			else if(g>0)
				dc.SetPixel(p,RGB(103,103,103));//灰色属于ω2类
			else
				dc.SetPixel(p,RGB(0,255,255));//其他
		}
	dc.TextOut(rect.Width()/2+10,10,"X2");//x2
	dc.TextOut(rect.Width()-20,rect.Height()/2+5,"X1");	//x1
	dc.TextOut(rect.Width()-22,rect.Height()/2-8,">");//x1方向
	dc.MoveTo(rect.Width()/2-5,16);
	dc.LineTo(rect.Width()/2,10);
	dc.LineTo(rect.Width()/2+5,17);
	//x1轴
	dc.MoveTo(10,rect.Height()/2);
	dc.LineTo(rect.Width()-18,rect.Height()/2);
	//x2轴
	dc.MoveTo(rect.Width()/2,rect.Height()-20);
	dc.LineTo(rect.Width()/2,10);
	//原点
	dc.TextOut(rect.Width()/2+1,rect.Height()/2+1,"O");
	//绘制间隔
	for(i=20;i<200;i+=20)
	{
	
		dc.MoveTo(rect.Width()/2+i,rect.Height()/2);
		dc.LineTo(rect.Width()/2+i,rect.Height()/2-3);		
		dc.MoveTo(rect.Width()/2-i,rect.Height()/2);
		dc.LineTo(rect.Width()/2-i,rect.Height()/2-3);		
		dc.MoveTo(rect.Width()/2,rect.Height()/2+i);
		dc.LineTo(rect.Width()/2+3,rect.Height()/2+i);		
		dc.MoveTo(rect.Width()/2,rect.Height()/2-i);
		dc.LineTo(rect.Width()/2+3,rect.Height()/2-i);	
	}
	dc.TextOut(rect.Width()/2+20,rect.Height()/2-1,"1");
	dc.TextOut(rect.Width()/2-22,rect.Height()/2-1,"-1");	
	dc.TextOut(rect.Width()/2+3,rect.Height()/2-25,"1");
	dc.TextOut(rect.Width()/2+5,rect.Height()/2+12,"-1");
	UpdateData(false);
	// Do not call CDialog::OnPaint() for painting messages
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -