博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
四则运算 改后
阅读量:6992 次
发布时间:2019-06-27

本文共 4202 字,大约阅读时间需要 14 分钟。

 题目编写一个能对0--10之间的整数进行四则运算的“软件”;

         程序能接收用户输入的整数答案,并判断对错;
         程序结束时,统计出答对、答错的题目数量。
补充说明0——10的整数是随机生成的;
          用户可以用键盘输入来选择四则运算中的一种,比如输入1代表加法运算;
          用户用键盘输入一个字符来结束程序的运行并显示统计结果,比如输入e程序结束并显示统计结果              编程语言不限制,命令行输出和图像界面输出都可以。

1.需求分析

设计环境:C#窗体应用程序;

目的:能进行0—10之间随机的整数四则运算;

        接受整数答案,判断对错可以统计答对答错的题数;

代码的设计思路:

代码具体设计:

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 Form1()        {            InitializeComponent();        }        public static int count = 0;        public static int right = 0;        public static int wrong = 0;        private void RandomNum()        {            Random ran = new Random();            int a, b;            a = ran.Next(1, 11);            b = ran.Next(1, 11);            textBox1.Text = a.ToString();            textBox2.Text = b.ToString();            textBox3.Text = "";        }        private void Form1_Load(object sender, EventArgs e)        {            RandomNum();        }        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)        {            int sum;            string i = label1.Text;            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 if (label1.Text == "/")                            sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);            if (textBox3.Text == sum.ToString())                right++;            else                wrong++;            RandomNum();        }        private void button6_Click(object sender, EventArgs e)        {            Form2 frm2 = new Form2();            frm2.ShowDialog();        }        private void button6_KeyDown(object sender, KeyEventArgs e)        {            if (e.KeyCode == Keys.Enter)            {                Form2 frm2 = new Form2();                frm2.ShowDialog();            }        }        private void button1_KeyDown(object sender, KeyEventArgs e)        {            if (e.KeyCode == Keys.A)            {                label1.Text = "+";            }        }        private void button2_KeyDown(object sender, KeyEventArgs e)        {            if (e.KeyCode == Keys.S)            {                label1.Text = "-";            }        }        private void button3_KeyDown(object sender, KeyEventArgs e)        {            if (e.KeyCode == Keys.D)            {                label1.Text = "*";            }        }        private void button4_KeyDown(object sender, KeyEventArgs e)        {            if (e.KeyCode == Keys.F)            {                label1.Text = "/";            }        }    }}

  

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 Form2 : Form    {        public Form2()        {            InitializeComponent();        }        private void Form2_Load(object sender, EventArgs e)        {            textBox1.Text = Form1.right.ToString();            textBox2.Text = Form1.wrong.ToString();            textBox3.Text = ((Form1.right / (double)(Form1.count) *                100).ToString() + "%");        }    }}

 

PSP耗时分析:

 
估计需要的时间 12小时
需求分析 30分钟
生成设计文档 30分钟
设计复审 30分钟
代码规范 1小时
具体设计 3小时
具体编码 3小时
代码复审 1小时
测试 30分钟
测试报告 30分钟
报告总结 30分钟

报告总结:

 运行出来了,这是截图。底子太薄弱了,以后我会找些例子练习练习的;

运行代码如下:

转载于:https://www.cnblogs.com/mhwgo2205509957/p/4857827.html

你可能感兴趣的文章
Linux内核-内核线程
查看>>
zoj 1152 A Mathematical Curiosity
查看>>
UML时序图总结
查看>>
【2013Esri全球用户大会精彩案例】Horry Count GIS--南卡罗来那州霍里县企业级应用...
查看>>
c++虚函数表 Brew VTBL
查看>>
SQL Server 2008开启sa账户以及如何用JDBC进行连接
查看>>
读取同一文件夹下多个txt文件中的特定内容并做统计
查看>>
为sourceinsight添加makefile、kconfig、*.S文件支持
查看>>
sharepoint2010问卷调查(1)-实现问卷的图片调查(采用JS实现)
查看>>
linux下如何挂接(mount)光盘镜像文件、移动硬盘、U盘、Windows网络共享和NFS网络共享...
查看>>
python开发_函数的参数传递
查看>>
利用mysqldump 实现每天备份方案
查看>>
一周一世界,一世一漂泊
查看>>
屏保:画圈圈诅咒你
查看>>
(转)连接(内、左、右、外、交叉)查询
查看>>
基于Flot可放缩的折线图
查看>>
Redis debugging guide---官方
查看>>
LINQ
查看>>
微信支付宝
查看>>
Android下用Activity实现圆角的自定义弹窗
查看>>