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

📄 wajue.cpp

📁 用Visual c++写
💻 CPP
字号:
// Wajue.cpp : implementation file
//

#include "stdafx.h"
#include "mining.h"
#include "Wajue.h"

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

/////////////////////////////////////////////////////////////////////////////
// CWajue dialog

extern TreeNode dt;

CWajue::CWajue(CWnd* pParent /*=NULL*/)
	: CDialog(CWajue::IDD, pParent)
{
	nCount=0;
	//{{AFX_DATA_INIT(CWajue)
	//}}AFX_DATA_INIT
}


void CWajue::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWajue)
	DDX_Control(pDX, IDC_LIST4, m_guize);
	DDX_Control(pDX, IDC_LIST2, m_yucelie);
	DDX_Control(pDX, IDC_LIST1, m_shurulie);
	DDX_Control(pDX, IDC_TREE1, m_tree);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CWajue, CDialog)
	//{{AFX_MSG_MAP(CWajue)
	ON_BN_CLICKED(IDC_WAJUE, OnWajue)
	ON_BN_CLICKED(IDC_CLOSE, OnGuanbi)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWajue message handlers

BOOL CWajue::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CODBCFieldInfo fldInfo;
	CHAR ***string;
	CHAR **title;
	int height=0,width=0;
	CDTID3 id3;
	TreeNode *node;

	m_RecJoin.Open(AFX_DB_USE_DEFAULT_TYPE,"SELECT * FROM 学校成绩表,过级成绩表\
		where 学校成绩表.学号=过级成绩表.学号");
	

	//得到记录集的字段数和记录数
	m_RecJoin.MoveFirst();
	while(!m_RecJoin.IsEOF())
	{
		height++;
		m_RecJoin.MoveNext();
	}
	width=m_RecJoin.GetODBCFieldCount()-3;

	//得到记录集的各个字段的名字
	title= (CHAR**) malloc (width * sizeof (CHAR*));
/*	for(i=0;i<matrix.width;i++)
	{
		m_RecJoin.GetODBCFieldInfo(i,fldInfo);
		title[i]=fldInfo.m_strName.GetBuffer(fldInfo.m_strName.GetLength());
	}*/
	for(int m=0;m<width;m++)
		title[m]=(CHAR *)malloc(10 * sizeof(CHAR));
	
//测试
	LPSTR lpStr;
	m_RecJoin.GetODBCFieldInfo(1,fldInfo);
	lpStr=fldInfo.m_strName.GetBuffer(fldInfo.m_strName.GetLength());
	strcpy(title[0],lpStr);

	m_shurulie.InsertString(0,title[0]);	
	
	m_RecJoin.GetODBCFieldInfo(2,fldInfo);
	lpStr=fldInfo.m_strName.GetBuffer(fldInfo.m_strName.GetLength());
	strcpy(title[1],lpStr);
	m_shurulie.InsertString(1,title[1]);
	
	m_RecJoin.GetODBCFieldInfo(3,fldInfo);
	lpStr=fldInfo.m_strName.GetBuffer(fldInfo.m_strName.GetLength());
	strcpy(title[2],lpStr);
	m_shurulie.InsertString(2,title[2]);
	
	m_RecJoin.GetODBCFieldInfo(6,fldInfo);
	lpStr=fldInfo.m_strName.GetBuffer(fldInfo.m_strName.GetLength());
	strcpy(title[3],lpStr);
	m_shurulie.InsertString(3,title[3]);

	m_RecJoin.GetODBCFieldInfo(7,fldInfo);
	lpStr=fldInfo.m_strName.GetBuffer(fldInfo.m_strName.GetLength());
	strcpy(title[4],lpStr);
	m_yucelie.InsertString(0,title[4]);
	
	//将记录集的数据量化成适合我们的ID3算法的格式
	string=(char ***)malloc(height * sizeof(char **));
	for(int i=0;i<height;i++)
	{
		string[i]=(char **)malloc(width * sizeof(char *));
		for(int j=0;j<width;j++)
			string[i][j]=(char *)malloc(10 * sizeof(char));
	}

	m_RecJoin.MoveFirst();
	int k=0;
	while(!m_RecJoin.IsEOF())
	{
		CString s;
		
		if(m_RecJoin.m_column2<20)		//教学机时概化;
		{
			string[k][0]="低";
		}
		else if(m_RecJoin.m_column2<=29)
		{
			string[k][0]="中";
			
		}
		else if (m_RecJoin.m_column2<=40)
		{
			string[k][0]="高";
		}
		if(m_RecJoin.m_column3<20)			//自由机时概化;
		{
			string[k][1]="低";
		}
		else if(m_RecJoin.m_column3<=29)
		{
			string[k][1]="中";
		}
		else if (m_RecJoin.m_column3>=30)
		{
			string[k][1]="高";
		}
		if(m_RecJoin.m_column4<60)			//期末成绩概化;
		{
			string[k][2]="不及格";
		}
		else 
		{
			string[k][2]="及格";
		}
		char *zhuanye;
		zhuanye=m_RecJoin.m_column32.GetBuffer(m_RecJoin.m_column32.GetLength());
		if((strcmp(zhuanye,"化学")==0) ||		
			(strcmp(zhuanye,"计算机")==0) ||	
			(strcmp(zhuanye,"数学")==0) ||		
			(strcmp(zhuanye,"教育技术")==0))
		{
			string[k][3]="理科";
		}

		if((strcmp(zhuanye,"机器翻译")==0) ||		
			(strcmp(zhuanye,"教育学")==0) ||		
			(strcmp(zhuanye,"历史教育")==0) ||			
			(strcmp(zhuanye,"心理学")==0) ||
			(strcmp(zhuanye,"对外汉语")==0) ||
			(strcmp(zhuanye,"政教")==0))
		{
			string[k][3]="文科";
		}

		if(strcmp(zhuanye,"美术学")==0 ||
			strcmp(zhuanye,"体育")==0)
		{
			string[k][3]="艺术类";
		}

		if(m_RecJoin.m_column12<60)			//过级成绩概化
		{
			string[k][4]="不及格";
		}
		else 
		{
			string[k][4]="及格";
		}


		m_RecJoin.MoveNext();
		k++;
	}

	
	m_tree.SetTextColor(RGB(78,27,28));
	m_tree.SetBkColor(RGB(225,206,226));
	m_guize.SetTextBkColor(RGB(225,206,226));
	m_guize.SetBkColor(RGB(225,206,226));
	m_guize.SetTextColor(RGB(78,27,28));
	m_guize.InsertColumn(0,"规则",LVCFMT_LEFT,600);
	id3.PrepareID3(string,height,width,title);
	
	
	node=dt.child->node;
	VisitNode(NULL,node);

	FillList(node,NULL);

	CRect rectSeparator;
	GetWindowRect(&m_largeWindow);
	GetDlgItem(IDC_SEPARATOR)->GetWindowRect(&rectSeparator);
	m_smallWindow.left=m_largeWindow.left;
	m_smallWindow.top=m_largeWindow.top;
	m_smallWindow.right=m_largeWindow.right;
	m_smallWindow.bottom=rectSeparator.bottom;
	SetWindowPos(NULL,0,0,m_smallWindow.Width(),m_smallWindow.Height(),SWP_NOMOVE | SWP_NOZORDER);


	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CWajue::VisitNode(HTREEITEM hTreeParent, TreeNode *node)
{
	HTREEITEM	hTreeItem,hChildItem;
 	TV_INSERTSTRUCT	tvInsert;
 	tvInsert.hParent=hTreeParent;
 	tvInsert.hInsertAfter = TVI_LAST; 
 	tvInsert.item.mask=TVIF_TEXT;
 	tvInsert.item.pszText =(char *)malloc(sizeof(node->Title)+1);
 	strcpy(tvInsert.item.pszText,node->Title);
 	hTreeItem=m_tree.InsertItem(&tvInsert);
	free(tvInsert.item.pszText);
	tvInsert.item.pszText=NULL;
 
 	for(int i=0;i<node->nChildCount;i++)
 	{
 		tvInsert.hParent=hTreeItem;
 		tvInsert.hInsertAfter = TVI_LAST; 
 		tvInsert.item.mask=TVIF_TEXT;
 		tvInsert.item.pszText =(char *)malloc(strlen(node->child[i].value)+1);
 		strcpy(tvInsert.item.pszText,node->child[i].value);
 		hChildItem=m_tree.InsertItem(&tvInsert);

		free(tvInsert.item.pszText);
		tvInsert.item.pszText=NULL;
 
 		VisitNode(hChildItem,node->child[i].node);
 
 	}
 	m_tree.Expand(hTreeItem,TVE_EXPAND);

}

void CWajue::OnWajue() 
{
	SetWindowPos(NULL,0,0,m_largeWindow.Width(),m_largeWindow.Height(),SWP_NOMOVE | SWP_NOZORDER);
	
}

void CWajue::OnGuanbi() 
{
	if(m_RecJoin.IsOpen())
		m_RecJoin.Close();
	EndDialog(0);
	
}

void CWajue::OnClose() 
{
	if(m_RecJoin.IsOpen())
		m_RecJoin.Close();
	
	CDialog::OnClose();
}



void CWajue::FillList(TreeNode *node, char *str)
{
	ASSERT(node!=NULL);
	
	char str1[80];
	
	if(str!=NULL)
	{
		strcpy(str1,str);
	}

	if((strcmp(node->Title,"YES")==0) || (strcmp(node->Title,"NO")==0))
	{
		strcat(str1,"   THEN 过级成绩=");
		strcat(str1,node->Title);
		m_guize.InsertItem(nCount,str1,0);
		nCount++;

	}
	else
	{
		for(int i=0;i<node->nChildCount;i++)
		{
			char str2[80];
			if(str!=NULL)
			{			
				strcpy(str2,str1);
				strcat(str2," AND ");
				strcat(str2,node->Title);
				strcat(str2,"=");
				strcat(str2,node->child[i].value);
			}
			else
			{			
				strcpy(str2,"IF ");	
				strcat(str2,node->Title);
				strcat(str2,"=");
				strcat(str2,node->child[i].value);

			}
			FillList(node->child[i].node,str2);
		}
	}
	
	
}

⌨️ 快捷键说明

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