在线答题
Posted 1113482502lq
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在线答题相关的知识,希望对你有一定的参考价值。
设计思想:先通过之前的程序输出四则运算的式子
再计算出正确答案
然后再输入答案
最后比较输入的答案与正确答案进行判断对错
日志:
代码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace 在线答题 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { } public void button1_Click(object sender, EventArgs e) { dataGridView1.DataSource = null; double n = Convert.ToDouble(textBox3.Text); double m = Convert.ToDouble(textBox2.Text); double num = Convert.ToDouble(textBox1.Text); double[] a = new double[2* (int)num]; double[] tureans = new double[(int)num]; dataGridView1.RowCount = (int)num; Random r = new Random(); for (int i = 0; i < 2 * num; i++) { double temp = r.Next((int)m, (int)n); a[i] = temp; } string sign = "+"; for(int i=0;i<num ;i++) { double sum=a[i]+a[i+(int)num]; if (a[i] % a[i + (int)num] == 0&&a[i + (int)num]!=0) { sign = "/"; tureans[i] = a[i] / a[i + (int)num]; } else if (sum <= (int)n / 2) { sign = "*"; tureans[i] = a[i] * a[i + (int)num]; } else if (a[i] > a[i + (int)num]) { sign = "-"; tureans[i] = a[i] - a[i + (int)num]; } else { sign = "+"; tureans[i] = a[i] + a[i + (int)num]; } dataGridView1.Rows[i].Cells[0].Value = Convert.ToString(a[i]) + sign + Convert.ToString(a[i+(int)num])+"="; dataGridView1.Rows[i].Cells[2].Value = Convert.ToString(tureans[i]); } } public void button2_Click(object sender, EventArgs e) { string path = @"C:Users11134Desktop错题本.txt"; if (File.Exists(path)) { File.Delete(path); } double num = Convert.ToDouble(textBox1.Text); dataGridView1.Columns[2].Visible = true; dataGridView1.Columns[3].Visible = true; string wrrong = ""; for (int i = 0; i < num; i++) { if (Convert.ToDouble(dataGridView1.Rows[i].Cells[1].Value) == Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value)) { dataGridView1.Rows[i].Cells[3].Value = "对"; } else if (Convert.ToDouble(dataGridView1.Rows[i].Cells[1].Value) != Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value)) { dataGridView1.Rows[i].Cells[3].Style.BackColor = Color.Red; dataGridView1.Rows[i].Cells[3].Value = "错"; wrrong += Convert.ToString(dataGridView1.Rows[i].Cells[0].Value + " "); } } StreamWriter sw = new StreamWriter(path); sw.WriteLine(wrrong); sw.Close(); } private void button3_Click(object sender, EventArgs e) { Application.Exit(); } } }
窗口设计截图:
运算结果截图:
错题本截图:
以上是关于在线答题的主要内容,如果未能解决你的问题,请参考以下文章