首页 > 技术文章 > 第二次作业:四则运算

zwt0626 2015-10-05 16:11 原文

题目:编写一个能对0--10之间的整数进行四则运算的“软件” 程序能接收用户输入的整数答案,并判断对错 程序结束时,统计出答对、答错的题目数量。

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

需求分析,我感觉这个程序就是让小学生用的,让小学生联系0-10以内的加减乘除法。

思路:这个题,有点类似于我们现在所学的C#教程里的一道题,我感觉采用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();
            }
        }
    }
}

窗口2代码如下:

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() + "%";
            
        }

测试界面:

psp耗时分析:

PSP2.1 Personal Software Process Stages Time(h)
Planning 计划 2
  • Estimate 估计这个任务需要多长时间 2
Development 开发 6
  • Analysis 需求分析 3
  • Design Spec 生成设计文档 2
  • Coding Standard 代码规范 1
  • Design 具体设计 1
  • Coding 具体代码 3
  • Code Review 代码复审 2
  • Text 测试 2
Reporting 报告 2
  • Test Report 测试报告 0.5
  • Size Measurement 计算工作量

0.5

  • Postmortem 事后总结

1

 

 

 

 

 

 

 

 

 

 

 

 

总结:

做这个题,我感觉自己学的什么也不是,这样毕业了,根本找不到工作,学的太浅薄了,我想抓个强项学习,计算机应用学的,都是基础,老师经常说,师傅领进门,修行在个人,我认为形容计算机这个专业太对了,对于这次作业,居然要花几天做,我感觉,毕业找到工作,立马也会被辞退,学的太少,速度慢,不牢固的知识。多学,多看,多实践才是以后多注意的问题。如果没有别人的帮忙,我想我是完不成这次作业的。

关于附加题,:如果用户要求处理的范围是0——100,程序应该如何设计才能很轻松的应对扩展性。

          只需要改动这里, a = un.Next(1, 11);
                         b = un.Next(1, 11);
改为
                        a = un.Next(1, 101);
                        b = un.Next(1, 101);

推荐阅读