计算机实习报告输入法.docx
《计算机实习报告输入法.docx》由会员分享,可在线阅读,更多相关《计算机实习报告输入法.docx(21页珍藏版)》请在冰豆网上搜索。
![计算机实习报告输入法.docx](https://file1.bdocx.com/fileroot1/2023-5/27/4d47ee6b-bfed-4002-bf3f-4d350615757b/4d47ee6b-bfed-4002-bf3f-4d350615757b1.gif)
计算机实习报告输入法
一、开发任务
开发任务的具体要求。
拼音输入法:
通过编程实现拼音输入并找到相应汉字后打印出来。
二、需求分析
(这一部分主要是确定要做什么,以及问题的边界。
如对于本例,主要给出游戏软件的功能,描述操作的特性等。
具体来说,就是给出程序的基本功能和性能,设计问题的输入/输出)
1.说明自己针对这个任务将完成哪些功能的设计。
拼音输入法的功能有:
(1)提供输入法主界面。
包括键盘,汉字选项以及输出框。
如图所示:
(2)输入汉字功能。
点击模拟键盘实现输入,右侧拼音、汉字选择即可。
(3)汉字输出。
用户选中相应汉字后即可在输入框中显示,如图:
2.说明程序将会具有什么样的性能:
程序中有如下性能:
(1)点击键盘按钮输入相应拼音,并显示所有拼音组合情况。
(2)点击选择拼音即可出现相应汉字,点击汉字即可显示在输入框中。
(3)点击清除即可实现清除拼音,点击标点即可选择标点输入。
三、程序设计
(这一部分主要是说怎么做,以及语言环境对问题处理的特殊影响。
如下例所示,游戏区域的表示,下坠物的形状表示,辅助数据结构,结果输出格式。
具体来说,就是给出程序的数据结构,模块划分,主程序结构)
操作区域由编辑框、按钮、列表框组成。
如下图所示:
针对需要做如下设计:
(1)数据结构设计
设置CString类型的input,用于存储按键点击输入。
(2)界面设计
输入框由编辑框组成,用于输出汉字。
模拟按键区域,由12个按钮组成,用于用户的输入。
拼音汉字选择处由列表框组成,实现汉字显示以及用户选择。
(3)操作代码设计
(a)键盘拼音按钮操作(以按键2为例)
用户点击完成,分别将a,b,c赋值给input[]数组,并将input[]数组中的信息与文件中的拼音比较,若存在相同则显示到拼音列表即可。
case2:
if(input_count==0)
{
input_count=3;
temp[m++]="a";temp[m++]="b";temp[m++]="c";
}
else
{
for(intk=0;k{
temp[m++]=input[k]+_T("a");
temp[m++]=input[k]+_T("b");
temp[m++]=input[k]+_T("c");
}
}
for(i=0;iinput[i]=temp[i];
input_count=m;
Update_em_listctrl();
break;
(b)键盘标点按钮操作
点击标点按钮后,将存放标点的数组所有值显示到列表控件即可。
CStringbiaodian[7]={_T(","),_T("."),_T("、"),_T(":
"),_T(";"),_T("?
"),_T("!
")};
(c)键盘清除按钮操作
清空两个列表以及input[]数组,并将输入计数置零。
em_listctrl.DeleteAllItems();
hm_listctrl.DeleteAllItems();
for(inti=0;iinput[i]="";
input_count=0;
(d)选中拼音列表选项操作
清空汉字列表后,取出列表中的拼音并与汉字表文本文件中对比,找到相同的则将汉字全部赋值给汉字列表。
(e)选中汉字列表选项操作
取出列表中选中的汉字,赋值给输入框即可显示。
显示完成则清空拼音、汉字列表以及input[]数组,便于下一次继续输入。
四、程序实现
(这一部分主要是说子程序的实现,以及引用的语言资源。
具体来说,就是给出程序模块的实现)
(1)界面设计实现
开始运行界面汉字输入界面
(2)操作代码实现
(a)按钮点击代码实现
voidCMyDlg:
:
Button_Handle(intn)//所有的按键处理函数
{
CStringbiaodian[7]={_T(","),_T("."),_T("、"),_T(":
"),_T(";"),_T("?
"),_T("!
")};
CStringtemp[10000];
intj,i;
if(flag_123_or_en==1)//当前键盘为数字
{
input_cstring.Format(_T("%s%d"),input_cstring,n);
UpdateData(false);//刷新变量的值到控件
}
else//当前键盘为字符和标点符号
{
UpdateData(true);//刷新控件的值到变量
intm=0;
switch(n)
{
case0:
//点击标点按钮
hm_listctrl.DeleteAllItems();//先清空汉字列表框中的值
for(j=0;j<7;j++)
{
hm_listctrl.InsertItem(j,_T(""));
hm_listctrl.SetItemText(j,0,biaodian[j]);
}
break;
case1:
//点击按钮1
input_cstring.Format(_T("%s"),input_cstring);
UpdateData(false);
break;
case2:
//点击按钮2
if(input_count==0)
{
input_count=3;
temp[m++]="a";temp[m++]="b";temp[m++]="c";
}
else
{
for(intk=0;k{
temp[m++]=input[k]+_T("a");
temp[m++]=input[k]+_T("b");
temp[m++]=input[k]+_T("c");
}
}
for(i=0;iinput[i]=temp[i];
input_count=m;
Update_em_listctrl();
break;
case3:
//点击按钮3
if(input_count==0)
{
input_count=3;
temp[m++]="d";temp[m++]="e";temp[m++]="f";
}
else
{
for(intk=0;k{
temp[m++]=input[k]+_T("d");
temp[m++]=input[k]+_T("e");
temp[m++]=input[k]+_T("f");
}
}
for(i=0;iinput[i]=temp[i];
input_count=m;
Update_em_listctrl();
break;
case4:
//点击按钮4
if(input_count==0)
{
input_count=3;
temp[m++]="g";temp[m++]="h";temp[m++]="i";
}
else
{
for(intk=0;k{
temp[m++]=input[k]+_T("g");
temp[m++]=input[k]+_T("h");
temp[m++]=input[k]+_T("i");
}
}
for(i=0;iinput[i]=temp[i];
input_count=m;
Update_em_listctrl();
break;
case5:
//点击按钮5
if(input_count==0)
{
input_count=3;
temp[m++]="j";temp[m++]="k";temp[m++]="l";
}
else
{
for(intk=0;k{
temp[m++]=input[k]+_T("j");
temp[m++]=input[k]+_T("k");
temp[m++]=input[k]+_T("l");
}
}
for(i=0;iinput[i]=temp[i];
input_count=m;
Update_em_listctrl();
break;
case6:
//点击按钮6
if(input_count==0)
{
input_count=3;
temp[m++]="m";temp[m++]="n";temp[m++]="o";
}
else
{
for(intk=0;k{
temp[m++]=input[k]+_T("m");
temp[m++]=input[k]+_T("n");
temp[m++]=input[k]+_T("o");
}
}
for(i=0;iinput[i]=temp[i];
input_count=m;
Update_em_listctrl();
break;
case7:
//点击按钮7
if(input_count==0)
{
input_count=4;
temp[m++]="p";temp[m++]="q";temp[m++]="r";temp[m++]="s";
}
else
{
for(intk=0;k{
temp[m++]=input[k]+_T("p");
temp[m++]=input[k]+_T("q");
temp[m++]=input[k]+_T("r");
temp[m++]=input[k]+_T("s");
}
}
for(i=0;iinput[i]=temp[i];
input_count=m;
Update_em_listctrl();
break;
case8:
//点击按钮8
if(input_count==0)
{
input_count=3;
temp[m++]="t";temp[m++]="u";temp[m++]="v";
}
else
{
for(intk=0;k{
temp[m++]=input[k]+_T("t");
temp[m++]=input[k]+_T("u");
temp[m++]=input[k]+_T("v");
}
}
for(i=0;iinput[i]=temp[i];
input_count=m;
Update_em_listctrl();
break;
case9:
//点击按钮9
if(input_count==0)
{
input_count=4;
temp[m++]="w";temp[m++]="x";temp[m++]="y";temp[m++]="z";
}
else
{
for(intk=0;k{
temp[m++]=input[k]+_T("w");
temp[m++]=input[k]+_T("x");
temp[m++]=input[k]+_T("y");
temp[m++]=input[k]+_T("z");
}
}
for(i=0;iinput[i]=temp[i];
input_count=m;
Update_em_listctrl();
break;
}
}
}
(b)拼音列表点击代码
voidCMyDlg:
:
OnClickList2(NMHDR*pNMHDR,LRESULT*pResult)
{
//TODO:
Addyourcontrolnotificationhandlercodehere
intpos;
CStringitem;
FILE*file;
hm_listctrl.DeleteAllItems();//删除汉字列表所有项目
pos=em_listctrl.GetSelectionMark();//找到点击行数
item=em_listctrl.GetItemText(pos,0);//获取拼音列表点击的拼音
for(inti=0;i<453;i++)
if(item==pinyin[i])
{
if((file=fopen("汉字库.txt","r"))==NULL)//访问汉字库文本文档
{
printf("打开文件失败\n");
return;
}
CStringhanzi;
chartemp[200];
for(intj=0;j
fgets(temp,200,file);
fscanf(file,"%s",temp);
fscanf(file,"%s",temp);
hanzi=temp;
intkk=0;
for(intk=0;k{
hm_listctrl.InsertItem(k,_T(""));
CStringt=hanzi.Mid(k,2);
hm_listctrl.SetItemText(kk,0,t);//找到匹配汉字并显示到汉字列表框
kk++;
}
fclose(file);//关闭文件
break;
}
*pResult=0;
}
(c)汉字列表点击函数代码
voidCMyDlg:
:
OnClickList1(NMHDR*pNMHDR,LRESULT*pResult)
{
//TODO:
Addyourcontrolnotificationhandlercodehere
intpos;
pos=hm_listctrl.GetSelectionMark();//找到点击行数
UpdateData(true);
input_cstring+=hm_listctrl.GetItemText(pos,0);//获取选中文本并显示到输入框
UpdateData(false);
hm_listctrl.DeleteAllItems();//删除拼音列表所有项目
em_listctrl.DeleteAllItems();//删除汉字列表所有项目
for(inti=0;iinput[i]="";//清空输入数组
input_count=0;//输入计数置零
*pResult=0;
}
(d)相关辅助函数
对话框初始化函数,包括列表框的初始化,按钮的初始化等。
BOOLCMyDlg:
:
OnInitDialog()
{
CDialog:
:
OnInitDialog();
//Add"About..."menuitemtosystemmenu.
//IDM_ABOUTBOXmustbeinthesystemcommandrange.
ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX<0xF000);
CMenu*pSysMenu=GetSystemMenu(FALSE);
if(pSysMenu!
=NULL)
{
CStringstrAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if(!
strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);
}
}
//Settheiconforthisdialog.Theframeworkdoesthisautomatically
//whentheapplication'smainwindowisnotadialog
SetIcon(m_hIcon,TRUE);//Setbigicon
SetIcon(m_hIcon,FALSE);//Setsmallicon
//TODO:
Addextrainitializationhere
LONGstyle;
style=:
:
GetWindowLong(em_listctrl.m_hWnd,GWL_STYLE);
style&=~(LVS_TYPEMASK);
style&=~(LVS_EDITLABELS);
style|=LVS_REPORT;
:
:
SetWindowLong(em_listctrl.m_hWnd,GWL_STYLE,style|LVS_NOLABELWRAP|LVS_SHOWSELALWAYS);
LONGestyle;
estyle=em_listctrl.GetExtendedStyle();
estyle|=LVS_EX_FULLROWSELECT;
estyle|=LVS_EX_GRIDLINES;
em_listctrl.SetExtendedStyle(estyle);
em_listctrl.InsertColumn(0,_T("拼音"),LVCFMT_LEFT,60);
style=:
:
GetWindowLong(hm_listctrl.m_hWnd,GWL_STYLE);
style&=~(LVS_TYPEMASK);
style&=~(LVS_EDITLABELS);
style|=LVS_REPORT;
:
:
SetWindowLong(hm_listctrl.m_hWnd,GWL_STYLE,style|LVS_NOLABELWRAP|LVS_SHOWSELALWAYS);
estyle=hm_listctrl.GetExtendedStyle();
estyle|=LVS_EX_FULLROWSELECT;
estyle|=LVS_EX_GRIDLINES;
hm_listctrl.SetExtendedStyle(estyle);
hm_listctrl.InsertColumn(0,_T("汉字"),LVCFMT_LEFT,60);
flag_123_or_en=0;//键盘初始化时为字母
input_count=0;//初始化时输入的字符数组合数位0
//初始化时先读入所有拼音
FILE*file;
if((file=fopen("拼音库.txt","r"))==NULL)
{
printf("打开文件失败\n");
return0;
}
chartemp[10];
for(inti=0;i<453;i++)
{
fscanf(file,"%s",temp);
//pinyin[i].Format(_T("%s"),temp);
pinyin[i]=temp;
}
fclose(file);
returnTRUE;//returnTRUEunlessyousetthefocustoacontrol
}
更新拼音列表框的函数代码
voidCMyDlg:
:
Update_em_listctrl()
{
em_listctrl.DeleteAllItems();//清空拼音列表中的所有内容
intk=0;
for(inti=0;i{
for(intj=0;j<453;j++)
{
if(input[i]==pinyin[j])
{
em_listctrl.InsertItem(k,_T(""));
em_listctrl.SetItemText(k,0,input[i]);
k++;
break;
}
}
}
}
(3)函数和过程主要调用关系
按钮单击事件
利用switchcase语句,根据按钮的不同数值,转换至不同的操作。
五、程序测试
(这一部分主要是说用什么数据测试程序,保证程序的每一条分支上的语句都被调试。
具体来说,就是进行程序白盒测试)
拼音输入法测试操作如下。
开始界面:
输入界面
六、设计小结
(这一部分分析程序的优缺点,提出可能的改进方案)
本程序完成了拼音输入法基本输入的功能。
优点是,外观一目了然,方便用户的操作。
缺点是,每次只能输入一个字,增加了输入难度。
七、使用说明
(这一部分主要是说程序安装说明和启动。
具体来说,就是给出