• 【C#】试卷批改系统


    简介

    实现语言:C#

    项目名称:试卷批改系统

    项目类型:Windows 窗体应用(.NET Framework)

    开发环境:Visual Studio 2022 Community 17.2.5 

    目标框架:.NET Framework 4.8


    项目介绍

    为了缓解老师们的疲劳,让我们更快乐得玩耍,我做了这个试卷批改的系统,能帮老师快速地批改选择题、判断题和有唯一答案的填空题,并且让我们有充分的时间玩耍,简直一举(没)两得(用)啊!

    好了,回到正题,其实是我一个老师用C++做了一个简单的试卷批改系统,但每次的答案都需手动输入,也不能一键批改,我就做了这么一个项目,支持直接导入老师文件(答案)与分数文件(每道题对应的分值写在这个文件中)与一键导入学生文件。


    更新历史

    •  2022-7-19:1.0.0正式版

            --忽略分数文件中的换行--

            --忽略老师文件和学生文件中的大小写--

    • 2022-7-18:1.0.0测试版

            --忽略老师文件和学生文件中的空格与换行--

    • 2022-7-16:创建项目

    运行截图

     先准备若干个个文本文档(由一个老师文档即答案、一个分数文件和若干个学生文件组成),内容如下:

     

    运行程序,选择“批改试卷”并按提示依次选择文件

     然后会弹出结果:

    然后我们在人工检验一下:

    • 学生1所有答案正确,忽略大小写和换行,应为满分即150分。
    • 学生2第二个答案和最后一个答案错误,忽略空格和换行,共减去40分,应得110分。

    由此看来程序运行无误。

    代码

    Form1.cs

    1. using System;
    2. using System.IO;
    3. using System.Windows.Forms;
    4. namespace 试卷批改系统
    5. {
    6. public partial class Form1 : Form
    7. {
    8. public Form1()
    9. {
    10. InitializeComponent();
    11. }
    12. private void button1_Click(object sender, EventArgs e)
    13. {
    14. label1.Visible = false;
    15. label2.Visible = true;
    16. button1.Visible = false;
    17. button2.Visible = false;
    18. button3.Visible = false;
    19. button4.Visible = true;
    20. string TeacherPath = "", ScorePath = "", TeacherAnswer = "", StringScore = "";
    21. string[] StudentPath = new string[100], StudentAnswers = new string[100];
    22. int StudentNum = 0, index = 0, temp = 0;
    23. int[] Score = new int[1000], StudentScore = new int[100];
    24. OpenFileDialog dialog = new OpenFileDialog();
    25. dialog.Multiselect = false;
    26. label2.Text = "请选择老师文件(答案):";
    27. dialog.Title = "选择老师文件(答案)";
    28. dialog.Filter = "文本文件(*.txt)|*.txt";
    29. if (dialog.ShowDialog() == DialogResult.OK)
    30. {
    31. TeacherPath = dialog.FileName;
    32. label2.Text = TeacherPath;
    33. }
    34. else
    35. {
    36. label2.Text = "文件路径为空!";
    37. return;
    38. }
    39. dialog.Multiselect = true;
    40. label2.Text = "请选择学生文件:";
    41. dialog.Title = "选择学生文件";
    42. if (dialog.ShowDialog() == DialogResult.OK)
    43. {
    44. try
    45. {
    46. StudentPath = dialog.FileNames;
    47. StudentNum = StudentPath.Length;
    48. }
    49. catch (OverflowException)
    50. {
    51. label2.Text = "人数过多!";
    52. return;
    53. }
    54. }
    55. else
    56. {
    57. label2.Text = "文件路径为空!";
    58. return;
    59. }
    60. dialog.Multiselect = false;
    61. label2.Text = "请选择分数文件:";
    62. dialog.Title = "选择分数文件";
    63. if (dialog.ShowDialog() == DialogResult.OK)
    64. {
    65. ScorePath = dialog.FileName;
    66. }
    67. else
    68. {
    69. label2.Text = "文件路径为空!";
    70. return;
    71. }
    72. label2.Text = "";
    73. StreamReader sr = new StreamReader(TeacherPath);
    74. TeacherAnswer = sr.ReadToEnd();
    75. TeacherAnswer = TeacherAnswer.Replace(" ", "");
    76. TeacherAnswer = TeacherAnswer.Replace("\r\n", "");
    77. TeacherAnswer = TeacherAnswer.ToUpper();
    78. sr = new StreamReader(ScorePath);
    79. StringScore= sr.ReadToEnd();
    80. StringScore = StringScore.Replace("\r\n", " ");
    81. StringScore = StringScore + " ";
    82. for (int i = 0; index < StringScore.Length; i++)
    83. {
    84. Score[i] = 0;
    85. while (StringScore[index] != ' ' && index < StringScore.Length)
    86. {
    87. Score[i] *= 10;
    88. Score[i] += StringScore[index++] - '0';
    89. }
    90. if (Score[i] == 0) i--;
    91. else temp += Score[i];
    92. index++;
    93. }
    94. for (int i = 0; i < StudentNum; i++)
    95. {
    96. sr = new StreamReader(StudentPath[i]);
    97. StudentAnswers[i] = sr.ReadToEnd();
    98. StudentAnswers[i] = StudentAnswers[i].Replace(" ", "");
    99. StudentAnswers[i] = StudentAnswers[i].Replace("\r\n", "");
    100. StudentAnswers[i] = StudentAnswers[i].ToUpper();
    101. index = 0;
    102. for (int j = 0, k = 0; j < TeacherAnswer.Length && k < StudentAnswers[i].Length; index++)
    103. {
    104. if(TeacherAnswer[j] == StudentAnswers[i][k])
    105. {
    106. StudentScore[i] += Score[index];
    107. }
    108. j++;
    109. k++;
    110. }
    111. StudentPath[i] = StudentPath[i].Substring(StudentPath[i].LastIndexOf(@"\") + 1);
    112. }
    113. sr.Close();
    114. dataGridView1.Visible = true;
    115. dataGridView1.Rows.Clear();
    116. dataGridView1.ColumnCount = 3;
    117. dataGridView1.Columns[0].Name = "文件名";
    118. dataGridView1.Columns[1].Name = "总分";
    119. dataGridView1.Columns[2].Name = "成绩";
    120. for(int i = 0; i < StudentNum; i++)
    121. {
    122. dataGridView1.Rows.Add(StudentPath[i], temp, StudentScore[i]);
    123. }
    124. }
    125. private void button2_Click(object sender, EventArgs e)
    126. {
    127. label1.Visible = false;
    128. label2.Visible = true;
    129. button1.Visible = false;
    130. button2.Visible = false;
    131. button3.Visible = false;
    132. button4.Visible = true;
    133. label2.Text = "注意:\n" +
    134. "1、该程序在对比老师文件(答案)与学生文件时只会忽略空格和换行,因此,学生一定要注意自己TXT文档的格式,不要键入无用信息!\n" +
    135. "2、“分数文件”指的是每道题的分数,应与老师文件(答案)里的信息一一对应!";
    136. }
    137. private void button3_Click(object sender, EventArgs e)
    138. {
    139. _ = MessageBox.Show("试卷批改系统\n1.0.0正式版\n", "关于", MessageBoxButtons.OK, MessageBoxIcon.Information);
    140. }
    141. private void button4_Click(object sender, EventArgs e)
    142. {
    143. label1.Visible = true;
    144. label2.Visible = false;
    145. button1.Visible = true;
    146. button2.Visible = true;
    147. button3.Visible = true;
    148. button4.Visible = false;
    149. dataGridView1.Visible = false;
    150. }
    151. }
    152. }

    Form1.Designer.cs

    1. namespace 试卷批改系统
    2. {
    3. partial class Form1
    4. {
    5. ///
    6. /// 必需的设计器变量。
    7. ///
    8. private System.ComponentModel.IContainer components = null;
    9. ///
    10. /// 清理所有正在使用的资源。
    11. ///
    12. /// 如果应释放托管资源,为 true;否则为 false。
    13. protected override void Dispose(bool disposing)
    14. {
    15. if (disposing && (components != null))
    16. {
    17. components.Dispose();
    18. }
    19. base.Dispose(disposing);
    20. }
    21. #region Windows 窗体设计器生成的代码
    22. ///
    23. /// 设计器支持所需的方法 - 不要修改
    24. /// 使用代码编辑器修改此方法的内容。
    25. ///
    26. private void InitializeComponent()
    27. {
    28. this.label1 = new System.Windows.Forms.Label();
    29. this.button1 = new System.Windows.Forms.Button();
    30. this.button2 = new System.Windows.Forms.Button();
    31. this.button3 = new System.Windows.Forms.Button();
    32. this.label2 = new System.Windows.Forms.Label();
    33. this.button4 = new System.Windows.Forms.Button();
    34. this.dataGridView1 = new System.Windows.Forms.DataGridView();
    35. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
    36. this.SuspendLayout();
    37. //
    38. // label1
    39. //
    40. this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
    41. this.label1.AutoSize = true;
    42. this.label1.Font = new System.Drawing.Font("宋体", 42F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
    43. this.label1.Location = new System.Drawing.Point(184, 70);
    44. this.label1.Name = "label1";
    45. this.label1.Size = new System.Drawing.Size(450, 70);
    46. this.label1.TabIndex = 0;
    47. this.label1.Text = "试卷批改系统";
    48. //
    49. // button1
    50. //
    51. this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
    52. this.button1.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
    53. this.button1.Location = new System.Drawing.Point(337, 233);
    54. this.button1.Name = "button1";
    55. this.button1.Size = new System.Drawing.Size(144, 42);
    56. this.button1.TabIndex = 1;
    57. this.button1.Text = "批改试卷";
    58. this.button1.UseVisualStyleBackColor = true;
    59. this.button1.Click += new System.EventHandler(this.button1_Click);
    60. //
    61. // button2
    62. //
    63. this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
    64. this.button2.Font = new System.Drawing.Font("宋体", 15F);
    65. this.button2.Location = new System.Drawing.Point(337, 281);
    66. this.button2.Name = "button2";
    67. this.button2.Size = new System.Drawing.Size(144, 42);
    68. this.button2.TabIndex = 2;
    69. this.button2.Text = "帮助";
    70. this.button2.UseVisualStyleBackColor = true;
    71. this.button2.Click += new System.EventHandler(this.button2_Click);
    72. //
    73. // button3
    74. //
    75. this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
    76. this.button3.Font = new System.Drawing.Font("宋体", 15F);
    77. this.button3.Location = new System.Drawing.Point(337, 329);
    78. this.button3.Name = "button3";
    79. this.button3.Size = new System.Drawing.Size(144, 42);
    80. this.button3.TabIndex = 3;
    81. this.button3.Text = "关于";
    82. this.button3.UseVisualStyleBackColor = true;
    83. this.button3.Click += new System.EventHandler(this.button3_Click);
    84. //
    85. // label2
    86. //
    87. this.label2.AutoSize = true;
    88. this.label2.Location = new System.Drawing.Point(4, 3);
    89. this.label2.MaximumSize = new System.Drawing.Size(795, 445);
    90. this.label2.MinimumSize = new System.Drawing.Size(0, 15);
    91. this.label2.Name = "label2";
    92. this.label2.Size = new System.Drawing.Size(0, 15);
    93. this.label2.TabIndex = 4;
    94. this.label2.Visible = false;
    95. //
    96. // button4
    97. //
    98. this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
    99. this.button4.Font = new System.Drawing.Font("宋体", 15F);
    100. this.button4.Location = new System.Drawing.Point(644, 396);
    101. this.button4.Name = "button4";
    102. this.button4.Size = new System.Drawing.Size(144, 42);
    103. this.button4.TabIndex = 5;
    104. this.button4.Text = "返回";
    105. this.button4.UseVisualStyleBackColor = true;
    106. this.button4.Visible = false;
    107. this.button4.Click += new System.EventHandler(this.button4_Click);
    108. //
    109. // dataGridView1
    110. //
    111. this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
    112. this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
    113. this.dataGridView1.Location = new System.Drawing.Point(12, 12);
    114. this.dataGridView1.Name = "dataGridView1";
    115. this.dataGridView1.ReadOnly = true;
    116. this.dataGridView1.RowHeadersWidth = 51;
    117. this.dataGridView1.RowTemplate.Height = 27;
    118. this.dataGridView1.Size = new System.Drawing.Size(776, 426);
    119. this.dataGridView1.TabIndex = 6;
    120. this.dataGridView1.Visible = false;
    121. //
    122. // Form1
    123. //
    124. this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
    125. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    126. this.ClientSize = new System.Drawing.Size(800, 450);
    127. this.Controls.Add(this.button4);
    128. this.Controls.Add(this.label2);
    129. this.Controls.Add(this.button3);
    130. this.Controls.Add(this.button2);
    131. this.Controls.Add(this.button1);
    132. this.Controls.Add(this.label1);
    133. this.Controls.Add(this.dataGridView1);
    134. this.MaximumSize = new System.Drawing.Size(818, 497);
    135. this.MinimumSize = new System.Drawing.Size(818, 497);
    136. this.Name = "Form1";
    137. this.Text = "试卷批改系统";
    138. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
    139. this.ResumeLayout(false);
    140. this.PerformLayout();
    141. }
    142. #endregion
    143. private System.Windows.Forms.Label label1;
    144. private System.Windows.Forms.Button button1;
    145. private System.Windows.Forms.Button button2;
    146. private System.Windows.Forms.Button button3;
    147. private System.Windows.Forms.Label label2;
    148. private System.Windows.Forms.Button button4;
    149. private System.Windows.Forms.DataGridView dataGridView1;
    150. }
    151. }

    Program.cs

    1. using System;
    2. using System.Windows.Forms;
    3. namespace 试卷批改系统
    4. {
    5. internal static class Program
    6. {
    7. ///
    8. /// 应用程序的主入口点。
    9. ///
    10. [STAThread]
    11. static void Main()
    12. {
    13. Application.EnableVisualStyles();
    14. Application.SetCompatibleTextRenderingDefault(false);
    15. Application.Run(new Form1());
    16. }
    17. }
    18. }

     好了,是不是意想不到呀?我还会C#呢!好了,不多说了,拜拜!

  • 相关阅读:
    【K8s入门必看】第二篇 —— 快速部署集群指南
    mysql表百万数据搜索性能测试
    〖大前端 - 基础入门三大核心之JS篇㊲〗- DOM改变元素节点的css样式、HTML属性
    【已解决】nginx x-cache: MISS
    嵌入式开发和后端开发如何选择?
    git学习总结
    基于Python的医院信息管理系统
    技术管理进阶——跨级管理/汇报
    stl string内存空间增长探索
    DevSeo Studio设置中文界面
  • 原文地址:https://blog.csdn.net/qq_43546083/article/details/125879870