• 第一次打程序


      需求分析:说实话这是第一次打程序感觉如丈二和尚摸不着头脑,看看别人做的,然后看看书上类似的例子,看了很久也想了很久,可还是无从下手于是就找到朋友,在其帮助下勉为其难的把这次作业写完    需求是做一个窗体功能是编写一个能对0--10之间的整数进行四则运算的“软件” 程序能接收用户输入的整数答案,并判断对错程序结束时,统计出答对、答错的题目数量。
       设计思路:创作两个窗体,窗体1添加3个textbox及7个botton一个label,窗体2添加3个label三个textbox

       代码实现:

    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 计算机
    {
        public partial class Form1 : Form
        {
            public static int count = 0;
            public static int right = 0;
         
            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {


            }

            private void RandomNum()
            {
                Random ran = new Random();
                int a1, a2;
                a1 = ran.Next(1, 11);//产生一个加数
                a2 = ran.Next(1, 11);//产生一个加数
                textBox1.Text = a1.ToString();
                textBox2.Text = a2.ToString();
                textBox3.Text = "";
               
            }


            private void button6_Click(object sender, EventArgs e)
            {
                count++;
                right++;
                textBox3.Enabled = false;
                Form2 frm2 = new Form2();
                frm2.ShowDialog();

            }

            private void textBox3_KeyDown(object sender, KeyEventArgs e)
            {
              
                int sum=0; //调用计算方式
                string m = button7.Text;
                switch (m)
                {
                    case "+":
                        sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);
                        break;
                    case "—":
                        sum = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);
                        break;
                    case "×":
                        sum = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);
                        break;
                    case "÷":
                        sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
                        break;
                    default:
                        break;
                }
                        if (e.KeyCode == Keys.Enter) //判断题目的正确率
                        {
                            if (textBox3.Text == sum.ToString())
                            {
                                right++;
                                count++;
                                RandomNum();
                            }
                            else
                            {
                                count++;
                                RandomNum();
                            }
           
               
                       
                }

            }

            private void button1_Click(object sender, EventArgs e) //显示各种运算符号
            {
                RandomNum();
                button7.Text = "+";
            }

            private void button2_Click(object sender, EventArgs e)
            {
                RandomNum();
                button7.Text = "-";
            }

            private void button3_Click(object sender, EventArgs e)
            {
                RandomNum();
                button7.Text = "*";
            }

            private void button4_Click(object sender, EventArgs e)
            {
                RandomNum();
                button7.Text = "/";
            }

            private void button5_Click(object sender, EventArgs e)
            {

            }
        }
    }

       测试:

       总结:其实找到朋友帮忙做到最后还是还有一些问题没有解决就是到最后统计的时候总是对不上数,只好很尴尬的打上代码向上凑,为了程序的正确度、完整性,在朋友的帮助下勉强凑够了但还不知道为什么对还望老师指导。

             怎么说呢通过作这个程序还是学到了很多比平时慢无目的照着书敲代码强太多,期望老师的下一次作业。

     

  • 相关阅读:
    Agreementhasbeenupdated--EditPhoneNumber
    android 6.0之后动态获取权限
    appstore加速审核通道
    ListView多种item注意以及自己出现的莫名其妙的错误
    2020-10-15:mysql的双1设置是什么?
    2020-10-14:Redisson分布式锁超时自动释放,会有什么问题?
    2020-10-13:hash与B+tree的区别?
    2020-10-12:在做分布式集群时候一般会产生什么问题?
    2020-10-11:一条sql语句执行时间过长,应该如何优化?从哪些方面进行优化?
    2020-10-10:OOM都有哪些,说出几种?
  • 原文地址:https://www.cnblogs.com/Dark1230/p/4857650.html
Copyright © 2020-2023  润新知