个性化推荐系统代码_第1页
个性化推荐系统代码_第2页
个性化推荐系统代码_第3页
个性化推荐系统代码_第4页
个性化推荐系统代码_第5页
已阅读5页,还剩21页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Newstj.h#include using namespace std;class newsdypublic:string newsid;int times;newsdy *next;newsdy();class newstjpublic:int sum;string newsid;newstj *next;newsdy *NDYnext;newstj();Newstj.cpp#include StdAfx.h#include newstj.hnewsdy:newsdy()newsid= ;times=0;next=NULL;newstj:newstj()newsid= ;next=NULL;sum=0;NDYnext=new newsdy;Recommend.h/ Recommend.h : PROJECT_NAME 应用程序的主头文件/#pragma once#ifndef _AFXWIN_H_#error 在包含此文件之前包含“stdafx.h”以生成 PCH 文件#endif#include resource.h/ 主符号/ CRecommendApp:/ 有关此类的实现,请参阅 Recommend.cpp/class CRecommendApp : public CWinApppublic:CRecommendApp();/ 重写public:virtual BOOL InitInstance();/ 实现?DECLARE_MESSAGE_MAP();extern CRecommendApp theApp;Recommend.cpp/ Recommend.cpp : 定义?应|用?程序的?类行D为a。/#include stdafx.h#include Recommend.h#include RecommendDlg.h#ifdef _DEBUG#define new DEBUG_NEW#endif/ CRecommendAppBEGIN_MESSAGE_MAP(CRecommendApp, CWinApp)ON_COMMAND(ID_HELP, &CWinApp:OnHelp)END_MESSAGE_MAP()/ CRecommendApp 构造CRecommendApp:CRecommendApp()/ 支持重新启动管理器m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;/ TODO: 在此处添加构造代码/ 将?所有D重?要a的?初?始?化放?置?在 InitInstance 中D/ 唯一?的?一?个? CRecommendApp 对?象CRecommendApp theApp;/ Recommend.cpp : 定义?应|用?程序的?类行D为a。/#include stdafx.h#include Recommend.h#include RecommendDlg.h#ifdef _DEBUG#define new DEBUG_NEW#endif/ CRecommendAppBEGIN_MESSAGE_MAP(CRecommendApp, CWinApp)ON_COMMAND(ID_HELP, &CWinApp:OnHelp)END_MESSAGE_MAP()/ CRecommendApp 构1造CRecommendApp:CRecommendApp()/ 支持?重?新?启?动管理器m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;/ TODO: 在此?处|添加构1造代码?,?/ 将?所有D重?要a的?初?始?化放?置?在 InitInstance 中D/ 唯一?的?一?个? CRecommendApp 对?象CRecommendApp theApp;/ CRecommendApp 初?始?化BOOL CRecommendApp:InitInstance()/ 如?果?一?个?运?行D在 Windows XP 上?的?应|用?程序清?单指?定要a/ 使1用? ComCtl32.dll 版?本? 6 或更高?版?本?来启?用?可视化方?式?,?/则需要a InitCommonControlsEx()。否?则,?将?无T法创建窗口。INITCOMMONCONTROLSEX InitCtrls;InitCtrls.dwSize = sizeof(InitCtrls);/ 将?它设置?为a包括所有D要a在应|用?程序中D使1用?的?/ 公?共2控?件t类。InitCtrls.dwICC = ICC_WIN95_CLASSES;InitCommonControlsEx(&InitCtrls);CWinApp:InitInstance();AfxEnableControlContainer();/ 创建 shell 管理器,?以?防对?话框包含?/ 任?何? shell 树视图?控?件t或 shell 列D表视图?控?件t。CShellManager *pShellManager = new CShellManager;/ 标准?初?始?化/ 如?果?未使1用?这a些?功|能并希望?减?小?/ 最?终?可执行D文?件t的?大小?,?则应|移?除y下?列D/ 不?需要a的?特?定初?始?化例y程/ 更改?用?于存?储设置?的?注册表项?/ TODO: 应|适当修T改?该?字?符?串?,?/ 例y如?修T改?为a公?司?或组织名?SetRegistryKey(_T(应|用?程序向导?生成的?本?地?应|用?程序);CRecommendDlg dlg;m_pMainWnd = &dlg;INT_PTR nResponse = dlg.DoModal();if (nResponse = IDOK)/ TODO: 在此?放?置?处|理何?时用?/ “确定”来关?闭?对?话框的?代码?else if (nResponse = IDCANCEL)/ TODO: 在此?放?置?处|理何?时用?/ “取?消?”来关?闭?对?话框的?代码?/ 删?除y上?面?创建的? shell 管理器。if (pShellManager != NULL)delete pShellManager;/ 由于对?话框已?关?闭?,?所以?将?返回? FALSE 以?便?退?出?应|用?程序,?/ 而?不?是?启?动应|用?程序的?消?息泵?。return FALSE;RecommendDlg.h/ RecommendDlg.h : 头文?件t/#pragma once#include afxwin.h#include afxcmn.h#include #include #include #include #include #include #include #include #include #include #include user.h#include newstj.h#include using namespace std;/ CRecommendDlg 对?话框class CRecommendDlg : public CDialogEx/ 构1造public:CRecommendDlg(CWnd* pParent = NULL);/ 标准?构1造函数y/ 对?话框数y据Yenum IDD = IDD_RECOMMEND_DIALOG ;protected:virtual void DoDataExchange(CDataExchange* pDX);/ DDX/DDV 支持?/ 实现?protected:HICON m_hIcon;/ 生成的?消?息映3射?函数yvirtual BOOL OnInitDialog();afx_msg void OnSysCommand(UINT nID, LPARAM lParam);afx_msg void OnPaint();afx_msg HCURSOR OnQueryDragIcon();DECLARE_MESSAGE_MAP()public:void DisPlay(CString str);CString file_str;CEdit m_Edit_Dis;CListCtrl m_CListCtrl;int num;CString STR;string str;newstj *TJtemp,*TJhead;newsdy *DYtemp,*DYhead;user *temp,*head;user *Ctemp,*Chead;news *ntemp,*nhead;afx_msg void OnBnClickedBtnList();afx_msg void OnBnClickedBtnSum();afx_msg void OnBnClickedBtnOut();afx_msg void OnBnClickedBtnOpen();afx_msg void OnBnClickedBtnC();afx_msg void OnBnClickedBtn();afx_msg void OnBnClickedBtnNt();afx_msg void OnBnClickedBtnChosen();afx_msg void OnBnClickedBtnSt();afx_msg void OnEnChangeEditDis();static UINT Thread(LPVOID lpParam);static UINT Thread_T(LPVOID lpParam);static UINT Thread_O(LPVOID lpParam);static UINT Thread_C(LPVOID lpParam);long long time;struct timeb t1;struct timeb t2;CString strTime;CSliderCtrl m_CSliderCtrl;afx_msg void OnBnClickedBtnSure();RecommendDlg.cpp/ RecommendDlg.cpp : 实现?文?件t/#include stdafx.h#include Recommend.h#include RecommendDlg.h#include afxdialogex.h#ifdef _DEBUG#define new DEBUG_NEW#endif/ 用?于应|用?程序“关?于”菜?单项?的? CAboutDlg 对?话框CWinThread* pThread;CWinThread* pThread_t;CWinThread* pThread_o;CWinThread* pThread_c;UINT CRecommendDlg:Thread(LPVOID lpParam)/接受的?死循-环所在线?程CRecommendDlg *p=(CRecommendDlg*)lpParam;ifstream file(p-file_str);/读入?步?相关?数y据Yp-DisPlay(CString(成功|打开astep_correlation,路径?:+p-file_str);ftime(&p-t1);int js=0;while(getline(file,p-str)stringstream ss(p-str);string sub_str;int i=0;while(getline(ss,sub_str,t)if(i=0)p-TJtemp=p-TJhead;for(;p-TJtemp=p-TJtemp-next)if(p-TJtemp-newsid= )break;elseif(p-TJtemp-newsid=sub_str)break;i=1;elsep-DYtemp=p-TJtemp-NDYnext;for(;p-DYtemp=p-DYtemp-next)if(p-DYtemp-newsid= )p-DYtemp-newsid=sub_str;p-DYtemp-times+;p-DYtemp-next=new newsdy;break;elseif(p-DYtemp-newsid=sub_str)p-DYtemp-times+;break;i=0;js+;ftime(&p-t2);file.close();p-STR.Format(%d,js);p-strTime.Format(%lldms,p-t2.time*1000-p-t1.time*1000);p-DisPlay(CString(读取?完成.共2读取?+p-STR+记?录?,耗?时 +p-strTime);return 0;UINT CRecommendDlg:Thread_T(LPVOID lpParam)/接受的?死循-环所在线?程CRecommendDlg *p=(CRecommendDlg*)lpParam;ifstream fileuser(p-file_str);/读入?用?户最?后访?问列D表p-DisPlay(CString(成功|打开auser_list,路径?:+p-file_str);ftime(&p-t1);int js=0;while(getline(fileuser,p-str)stringstream ss(p-str);string sub_str;int i=0;while(getline(ss,sub_str,t)if(i=0)p-temp-userid=sub_str;i=1;elseif(i=1)p-temp-newsid=sub_str;p-temp-next=new user;p-temp=p-temp-next;i=0;p-temp-next=new user;js+;ftime(&p-t2);fileuser.close();p-STR.Format(%d,js);p-strTime.Format(%lldms,p-t2.time*1000-p-t1.time*1000+litm);p-DisPlay(CString(读取?完成.共2读取?+p-STR+记?录?,耗?时 +p-strTime);p-temp=p-head;p-TJtemp=p-TJhead;p-DisPlay(CString(开a始?计?算?);ftime(&p-t1);for(;p-temp=p-temp-next)if(p-temp-userid= )break;p-TJtemp=p-TJhead;for(;p-TJtemp=p-TJtemp-next)if(p-TJtemp-newsid=p-temp-newsid|p-TJtemp-newsid= )break;p-DYtemp=p-TJtemp-NDYnext;int sum=0,sum1=0;for(;p-DYtemp=p-DYtemp-next)if(p-DYtemp-newsid= )break;if(p-DYtemp-timesp-m_CSliderCtrl.GetPos()if(sum1DYtemp-times)if(sumDYtemp-times|sum=p-DYtemp-times)sum1=sum;sum=p-DYtemp-times;p-temp-res1=p-temp-res;p-temp-res=p-DYtemp-newsid;elsesum1=p-DYtemp-times;p-temp-res1=p-DYtemp-newsid;p-temp-t=sum;p-temp-t1=sum1;ftime(&p-t2);p-strTime.Format(%llds,p-t2.time*1000-p-t1.time*1000+litm);p-DisPlay(CString(计?算?完成,共2耗?时 +p-strTime);return 0;UINT CRecommendDlg:Thread_O(LPVOID lpParam)/接受的?死循-环所在线?程CRecommendDlg *p=(CRecommendDlg*)lpParam;ofstream fout(c:/out.csv);p-DisPlay(CString(正y在输?出?,路径?:c:/out.csv);p-temp=p-head;foutuserid,newsidtemp=p-temp-next)if(p-temp-userid= )break;elsep-TJtemp=p-TJhead;for(;p-TJtemp=p-TJtemp-next)if(p-TJtemp-newsid=p-temp-newsid)break;int k=atoi(p-temp-cs.c_str();int l=atoi(p-temp-cs_.c_str();if(k!=0&lTJtemp-sum10)if(p-temp-res!= )fouttemp-userid,temp-restemp-res1!= &(100*abs(p-temp-t-p-temp-t1)/p-temp-ttemp-res1!=p-temp-res)fouttemp-userid,temp-res1DisPlay(CString(输?出?完成.);return 0;UINT CRecommendDlg:Thread_C(LPVOID lpParam)/接受的?死循-环所在线?程CRecommendDlg *p=(CRecommendDlg*)lpParam;ifstream fileinput(p-file_str);/读入?用?户最?后访?问列D表p-DisPlay(CString(成功|打开adata,路径?:+p-file_str);ftime(&p-t1);int js=0;while(getline(fileinput,p-str)stringstream ss(p-str);string sub_str;int i=0;while(getline(ss,sub_str,t)if(i=0)if(p-Ctemp-userid= )p-Ctemp-userid=sub_str;p-Ctemp-next=new user;p-ntemp=p-Ctemp-Nnext;i=1;elseif(p-Ctemp-userid!=sub_str)p-Ctemp=p-Ctemp-next;p-Ctemp-userid=sub_str;p-Ctemp-next=new user;p-ntemp=p-Ctemp-Nnext;i=1;elsei=1;elsep-ntemp-newsid=sub_str;p-ntemp-next=new news;p-ntemp=p-ntemp-next;i=0;js+;ftime(&p-t2);fileinput.close();p-STR.Format(%d,js);p-strTime.Format(%lldms,p-t2.time*1000-p-t1.time*1000+litm);p-DisPlay(CString(读取?完成.共2读取?+p-STR+记?录?,耗?时 +p-strTime);ofstream fout(step_correlation.txt);p-Ctemp=p-Chead;for(;p-Ctemp=p-Ctemp-next)if(p-Ctemp-userid= )break;p-ntemp=p-Ctemp-Nnext;for(;p-ntemp=p-ntemp-next)if(p-ntemp-next-newsid= )break;foutntemp-next-newsidtntemp-newsidDisPlay(CString(输?出?完成.);return 0;class CAboutDlg : public CDialogExpublic:CAboutDlg();/ 对?话框数y据Yenum IDD = IDD_ABOUTBOX ;protected:virtual void DoDataExchange(CDataExchange* pDX); / DDX/DDV 支持?/ 实现?protected:DECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialogEx(CAboutDlg:IDD)void CAboutDlg:DoDataExchange(CDataExchange* pDX)CDialogEx:DoDataExchange(pDX);BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)END_MESSAGE_MAP()/ CRecommendDlg 对?话框CRecommendDlg:CRecommendDlg(CWnd* pParent /*=NULL*/): CDialogEx(CRecommendDlg:IDD, pParent)m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);void CRecommendDlg:DoDataExchange(CDataExchange* pDX)CDialogEx:DoDataExchange(pDX);DDX_Control(pDX, IDC_LIST1, m_CListCtrl);DDX_Control(pDX, IDC_SLIDER, m_CSliderCtrl);BEGIN_MESSAGE_MAP(CRecommendDlg, CDialogEx)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BTN_CHOSEN, &CRecommendDlg:OnBnClickedBtnChosen)ON_BN_CLICKED(IDC_BTN, &CRecommendDlg:OnBnClickedBtn)ON_BN_CLICKED(IDC_BTN_NT, &CRecommendDlg:OnBnClickedBtnNt)ON_BN_CLICKED(IDC_BTN_ST, &CRecommendDlg:OnBnClickedBtnSt)ON_BN_CLICKED(IDC_BTN_LIST, &CRecommendDlg:OnBnClickedBtnList)ON_BN_CLICKED(IDC_BTN_SUM, &CRecommendDlg:OnBnClickedBtnSum)ON_BN_CLICKED(IDC_BTN_OUT, &CRecommendDlg:OnBnClickedBtnOut)ON_BN_CLICKED(IDC_BTN_OPEN, &CRecommendDlg:OnBnClickedBtnOpen)ON_BN_CLICKED(IDC_BTN_C, &CRecommendDlg:OnBnClickedBtnC)ON_BN_CLICKED(IDC_BTN_SURE, &CRecommendDlg:OnBnClickedBtnSure)END_MESSAGE_MAP()/ CRecommendDlg 消?息处|理程序void CRecommendDlg:DisPlay(CString str)CString num_str;num_str.Format(%d,num);m_CListCtrl.InsertItem(num,num_str);m_CListCtrl.SetItemText(num,1,str);num+;BOOL CRecommendDlg:OnInitDialog()CDialogEx:OnInitDialog();/ 将?“关?于.”菜?单项?添加到?系统3菜?单中D。/ IDM_ABOUTBOX 必?须?在系统3命令?范?围内。ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);/ 设置?此?对?话框的?图?标。当应|用?程序主窗口不?是?对?话框时,?框架将?自?动/ 执行D此?操作SetIcon(m_hIcon, TRUE);/ 设置?大图?标SetIcon(m_hIcon, FALSE);/ 设置?小?图?标/ TODO: 在此?添加额?外a的?初?始?化代码?m_CListCtrl.InsertColumn(0,_T(序号?),LVCFMT_CENTER, 40, -1);m_CListCtrl.InsertColumn(1,_T(行D为a),LVCFMT_CENTER, 390, -1);m_CSliderCtrl.SetRange(5,20,FALSE);m_CSliderCtrl.SetLineSize(1);num=0;DisPlay(CString(欢?迎-使1用?本?软件t,请?参?照?说明使1用?.);TJtemp=new newstj;TJhead=TJtemp;DYtemp=new newsdy;DYhead=DYtemp;temp=new user;head=temp;Ctemp=new user;Chead=Ctemp;ntemp=new news;nhead=ntemp;return TRUE; / 除y非?将?焦1点?设置?到?控?件t,?否?则返回? TRUEvoid CRecommendDlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();elseCDialogEx:OnSysCommand(nID, lParam);/ 如?果?向对?话框添加最?小?化按钮,?则需要a下?面?的?代码?/ 来绘?制?该?图?标。对?于使1用?文?档/视图?模型的? MFC 应|用?程序,?/ 这a将?由框架自?动完成。void CRecommendDlg:OnPaint()if (IsIconic()CPaintDC dc(this); / 用?于绘?制?的?设备?上?下?文?SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc(), 0);/ 使1图?标在工作区?矩?形?中D居中Dint cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;/ 绘?制?图?标dc.DrawIcon(x, y, m_hIcon);elseCDialogEx:OnPaint();/当用?户拖?动最?小?化窗口时系统3调用?此?函数y取?得?光a标/显?示?。HCURSOR CRecommendDlg:OnQueryDragIcon()return static_cast(m_hIcon);void CRecommendDlg:OnBnClickedBtnChosen()/ TODO: 在此?添加控?件t通知a处|理程序代码?CFileDialog fdlg(TRUE);if(fdlg.DoModal()=IDOK)file_str=fdlg.GetPathName();GetDlgItem(IDC_BTN_FILEPATH)-SetWindowText(file_str);void CRecommendDlg:OnBnClickedBtn()/ TODO: 在此?添加控?件t通知a处|理程序代码?ifstream list(file_str);DisPlay(CString(成功|打开anews_list,路径?:+file_str);ftime(&t1);int js=0;while(getline(list,str)TJtemp-newsid=str;TJtemp-next=new newstj;TJtemp=TJtemp-next;js+;TJtemp-next=new newstj;ftime(&t2);list.close();STR.Format(%d,js);strTime.Format(%lldms,t2.time*1000-t1.time*1000+litm);DisPlay(CString(读取?完成.共2读取?+STR+记?录?,耗?时 +strTime);void CRecommendDlg:OnBnClickedBtnNt()/ TODO: 在此?添加控?件t通知a处|理程序代码?ifstream fnews(file_str);DisPlay(CString(成功|打开anews_times,路径?:+file_str);ftime(&t1);TJtemp=TJhead;int js=0;while(getline(fnews,str)stringstream ss(str);string sub_str;int i=0;while(getline(ss,sub_str,t)if(i=0)i=1;elseTJtemp-sum=atoi(sub_str.c_str();TJtemp=TJtemp-next;i=0;js+;ftime(&t2);fnews.close();TJtemp=TJhead;STR.Format(%d,js);strTime.Format(%lldms,t2.time*1000-t1.time*1000+litm);DisPlay(CString(读取?完成.共2读取?+STR+记?录?,耗?时 +strTime);void CRecommendDlg:OnBnClickedBtnSt()/ TODO: 在此?添加控?件t通知a处|理程序代码?pThread=Af

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论