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


    作业要求:

    该程序是一个能随机在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 ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    {
    int w = 0;
    int c= 0;
    do
    {
    Random suiji = new Random();
    int a = suiji.Next(0, 11);
    int b = suiji.Next(1, 11);

    Console.WriteLine("用'1''2''3''4'来选择运算符号");

    Console.WriteLine("用按回车输入x来结束运算");


    string i = Convert.ToString(Console.ReadLine());

    if (i == "1")
    {
    Console.WriteLine("{0}+{1}=" ,a, b);
    int q = Convert.ToInt32(Console.ReadLine());
    if (q == a + b)
    {

    w++;

    }
    else
    {
    Console.WriteLine("哎呦,答错啦!");
    c++;

    }
    }
    else
    if (i == "2")
    {
    Console.WriteLine("{0}-{1}=", a, b);
    int q = Convert.ToInt32(Console.ReadLine());
    if (q == a - b)
    {

    w++;

    }
    else
    {
    Console.WriteLine("又不小心,答错啦!");
    c++;

    }
    }
    else

    if (i == "3")
    {
    Console.WriteLine("{0}*{1}=", a, b);
    int q = Convert.ToInt32(Console.ReadLine());
    if (q == a * b)
    {

    w++;

    }
    else
    {
    Console.WriteLine("再错打你小屁屁");
    c++;

    }
    }
    else
    if (i == "4")
    {
    Console.WriteLine("{0}/{1}=", a, b);
    int q = Convert.ToInt32(Console.ReadLine());
    if (q == a / b)
    {

    w++;

    }
    else
    {
    Console.WriteLine("还错!生气了啊");
    c++;

    }
    }
    }
    while (Console.ReadLine() != "x");
    Console.WriteLine("你一共答对了{0}道题, 正确{1}.错误{2}", w + c, w, c);
    Console.WriteLine("继续努力,加油哦");
    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

    思考题:

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

    Random suiji = new Random();
    int a = suiji.Next(0, 11);
    int b = suiji.Next(1, 11);

    改成

    Random suiji = new Random();
    int a = suiji.Next(0, 101);
    int b = suiji.Next(1, 101);

    附加题:

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

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

     

  • 相关阅读:
    鼠标放大镜案例代码
    鼠标点击跟随,鼠标点击哪里,图片跟随到哪里;
    筋斗云效果(云朵在导航栏内随着鼠标移动)
    HDU5003:Osu!(签到题)HDU5038:(签到题,题意很坑)
    SDUT3146:Integer division 2(整数划分区间dp)
    SDUT3145:Integer division 1(换零钱背包)
    SDUT3143:Combinatorial mathematics(组合数学)
    SDUT3141:Count(哈希)好题
    SDUT1574:组合数的计算
    SDUT1607:Number Sequence(矩阵快速幂)
  • 原文地址:https://www.cnblogs.com/zj15517225953/p/4854139.html
Copyright © 2020-2023  润新知