老陈与小石头运算代码

总结:在这次作业中学会了封装,但是还是不会运用策略模式。Form1窗体的代码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;
using System.IO;

namespace 老陈小石头
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string path = "I:\\大二上\\软件工程";
        public static int count=0;
        public static int t = 0;
        public static int right = 0;
        public static int sum;
        int j = 0;
        int i = 0;
        //"*"
        private void cheng_Click(object sender, EventArgs e)
        {
            ysf.Text = "*";
            count++;
            number2.Focus();
        }
        //"+"
        private void jia_Click(object sender, EventArgs e)
        {
            ysf.Text = "+";
            count++;
            number2.Focus();
        }
        //"-"
        private void jian_Click(object sender, EventArgs e)
        {
            ysf.Text = "-";
            count++;
            number2.Focus();
        }
        //出题
        private void submitan_Click(object sender, EventArgs e)
        {
            StreamWriter n1 = File.AppendText("n1.txt");
            n1.WriteLine(number1.Text);
            n1.Close();
            StreamWriter fu = File.AppendText("fu.txt");
            fu.WriteLine(ysf.Text);
            fu.Close();
            StreamWriter n2 = File.AppendText("n2.txt");
            n2.WriteLine(number2.Text);
            n2.Close();
            tiku.Text += number1.Text + ysf.Text + number2.Text + deng.Text + "\n";
            j++;
            number1.Text = "";
            number2.Text = "";
            ysf.Text = " ";
            txtsave.Enabled = true;
            txtopen.Enabled = true;
            number1.Focus();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            t = t + 1;
            jitime.Text = t.ToString();
        }
        //开始答题
        private void start_Click(object sender, EventArgs e)
        {
            jitime.Text = t.ToString();
            timer1.Enabled = true;
            timer1.Interval = 1000;
            timer1.Start();
            string[] m1 = new string[100];
            m1 = File.ReadAllLines("n1.txt");
            string[] m2 = new string[100];
            m2 = File.ReadAllLines("fu.txt");
            string[] m3 = new string[100];
            m3 = File.ReadAllLines("n2.txt");
            textBox1.Text = m1[0];
            textBox2.Text = m2[0];
            textBox3.Text = m3[0];
            answer.Focus();
        }
        //提交答案
        private void mit_Click(object sender, EventArgs e)
        {
            string m = textBox2.Text;
            switch (m)
            {
                case "+":
                    sum = int.Parse(textBox1.Text) + int.Parse(textBox3.Text);
                    break;
                case "-":
                    sum = int.Parse(textBox1.Text) - int.Parse(textBox3.Text);
                    break;
                case "*":
                    sum = int.Parse(textBox1.Text) * int.Parse(textBox3.Text);
                    break;
                default:
                    break;
            }
            if (answer.Text == sum.ToString())
                right++;
            answer.Text = "";
            i++;
            if (i < j)
            {
                string[] m1 = new string[100];
                m1 = File.ReadAllLines("n1.txt");
                string[] m2 = new string[100];
                m2 = File.ReadAllLines("fu.txt");
                string[] m3 = new string[100];
                m3 = File.ReadAllLines("n2.txt");
                textBox1.Text = m1[i];
                textBox2.Text = m2[i];
                textBox3.Text = m3[i];
            }
            else
            {
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
            }
            answer.Focus();
        }
        //查看做题情况
        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            Form2 frm = new Form2();
            frm.Show();
        }
        //保存
        private void txtsave_Click(object sender, EventArgs e)
        {
            SaveFileDialog TxtSaveDialog = new SaveFileDialog();
            TxtSaveDialog.Filter = "RTF文件(*.RTF)|*.RTF";
            if (File.Exists(path))
            {
                this.tiku.SaveFile(path, RichTextBoxStreamType.RichText);
                MessageBox.Show("保存成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.tiku.Clear();
                txtsave.Enabled = false;
            }
            else
            {
                if (TxtSaveDialog.ShowDialog() == DialogResult.OK)
                {

                    this.tiku.SaveFile(TxtSaveDialog.FileName, RichTextBoxStreamType.RichText);
                    MessageBox.Show("保存成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.tiku.Clear();
                    txtsave.Enabled = false;
                }
            }
        }
        //查看
        private void txtopen_Click(object sender, EventArgs e)
        {
            OpenFileDialog TxTOpenDialog = new OpenFileDialog();
            TxTOpenDialog.Filter = "RTF文件(*.RTF)|*.RTF";
            if (TxTOpenDialog.ShowDialog() == DialogResult.OK)
            {
                path = TxTOpenDialog.FileName;
                this.tiku.LoadFile(TxTOpenDialog.FileName, RichTextBoxStreamType.RichText);
                txtsave.Enabled = false;
                txtopen.Enabled = false;
                MessageBox.Show("打开成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            txt tt = new txt();
            tt.text1();
        }
   }
}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 老陈小石头
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {            textcount.Text = Form1.count.ToString();
            Ttishu.Text = Form1.right.ToString();
            Tlv.Text = ((Form1.right / (double)(Form1.count)) * 100).ToString()+"%";
            yunss.Text=(Form1.t/(double)(Form1.count)).ToString()+"/t";
        }
    }
}类txt的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace 老陈小石头
{
    class txt
    {        //生成三个文本存放数据
        public void text1()
        {
            File.WriteAllText("n1.txt", string.Empty);
            File.WriteAllText("fu.txt", string.Empty);
            File.WriteAllText("n2.txt", string.Empty);
        }
    }
}




  

  

  

时间: 2024-08-03 07:26:28

老陈与小石头运算代码的相关文章

对于牛老师作业陈老师作业补充(老陈、小石头的典型用户、用例图、场景)

对于牛老师作业陈老师作业补充(老陈,小石头的典型用户.用例图.场景) 一  :  典型用户 (1)名字:小石头 性别:男 年龄:    8岁 职业:学生 收入:无 知识层次能力:小学二年级 生活/工作情况:父母抚养,无工作 动机,目的,困难:想测试自己的运算速度 用户偏好:上网,打小游戏,看动画片 典型场景:放学回家后,老陈了解他的学习情况 典型描述:正确率越高,小石头学的越好 (2)名字:老陈 性别:男 职业:大学教师 年龄:   40岁 收入:6000/月 知识层次能力:本科毕业 生活/工作

对于牛老师作业陈老师作业补充(老陈,小石头的典型用户、用例图、场景)

典型用户 名字:小石头 性别:男 职业:小学二年级学生 收入:无 知识层次能力:小学二年级 生活/工作情况:父母抚养,无工作 动机,目的,困难:想测试自己的运算速度 用户偏好:玩, 典型场景:放学回家后,老陈了解他的学习情况 典型描述:正确率越高,小石头学的越好 名字:老陈 性别:男 职业:大学教师 收入:5000/月 知识层次能力:本科毕业 生活/工作情况:生活美满,工作很好 动机,目的,困难:想测试孩子的学习 用户偏好:专研计算机, 典型场景:放学回家后,解决不能辅导孩子的空缺 典型描述:正

老陈与小石头

(1)典型故事 名字 老陈 年龄 45岁 职业 教师 知识层次和能力 本科毕业,能熟练操作电脑 用户偏好 上网查资料,看书 用户比例 50% 典型场景 辅导孩子完成家庭作业 典型描述 希望多些空闲时间 名字 小石头 年龄 8岁 职业 小学生 知识层次和能力 小学二年级学生,可以完成两位数的连加连减,能简单操作电脑 用户偏好 玩游戏,看电视 用户比例 50% 电型场景 完成家庭作业,遇到困难请父母帮助 典型描述 回家后完成家庭作业 (2)场景用例图 (3)用户故事 老陈:作为一个能熟练操作电脑的家

老陈,小石头、

1.背景 (1)典型用户: 老陈: 名字 老陈 性别.年龄 男,40岁 职业 大学老师 收入 1万元/月 知识层次喝能力 大学,能够熟练操作电脑基本功能,喜欢上网,发邮件 生活/工作情况 已婚/在大学任教 动机,目的,困难 作为一名老师每天要处理的问题比较多,没有过多的时间辅导孩子学习, 想借用此软件来辅导孩子学习以便于节省更多的时间 用户偏好 阅读 用户比例 50% 典型场景 借用程序节省时间工作 典型描述 工作繁忙,没有时间辅导孩子 小石头: 名字 小石头 性别.年龄 男,8岁 职业 小学二

老陈 小石头 典型事例

名字 老陈 性别,年龄 男,40岁 职业 大学老师 收入 5000/月 知识层次和能力 熟知计算机专业知识 生活,工作情况 在大学教书,有一个8岁的儿子 动机,目的,困难 想要一个软件帮助儿子做作业 用户偏好 看书,晒太阳 用户比例 ? 典型场景 辅导孩子做作业 典型描述 辅导孩子加减法运算,10以内乘法运算   名字 小石头 性别,年龄 男,8 职业 小学生 收入 - 知识层次和能力 小学二年级,只会加减法,10以内乘法 生活,工作情况 - 动机,目的,困难 练习四则运算 用户偏好 看电视,做

典型用户分析(小石头,老陈)

典型用户 名字:小石头 年龄.性别:9岁,男 职业:小学二年级学生 收入:无 知识层次能力:小学二年级 生活/工作情况:父母抚养,无工作 动机,目的,困难:想测试自己的运算速度 用户偏好:玩, 典型场景:放学回家后,老陈了解他的学习情况 典型描述:正确率越高,小石头学的越好 名字:老陈 年龄.性别:40岁,男 职业:大学教师 收入:5000/月 知识层次能力:本科毕业 生活/工作情况:生活美满,工作很好 动机,目的,困难:想测试孩子的学习 用户偏好:专研计算机, 典型场景:放学回家后,解决不能辅

小石头和老陈

名字 老陈 性别.年龄 男.40岁 职业 教师 收入 3000 知识层次和能力 熟知计算机 生活/工作情况 教学    动机,目的,困难 帮助孩子辅导作业 用户偏好 学习计算机相关书籍     用户比例 ? 典型场景 做一个可可以计时统计正确率的计算机软件 典型描述 可以让孩子更好的学习1 名字             小石头 性别.年龄 男,8 岁 职业 无 收入 无 知识层次和能力 小学二年级 生活/工作情况 上课 动机,目的,困难 提高做题速度 用户偏好 玩手机 用户比例 ? 典型场景 学

老陈 WPF

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Med

老陈---谈Delphi中SSL协议的应用[转]

摘要:本文主要介绍如何在Delphi中使用SSL协议.一共分为七个部分:(1)SSL协议是什么?(2)Delphi中如何使用SSL协议?(3)SSL客户端编程实例.(4)SSL服务端编程实例.(5)SSL证书编程实例.(6)中间人欺骗实例.(7)其它.本文作者同时有一个用SSL协议编写的作品叫SSLPROXY,感兴趣的读者可以从作者主页http://www.138soft.org下载. 一:SSL协议是什么?  SSL是一种加密传输协议.引用网上一段话:SSL 是Secure socket La