码迷,mamicode.com
首页 > 其他好文 > 详细

第三次作业,疑问希望老师解答一下。谢谢

时间:2015-10-04 09:56:32      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:

作业要求:

该程序是一个能随机在1-10数字之间整数进行的四则运算,程序可以根据用户输入的答案判断对错,并且可以统计出答题的总数和答对题的数量。

(做了两个第一个遇到点麻烦,又做第二个)

这是我第一次做的窗体程序,但是遇到点麻烦,运行起来点击第一个数textbox1或第二个数textbox2或第三个数textbox3中任意一个按钮运行的页面就会消失,但还在调试中。我问陈老师,老师没能给我具体解答,只好等开学问c#老师。所以这个程序就先搁置这了。下面作业是后来用控制台做的

设计思路:

1、先建两个窗体,拉进去自己需要的控件,然后编写代码。

2、定义正确和总的题数的变量。

3、Random产生随机数。

4、textBox3计算加减乘除结果,单击开始运行。

5、停止转到Form2进行测试。 

 

技术分享

 

 

技术分享

 

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;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int count = 0;
private int t = 60;
public static int right = 0;

private void button1_Click(object sender, EventArgs e)
{
label4.Text = t.ToString();
timer1.Enabled = true;
timer1.Interval = 1000;
timer1.Start();
RandomNum();
}
private void RandomNum()
{
Random ran = new Random();
int n1, n2;
n1 = ran.Next(1, 11);
n2 = ran.Next(1, 11);
textBox1.Text = n1.ToString();
textBox2.Text = n2.ToString();
textBox3.Text = "";
count++;
}

private void timer1_Tick(object sender, EventArgs e)
{
if (t <= 0)
{
timer1.Enabled = false;
textBox3.Enabled = false;
MessageBox.Show("时间到!");
textBox3.Enabled = false;
Form2 frm2 = new Form2();
frm2.ShowDialog();
}
t = t - 1;
label4.Text = t.ToString();

}

private void button2_Click(object sender, EventArgs e)
{
textBox3.Enabled = false;
Form2 frm2 = new Form2();
frm2.ShowDialog();
}

 

 


private void button3_Click(object sender, EventArgs e)
{
new Form3().Show();
}

private void textBox3_KeyDown(object sender, KeyEventArgs e)
{
int sum;
if (comboBox1.Text == "+")
sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);
else
if (comboBox1.Text == "-")
sum = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);
else
if (comboBox1.Text == "*")
sum = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);
else
if (comboBox1.Text == "/")
sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);

 


if (e.KeyCode == Keys.Enter)
{
if (textBox3.Text == textBox3.ToString())
right++;
textBox3.Text = "";
RandomNum();


}

 


}
}
}

 

这个程序花费我两天但我不后悔。

思考题:

   private void Random()

 

        {

 

            Random ran = new Random();

 

            int n1, n2;

 

            n1 = ran.Next(1, 11);

 

            n2 = ran.Next(1, 11);

 

            textBox1.Text = n1.ToString();

 

            textBox2.Text = n2.ToString();

 

            textBox3.Text="";

 

            count++;

//换成

 

   private void Random()

 

        {

 

            Random ran = new Random();

 

            int n1, n2;

 

            n1 = ran.Next(1, 101);

 

            n2 = ran.Next(1, 101);

 

            textBox1.Text = n1.ToString();

 

            textBox2.Text = n2.ToString();

 

            textBox3.Text="";

 

            count++;//就行了

 

 第二次做

设计思路:

用控制台应用程序设计,主要运用定义变量,并用while(){}循环,switch(表达式){case常量表达式1:语句1;break;case常量表达式2:语句2;break;.....default;语句m;break;}循环语句,if(){}循环语句来实现程序的运用。

代码如下:

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace jiajianyunsuan
{
class Program
{
static void Main(string[] args)
{

int q = 0;
int x = 1;
int o = 0;
Random r = new Random();


while (q < 1)
{
int a = r.Next(0, 11);
int b = r.Next(0, 11);
int c = r.Next(0, a);
int d = r.Next(1, 11);
Console.WriteLine("请输入1为加,2为减,3为乘,4为除");
int y = int.Parse(Console.ReadLine());
switch (y)
{
case 1:
Console.WriteLine("第{0}题:{1} + {2} = ? ", x, a, b);
int result = Convert.ToInt32(Console.ReadLine());
if (result == a + b)
{
o++;

;

}
x++;
break;
case 2:
Console.WriteLine("第{0}题:{1} - {2} = ? ", x, a, c);
int result2 = Convert.ToInt32(Console.ReadLine());
if (result2 == a - c)
{
o++;

}
x++;

break;
case 3:
Console.WriteLine("第{0}题:{1} * {2} = ? ", x, a, b);

int result3 = Convert.ToInt32(Console.ReadLine());

if (result3 == a * b)
{
o++;

}
x++;
break;
case 4:
Console.WriteLine("第{0}题:{1} / {2} = ? ", x, a, d);

int result4 = Convert.ToInt32(Console.ReadLine());
;
if (result4 == a / d)
{
o++;

}
x++;
break;

}
Console.WriteLine("输入0继续答题,输入1结束答题");
int q1 = int.Parse(Console.ReadLine());
q = q + 1;

}

Console.WriteLine("你一共答了{0}题,你答对了{1}题", x - 1, o);
Console.ReadLine();


}
}
}

 

技术分享

 

整个作业做下来真不容易,第一个程序整整花了我两天时间,克服了九九八十一难还是没有成功,第二个是请教同学之后做出来的,这个作业考虑的更多一点,想到了除数不能为零,这个程序页面看起来没有窗体看到简洁明了,但是相对来说这个更容易设计。

psp耗时分析:

psp Personal Software Process Stages Time(h)
planning .计划 36
.Estimate .估计这个任务需要多长时间 36
Development .开发 30
.Analysis .需求分析 3
.Design Spec .生成设计文档 3
.Design Review .设计复审 2
• Coding Standard .代码规范 2
 • Design .具体设计 3
 • Coding .具体编码 8
• Code Review .代码复审 4
 • Text .测试 2
Reporting .报告 1
• Test Report .测试报告 1
• Size Measurement .计算工作量 1
 • Postmortem&Process Improvement Plan .事后总结并提出改进计划 4

思考题:

同上,只要把范围改一下就行了

nt a = r.Next(0, 11);
int b = r.Next(0, 11);
int c = r.Next(0, a);
int d = r.Next(1, 11);

改成

nt a = r.Next(0, 101);
int b = r.Next(0, 101);
int c = r.Next(0, a);
int d = r.Next(1, 101);

附加题:

有一点想法 ,但不知道成熟不成熟。不敢写。

总结:做下来这个作业我的假期已经过的差不多了,虽然没能向同学们那样出去游玩,但我在书的海洋里遨游的也挺好。现在看来是我学的不到家。看到题后思路想法都是有的,具体实践有点难度,需要助手。不过,我会继续努力。加油

 

 

 

 

 

 

 

 

第三次作业,疑问希望老师解答一下。谢谢

标签:

原文地址:http://www.cnblogs.com/zj15517225953/p/4854139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!