第一次网上作业。

 需求分析:

写一个能对0到10之间的整数进行四则运算的“软件” 程序,能够对用户填写的结果进行判断并且能计算出用户做题的正确率。

思路:我认为这个题目用那个windowsFOrm那个做比较好吧,刚开始学习C#的时候,做的简单的计算器就是用那个做的。

 

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 jjcc
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public static int Count = 0;  
        public static int right = 1;
        public static int sum;

        private void js()
        {
            Random un = new Random();
            int a, b;
            a = un.Next(1, 11);
            b = un.Next(1, 11);
            textBox1.Text = a.ToString();
            textBox2.Text = b.ToString();
            textBox3.Text = "";
            

        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = "+";
        }

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

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

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



        private void button5_Click(object sender, EventArgs e)
        {
            if (textBox3.Text == sum.ToString())
            {
                
                Count++;
                right++;
                js();
            }
            else
            {
                Count++;
                js();
            }

        }



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

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

        private void button7_Click(object sender, EventArgs e)
        {
            if (textBox3.Text == sum.ToString())
            {
                
                Count++;
                right++;
                js();
            }
            else
            {
                Count++;
                js();
            }
        }
    }
}



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 jjcc
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            textBox1.Text =Form1.Count.ToString();
            textBox2.Text = Form1.right.ToString();
            textBox3.Text = ((Form1.right / (double)(Form1.Count)) * 100).ToString() + "%";
            
        }





老师,其实我是不会做的,前面的几句话是我自己写的。中间的代码是我看人家的,我自己做不出来,就看了看别人的了解一下,好像知道是这种类型的,可是实在写不好,只好写了别人写的好的,自己保存了看。





posted on 2015-10-06 22:31  王耀伟  阅读(140)  评论(2)    收藏  举报

导航