作业四: 结对编程项目---四则运算
1) 注明结对小伙伴的学号,姓名以及博客地址:
130201236 刘彦麟 博客地址:http://www.cnblogs.com/lylljj/
2) 实现的主要功能有哪些?
1、可以选择运算的形式,比如 +、-、 *、 /、 +-、 */、还有四种混合形式。
2、也可以选择难度,一个有三个选项,10以内、20以内以及100以内。
3、自动生成新的题目。
4、提交后可以判断对错。
3) 合作过程中主要负责完成了哪些工作?
刘彦麟同学主要负责了主要代码的编写,我参与一些简单代码的查阅以及复审。在写代码的过程中,遇到好多不会的问题。我们一起查询了百度和经过同学的帮助,我们最终写出了这样一个程序。
4) 结对的每一个人的优点和缺点在哪里 (要列出至少三个优点和一个缺点)。
刘彦麟同学的优点:认真仔细负责任,对于老师留的作业有很高的积极性,遇到不会的会努力想办法弄明白。
缺点是:基础薄弱
蔡强同学的优点:听话,对于分给我的任务能很好完成,积极配合组内工作,好学。
缺点:基础太薄弱
5) 总结在合作过程中结对编程的优点和缺点。
对于我这样基础不太好的同学来说,结对编程可以让我学到很多我根本就不知道的东西,让我这样不会的很多的同学也可以加入到编程里来,从零到有,而且,两个人1+1的力量是大于2的,所以合作很有用,希望以后多一些这样的作业。
缺点就是,没有一个共同编程的地方,因为我们不能出现在一个宿舍,所以沟通起来比较困难。
6) 至少附一张照片, 展现两人在一起合作编程的情况。
这些就是我们的代码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using caculate.math.Biz; namespace caculate.math { public partial class Form1 : Form { public Form1() { InitializeComponent(); tcmbType.SelectedIndex = 0; tcmbLevel.SelectedIndex = 0; tcmbNum.SelectedIndex = 0; } private int pageNum = 1; private int maxPageNum; private Exam exam; TextBox txt1; TextBox txt2; TextBox txt3; Label lblErr; Label lblOp; Label lblIndex; ExamType examType; ExamLevel level; int numOfProblems; public static int CheckExamId; private string GetOperationString(Operation operation) { switch (operation) { case Operation.Add: return "+"; case Operation.Minus: return "-"; case Operation.Multiply: return "×"; case Operation.Divide: return "÷"; } return "+"; } private TextBox GetTextBox(int index, int num) { foreach (Control col in this.Controls) { if (col.Name == "txtNUM" + index + num) { return (TextBox)col; } } return null; } private Label GetLableOp(int index) { foreach (Control col in this.Controls) { if (col.Name == "lblOp" + index) { return (Label)col; } } return null; } private Label GetLableIndex(int index) { foreach (Control col in this.Controls) { if (col.Name == "lblIndex" + index) { return (Label)col; } } return null; } private Label GetLableErr(int index) { foreach (Control col in this.Controls) { if (col.Name == "lblErr" + index) { return (Label)col; } } return null; } private void GetExamAnswer(int pageNum) { int startNum = (pageNum - 1) * 10; for (int i = 0; i < 10; i++) { if (i < exam.Problems.Count) { Problem problem = exam.Problems[i + startNum]; txt1 = GetTextBox(i + 1, 1); txt2 = GetTextBox(i + 1, 2); txt3 = GetTextBox(i + 1, 3); lblErr = GetLableErr(i + 1); int answer = int.MinValue; if (problem.AnswerPosition == 1) { if (int.TryParse(txt1.Text.ToString(),out answer)) { problem.Answer = answer; } else { problem.Answer = int.MinValue; } lblErr.Text = problem.Answer == problem.Num1 ? "正确" : "错误"; } else if (problem.AnswerPosition == 2) { if (int.TryParse(txt2.Text.ToString(), out answer)) { problem.Answer = answer; } else { problem.Answer = int.MinValue; } lblErr.Text = problem.Answer == problem.Num2 ? "正确" : "错误"; } else if (problem.AnswerPosition == 3) { if (int.TryParse(txt3.Text.ToString(), out answer)) { problem.Answer = answer; } else { problem.Answer = int.MinValue; } lblErr.Text = problem.Answer == problem.Num3 ? "正确" : "错误"; } problem.IsAnswered = true; } } } private void SetErrVisbility(bool visible) { lblErr1.Visible = visible; lblErr2.Visible = visible; lblErr3.Visible = visible; lblErr4.Visible = visible; lblErr5.Visible = visible; lblErr6.Visible = visible; lblErr7.Visible = visible; lblErr8.Visible = visible; lblErr9.Visible = visible; lblErr10.Visible = visible; } private void LoadExam(int pageNum) { int startNum = (pageNum - 1) * 10; for (int i = 0; i < 10; i++) { if (i < exam.Problems.Count) { Problem problem = exam.Problems[i + startNum]; txt1 = GetTextBox(i + 1, 1); txt2 = GetTextBox(i + 1, 2); txt3 = GetTextBox(i + 1, 3); lblErr = GetLableErr(i + 1); lblIndex = GetLableIndex(i + 1); lblOp = GetLableOp(i + 1); lblIndex = GetLableIndex(i + 1); lblIndex.Text = (startNum + i + 1).ToString() + "."; lblOp.Text = GetOperationString(problem.Operation); if (problem.AnswerPosition == 1) { txt1.ReadOnly = false; if (problem.IsAnswered) { if (problem.Answer !=int.MinValue) { txt1.Text = problem.Answer.ToString(); } else { txt1.Text = ""; } lblErr.Text = problem.Answer == problem.Num1 ? "正确" : "错误"; } else { txt1.Text = ""; } txt2.Text = problem.Num2.ToString(); txt2.ReadOnly = true; txt3.Text = problem.Num3.ToString(); txt3.ReadOnly = true; } else if (problem.AnswerPosition == 2) { txt1.ReadOnly = true; txt1.Text = problem.Num1.ToString(); txt2.ReadOnly = false; if (problem.IsAnswered) { if (problem.Answer !=int.MinValue) { txt2.Text = problem.Answer.ToString(); } else { txt2.Text = ""; } lblErr.Text = problem.Answer == problem.Num2 ? "正确" : "错误"; } else { txt2.Text = ""; } txt3.Text = problem.Num3.ToString(); txt3.ReadOnly = true; } else if (problem.AnswerPosition == 3) { txt1.ReadOnly = true; txt1.Text = problem.Num1.ToString(); txt2.Text = problem.Num2.ToString(); txt2.ReadOnly = true; txt3.ReadOnly = false; if (problem.IsAnswered) { if (problem.Answer !=int.MinValue) { txt3.Text = problem.Answer.ToString(); } else { txt3.Text = ""; } lblErr.Text = problem.Answer == problem.Num3 ? "正确" : "错误"; } else { txt3.Text = ""; } } } } } private void SetErrColor() { lblErr1.ForeColor = lblErr1.Text == "错误"? Color.Red : Color.Black; lblErr2.ForeColor = lblErr2.Text == "错误"? Color.Red : Color.Black; lblErr3.ForeColor = lblErr3.Text == "错误"? Color.Red : Color.Black; lblErr4.ForeColor = lblErr4.Text == "错误"? Color.Red : Color.Black; lblErr5.ForeColor = lblErr5.Text == "错误"? Color.Red : Color.Black; lblErr6.ForeColor = lblErr6.Text == "错误"? Color.Red : Color.Black; lblErr7.ForeColor = lblErr7.Text == "错误"? Color.Red : Color.Black; lblErr8.ForeColor = lblErr8.Text == "错误"? Color.Red : Color.Black; lblErr9.ForeColor = lblErr9.Text == "错误"? Color.Red : Color.Black; lblErr10.ForeColor = lblErr10.Text == "错误"? Color.Red : Color.Black; } private ExamType GetExamType() { return (ExamType)tcmbType.SelectedIndex; } private ExamLevel GetExamLevel() { switch (tcmbLevel.SelectedIndex) { case 0: return ExamLevel.L10; case 1: return ExamLevel.L20; case 2: return ExamLevel.L100; } return ExamLevel.L10; } private int GetNumOfProbles() { switch (tcmbNum.SelectedIndex) { case 0: return 10; case 1: return 20; case 2: return 50; case 3: return 100; } return 10; } private void tbtnCreate_Click(object sender, EventArgs e) { if (CheckToolBarInfo()) { examType = GetExamType(); level = GetExamLevel(); numOfProblems = GetNumOfProbles(); maxPageNum = numOfProblems / 10; exam = new Exam(examType, level, numOfProblems); LoadExam(pageNum); SetFocus(); } } private void btnNext_Click(object sender, EventArgs e) { GetExamAnswer(pageNum); if (pageNum < maxPageNum) { pageNum++; txtPage.Text = pageNum.ToString(); LoadExam(pageNum); SetFocus(); SetErrVisbility(false); } } private void SetFocus() { switch (exam.Problems[0].AnswerPosition) { case 1: txtNUM11.Focus(); break; case 2: txtNUM12.Focus(); break; case 3: txtNUM13.Focus(); break; } } private bool CheckToolBarInfo() { if (tcmbType.SelectedIndex < 0) { MessageBox.Show("请选择运算。"); return false; } if (tcmbLevel.SelectedIndex < 0) { MessageBox.Show("请选择难度。"); return false; } if (tcmbNum.SelectedIndex < 0) { MessageBox.Show("请选择题数。"); return false; } return true; } private void lblIndex1_Click(object sender, EventArgs e) { } private void From1_Load(object sender, EventArgs e) { } private void btnPrevious_Click(object sender, EventArgs e) { GetExamAnswer(pageNum); if (pageNum < maxPageNum) { pageNum--; txtPage.Text = pageNum.ToString(); LoadExam(pageNum); SetFocus(); SetErrVisbility(false); } } private void btnOk_Click(object sender, EventArgs e) { GetExamAnswer(pageNum); SetErrVisbility(true); SetErrColor(); } public int FormCheckExamId { get; set; } private void tcmbNum_Click(object sender, EventArgs e) { } } }
下面的调试的截图
这是开始页面。
这是可以选择运算形式。
这是选择数的范围。
这是生成出题目的样子。
这是判断正误的结果。