c抽题软件开发课设Word下载.docx

上传人:b****3 文档编号:17028530 上传时间:2022-11-28 格式:DOCX 页数:12 大小:769.23KB
下载 相关 举报
c抽题软件开发课设Word下载.docx_第1页
第1页 / 共12页
c抽题软件开发课设Word下载.docx_第2页
第2页 / 共12页
c抽题软件开发课设Word下载.docx_第3页
第3页 / 共12页
c抽题软件开发课设Word下载.docx_第4页
第4页 / 共12页
c抽题软件开发课设Word下载.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

c抽题软件开发课设Word下载.docx

《c抽题软件开发课设Word下载.docx》由会员分享,可在线阅读,更多相关《c抽题软件开发课设Word下载.docx(12页珍藏版)》请在冰豆网上搜索。

c抽题软件开发课设Word下载.docx

4、为项目添加配置文件App.config。

在解决方案管理器中右击项目名,选择“添加”/“新建项”,打开“添加新项”对话框,选择“应用程序配置文件”,在名称处输入“App.config”,最后单击“添加”按钮,如图2所示。

打开配置文件,在<

configuration>

和<

/configuration>

之间添加以下代码:

<

appSettings>

<

addkey="

ConnString"

value="

server=WISECAT\SQLEXPRESS;

database=student;

integratedsecurity=true"

/>

/appSettings>

其中WISECAT代表机器名,student是即将导入的数据库。

图2建立应用程序配置文件App.config

将配置文件引用到程序中。

右击解决方案资源管理器的“引用”,选择“添加应用”,打开“添加引用”窗体,选择.NET选项卡中的“System.Configuration”,最后单击确定。

如图3所示。

图3添加配置文件的引用

5、在MainWindow设计窗体中添加控件,构造界面

从工具箱中选择合适的控件,加入窗体中。

包括4个用于显示题号的Label控件,字体设置醒目一些,名称分别为Lable1,Label2,Label3,label4;

一个用于提示“双击右侧列表框开始选题”的提示性Label控件,名称为label5;

一个用于调节速度的Slider控件,名称为slider1,最大值maximum设为100,最小值minimum为0,value值为50;

一个用于提示每章题目个数的Label控件,名称为label7;

一个Image控件,显示一幅图片,名称为image1,任意设置其source属性;

一个用于显示学生列表的ListBox控件,名称为listbox1;

一个用于关闭的按钮控件,button1。

其他指示性标签若干。

如图4所示。

图4.主界面控件安排图

6、响应关闭按钮事件

双击关闭按钮,为按钮添加事件响应程序如下:

privatevoidbutton1_Click(objectsender,RoutedEventArgse)

{

Close();

}

7、为系统添加文件

为系统准备学生信息文件students.txt和候选题目文件problems.txt,其中problems.txt文件每章之间加入一个空行,以便程序能够识别各章界限。

将.txt文件至于系统的运行

目录,即.exe文件所在的目录,一般为bin/debug目录;

如需支持数据库操作,还要将students.txt文件导入到SQLEXPRESS服务器中,数据库名称为student。

8、为类MainWindows完成构造函数

9、增加方法ReadProblems

10、增加方法showProblems和showIt

11、增加方法GetStudents,从文件中读取学生信息。

12、选中listbox1控件,在其属性窗口中,查找事件MouseDoubleClick,增加鼠标双击响应事件代码

13、选中整个MainWindow窗口,在其事件中查找KeyDown事件,加入事件响应函数。

14、加入保存抽题结果的方法saveResult

15、加入在listbox1状态下按空格也能停止抽题的响应事件PreviewKeyDown的响应程序,否则光标在listbox1下按空格不能停止抽题

16、增加slider1控件的滑动调速度响应事件ValueChanged

17、主窗口的标题设置为“概率统计抽题软件”,通过设置mainWindow的title属性。

系统最终运行结果如图5所示

2.2、主要程序代码

1.在代码文件“MainWindow.xaml.cs”中添加以下命名空间:

usingSystem.Timers;

usingSystem.IO;

usingSystem.Configuration;

usingSystem.Data.SqlClient;

usingSystem.Data;

2.在类MainWindow中增加成员:

privateboolisInProgress=false;

privateTimeraTimer;

privateintspeed;

privateconstintnChapters=4;

privateconstintmaxPrbs=40;

privatestring[,]problems=newstring[nChapters,maxPrbs];

privateint[]nPrb=newint[nChapters];

PrivatestringConnectionStr=ConfigurationManager.AppSettings["

].ToString();

SqlConnectionConn;

privateSqlDataAdapterStudentDA;

privateSystem.Data.DataSetStudentDS;

3.为类MainWindows完成构造函数

publicMainWindow()

speed=50;

//speed:

1..100

aTimer=newSystem.Timers.Timer();

aTimer.Elapsed+=newElapsedEventHandler(showProblems);

aTimer.Interval=10+2*(100-speed);

aTimer.AutoReset=true;

aTimer.Enabled=true;

//aTimer.Start();

//开始

aTimer.Stop();

//停止

InitializeComponent();

label1.Content="

XXX"

;

label2.Content="

label3.Content="

label4.Content="

ReadProblems();

label7.Content="

"

for(inti=0;

i<

nChapters;

i++)

{

label7.Content+="

第"

+System.Convert.ToString(i+1)+"

章共"

+nPrb[i].ToString()+"

道题"

if(i<

nChapters-1)label7.Content+="

"

}

if(!

GetStudents())

stringSqlStr="

selectsno,sname,specialty,classnofromstudents11"

StudentDS=GetData(SqlStr,"

students11"

);

DataRow[]student=StudentDS.Tables["

].Select();

intnStu=0;

foreach(DataRowstudinstudent)

listBox1.Items.Add(stud["

sno"

].ToString()+"

"

+stud["

sname"

].ToString());

nStu++;

MessageBox.Show(nStu.ToString()+"

studentsloadedfromdatabase."

}

4.增加方法ReadProblems的代码

publicvoidReadProblems()//读取problems.txt文件函数

stringstrLine;

i<

nChapters;

i++)nPrb[i]=0;

intnChap=0;

try

FileStreamaFile=newFileStream("

problems.txt"

FileMode.Open);

StreamReadersr=newStreamReader(aFile);

strLine=sr.ReadLine();

//Readdatainlinebyline

while(strLine!

=null)

if(strLine.Length>

0)

problems[nChap,nPrb[nChap]++]=strLine;

else

nChap++;

//数据的第二部分

sr.Close();

catch(IOExceptionex)

MessageBox.Show("

AnIOExceptionhasbeenthrown!

MessageBox.Show(ex.ToString());

return;

5.增加方法showProblems和showIt的代码

publicvoidshowIt(int[]nn)//展示你要做的题目

this.label1.Dispatcher.Invoke(newAction(()=>

{this.label1.Content=problems[0,nn[0]];

}));

this.label2.Dispatcher.Invoke(newAction(()=>

{this.label2.Content=problems[1,nn[1]];

this.label3.Dispatcher.Invoke(newAction(()=>

{this.label3.Content=problems[2,nn[2]];

this.label4.Dispatcher.Invoke(newAction(()=>

{this.label4.Content=problems[3,nn[3]];

publicvoidshowProblems(objectsource,ElapsedEventArgse)

Randomr=newRandom();

int[]nn=newint[nChapters];

nn[i]=r.Next(nPrb[i]);

showIt(nn);

6.增加鼠标双击响应事件代码:

privatevoidlistBox1_MouseDoubleClick(objectsender,MouseButtonEventArgse)

isInProgress)

label3.Content="

按回车或空格停止..."

isInProgress=true;

aTimer.Start();

7.增加方法GetStudents,从文件中读取学生信息的代码

publicboolGetStudents()//从文件中读取学生信息

string[]students;

students.txt"

StreamReadersr=newStreamReader(aFile,UnicodeEncoding.GetEncoding("

GB2312"

));

while(strLine!

if(strLine.Length>

0)

students=strLine.Split(newchar[]{'

\t'

});

listBox1.Items.Add(students[0]+'

'

+students[1]);

studentsloadedfromtxtfile."

returntrue;

students.txtnotfound!

+ex.Message);

returnfalse;

9.查找KeyDown事件的代码

privatevoidWindow_KeyDown(objectsender,KeyEventArgse)

{

if(isInProgress&

&

(e.Key==Key.Space||e.Key==Key.Enter))

label5.Content=listBox1.Items.GetItemAt(listBox1.SelectedIndex);

isInProgress=false;

aTimer.Stop();

saveResult(label5.Content+"

\t"

+label1.Content+"

+label2.Content

+"

+label3.Content+"

+label4.Content);

}

10.加入保存抽题结果的方法saveResult的代码

privatevoidsaveResult(stringresult)//保存抽题结果

results.txt"

FileMode.OpenOrCreate);

aFile.Seek(0,SeekOrigin.End);

//跳到文件尾部

StreamWritersw=newStreamWriter(aFile);

sw.WriteLine(result+"

\t抽题时间:

+DateTime.Now.ToLocalTime());

sw.Close();

11.停止抽题的响应事件PreviewKeyDown的响应程序代码

privatevoidlistBox1_PreviewKeyDown(objectsender,KeyEventArgse)//停止抽题响应事件

if(isInProgress)

if(e.Key==Key.Space)

+label2.Content+"

12.调速度响应事件ValueChanged的代码

privatevoidslider1_ValueChanged(objectsender,RoutedPropertyChangedEventArgs<

double>

e)

speed=Convert.ToInt32(slider1.Value);

aTimer.Interval=10+2*(100-speed);

//设置引发时间的间隔(毫秒)

三、收获和体会

1、收获

在这次实训中,通过亲身经历与亲自动手实践,明白了概率抽题软件的操作过程,还明白了C#的操作过程。

以及明白了其中重要函数的含义。

2、体会

在试验中遇到了很多的问题,都是以前没有发现的,这些问题设计的方面很多,有以前的C++基础的,也有最近学习的数据结构的知识,我们虽然学了C#,但是因为是考察课,没有认真学习,刚开始C#的软件都不会用。

通过实验的设计,让我发现了自己的不足,现在已经学会了很多C#的很多知识。

而且发现了自己在学习知识上面的漏洞,自己在细节方面的考虑还不够全面,很多细节都是通过调试才发现的,希望通过弥补这些发现的漏洞,提高自己的专业知识水平。

四、参考文献

1、《概率统计》抽题软件开发案例

2、XX搜索

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工作范文 > 制度规范

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1