好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

实验8CSV数据文件操作.doc

15页
  • 卖家[上传人]:平***
  • 文档编号:13519472
  • 上传时间:2017-10-24
  • 文档格式:DOC
  • 文档大小:216.50KB
  • / 15 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 实验 8 CSV 数据文件操作实验目的:了解 CSV 格式数据记录文件结构,掌握大数据量记录的查询技巧实验内容:编程设计一个成语接龙游戏具体要求如下:1、判断输入词语是否是成语;2、可以判断是否符合成语接龙游戏规则;3、可以实现提示功能;4、可以实现显示成语含义的功能;实验步骤:(基于 MFC 对话 框应用程序实现 )1、界面设计2、控件变量定义3、创建“Idiom” 类3.1“Idiom.h”文件内容// Idiom.h: interface for the Idiom class.////////////////////////////////////////////////////////////////////////#include #if !defined(AFX_IDIOM_H__C9A16E11_19F4_4BCF_B7D0_4CCF4FA5AE2D__INCLUDED_)#define AFX_IDIOM_H__C9A16E11_19F4_4BCF_B7D0_4CCF4FA5AE2D__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000class Idiom {private:CString Idiom1[30805];//成语CString Idiom2[30805];//读音CString Idiom3[30805];//释义CString Idiom4[3041];//首字unsigned long Idiom5[3041];//首字在大表位置public:void Help(CString C1,int *nIndex1);void Help(CString C1);int Distinguish(CString nC1);void Solitaire(CString C1,CString C2,int *nIndex1);void GetIdiom(long Index,CString *txt1,CString *txt2,CString *txt3);Idiom();virtual ~Idiom();};#endif // !defined(AFX_IDIOM_H__C9A16E11_19F4_4BCF_B7D0_4CCF4FA5AE2D__INCLUDED_)3.2“Idiom.cpp”文件内容// Idiom.cpp: implementation of the Idiom class.////////////////////////////////////////////////////////////////////////#include "stdafx.h"#include "shiyan3.h"#include "Idiom.h"#ifdef _DEBUG#undef THIS_FILEstatic char THIS_FILE[]=__FILE__;#define new DEBUG_NEW#endif//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////Idiom::Idiom(){CStdioFile file1;CString str;unsigned long row1=0;int count=0;int index;file1.Open(_T("a1.csv"),CFile::modeRead);while(file1.ReadString(str)){//str = str.Trim(_T(" "));str.TrimLeft();str.TrimRight(); count=0;index = str.Find(_T(","));while (index != -1 && row1=0 && Index30840) {n1=n1/2;}*txt1=Idiom1[n1];*txt2=Idiom2[n1];*txt3=Idiom3[n1];}}void Idiom::Solitaire(CString C1,CString C2,int *nIndex1){CString nC1,nC2;int n1;nC1=C1.Right(2);//当前成 语的最后一个字nC2=C2.Left(2); //答案词的第一个字if(nC1==nC2){n1=0;//接语成功*nIndex1=Distinguish(C2);}}int Idiom::Distinguish(CString nC1){CString nC2;int n1,n2,m1,m2;nC2=nC1.Left(2); //输入词的第一个字for (n1=0;n10){MessageBox(0,nC2,"合符要求的成语如下",1);}else{MessageBox(0,"没有合符要求的成语"," 警告 ",1);}}void Idiom::Help(CString C1, int *nIndex1){CString nC1,nC2;int n1,m1,m2;nC1=C1.Right(2); //输 入词的最后一个字for (n1=0;n10){myIdiom.GetIdiom(n1,&c1,&c2,&c3);m_ed1=c1;m_ed3.Format("%s\r\n%s",c2,c3);m_ed2="";m_list1.InsertString(0,m_ed1); //m_list1.AddString(m_ed1);}else{MessageBox("成语接龙错误!"," 警告");}UpdateData(FALSE);}6.2void CShiyan3Dlg::OnComputer() {// TODO: Add your control notification handler code hereCString c1,c2,c3;int n1;myIdiom.Help(m_ed1,&n1); if (n1>=0){myIdiom.GetIdiom(n1,&c1,&c2,&c3);m_ed1=c1;m_ed3.Format("%s\r\n%s",c2,c3);m_list1.InsertString(0,m_ed1); //m_list1.AddString(m_ed1);UpdateData(FALSE);}else{MessageBox("没有合符要求的成语了!","警告");}}6.3void CShiyan3Dlg::OnReStart() {// TODO: Add your control notification handler code hereCString c1,c2,c3;int n1;//srand(time(0));/*设置种子 ,并生成伪随机序列*///srand((unsigned)time(NULL));n1=rand();/*得到伪随机数*/m_list1.ResetContent(); myIdiom.GetIdiom(n1,&c1,&c2,&c3);m_ed1=c1;m_ed3.Format("%s\r\n%s",c2,c3);m_ed2="";m_list1.InsertString(0,m_ed1); UpdateData(FALSE);}6.4void CShiyan3Dlg::OnHelp() {// TODO: Add your control notification handler code heremyIdiom.Help(m_ed1); }5.5“*Dlg”初始化7、编译运行程序。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.