zoukankan      html  css  js  c++  java
  • 典型用户和场景代码的实现

    <需求分析>

    老陈希望通过一款软件来储存自己出的题,然后让孩子自己去做并给出评价,

    1,用户可以输入题。

    2,可以储存用户输入的题。

    3,可以通过用户输入的题进行出题。

    4,可以做出评价。

    <设计思路>

    1,创建windows窗体,设计窗体,并根据窗体进行编码。

    2,首先创建储存文件夹。

    3,写一个储存的方法。

    4,然后是读出用户所出的题。

    5,写一个判断正误的方法。

    <代码实现>

    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();
            }
    
            private void button1_Click(object sender, EventArgs e)//写入
            {
                    string fnm = @"one";
                    StreamWriter aaa = new StreamWriter(fnm,true);
                    aaa.WriteLine(this.textBox1.Text);
                    aaa.Close();
                    string fnmm = @"tow";
                    StreamWriter ddd = new StreamWriter(fnmm,true);
                    ddd.WriteLine(this.textBox2.Text);
                    ddd.Close();
                    string fnmn = @"fuhao";
                    StreamWriter fff = new StreamWriter(fnmn,true);
                    fff.WriteLine(this.comboBox1.Text);
                    fff.Close();
                    textBox1.Clear();
                    textBox2.Clear();
                                     
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                Form2 fam = new Form2();
                fam.ShowDialog();
             
            }
    
            private void button3_Click(object sender, EventArgs e)//清空题库
            {
                string fnmm = @"tow";
                StreamWriter ddd = new StreamWriter(fnmm);
                ddd.WriteLine(" ");
                ddd.Close();
                string fnm = @"one";
                StreamWriter aaa = new StreamWriter(fnm);
                aaa.WriteLine("");
                aaa.Close();
                string fnmn = @"fuhao";
                StreamWriter fff = new StreamWriter(fnmn);
                fff.WriteLine("");
                fff.Close();
            }
          
     
            }
        }
    

     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;
    using System.IO;
    
    namespace 出题
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
    
           private int sun; 
           private int i = 1;
           public static int count;
           public static int right;
            private void timer1_Tick(object sender, EventArgs e)
            {
                try
                {
                    int t = int.Parse(textBox5.Text);
                    if (t <= 0)
                    {
                        timer1.Enabled = false;
                        textBox5.Enabled = false;
                        MessageBox.Show("时间到了!");
                        Form3 fr3 = new Form3();
                        fr3.ShowDialog();
                    }
                    t = t - 1;
                    textBox5.Text = t.ToString();
    
                }
                catch
                { 
                }
    
            }
            private void button1_Click(object sender, EventArgs e)//开始
            {
                butt();
                try
                {
                    string t = textBox5.Text;
                    textBox5.Text = t;
                    timer1.Enabled = true;
                    timer1.Interval = 1000;
                    timer1.Start();
                }
                catch
                { 
                }
    
               
          
            }
            private void textBox4_KeyDown(object sender, KeyEventArgs e)
            {                      
                if (e.KeyCode == Keys.Enter)
                {
    
                    
                    string f = textBox2.Text;
                    int a = int.Parse(textBox1.Text);
                    int b = int.Parse(textBox3.Text);              
                    calcula(f, a, b);        
                    if (textBox4.Text == sun.ToString())
                    {
                        MessageBox.Show("回答正确!");
                        right++;
                    }
                    else
                    {
                        MessageBox.Show("回答错误!");
                    }
                    count++;
                    textBox4.Clear();
                    butt();      
                   
                  
                  
                }
                
                
            }//用户的输入
            private void button2_Click(object sender, EventArgs e)//停止
            {
                textBox4.Enabled=false;
    
            }
            private  int calcula(string operato, int a, int b)
            {
    
                switch (operato)
                {
                    case "+":
                        sun = a + b;
                        break;
                    case "-":
                        sun = a - b;
                        break;
                    case "*":
                        sun = a * b;
                        break;
                    case "/":
                        sun = a / b;
                        break;
    
                }
                return sun;
              
    
            }//求正确的值
            private void butt()
            {
                string[] line = File.ReadAllLines("one");
                if (i < line.Length )
                {
                    textBox1.Text = line[i];
                    string[] lines = File.ReadAllLines("tow");
                    textBox3.Text = lines[i];
                    string[] lin = File.ReadAllLines("fuhao");
                    textBox2.Text = lin[i];
    
                }
                i++;
                if (i == line.Length+1)
                {
                    Form3 foo = new Form3();
                    foo.ShowDialog();
                }
          
               
     
            }//读题
            private void button3_Click(object sender, EventArgs e)
            {
                this.Close();
            }//关闭窗体
    
        }
    }
    

     form3的代码

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

     <测试>

     <总结>

    刚开始写时真的没有一点头绪,不知道怎么实现写入,不用数据库不知道怎么保存,就是写入了也会清空上次的数据,终于不再清空上次的了,但是又不知道怎么一个一个的读出来,只能读出一个,但是最后还是一个一个的实现了。感觉自己增长了不少,同时有感觉很有成就感。知道了代码的严肃性,懂得了有时候看似不起眼的位置其实起了很大的作用。

  • 相关阅读:
    实现websocket中遇到的恶心问题。
    移动js框架使用报告
    超级难用的wireshark。
    三国演义LBS 20110406 本次清明节解决问题列表。
    【原创意】一个市值估算超亿的创意——愤怒的小猪(谢绝抄袭和冒名顶替)
    一个小游戏 让你感受“如何等待成功”!
    js 游戏引擎 + canvas 入门
    javascript 中的反射
    使用HTML5进行地理位置定位。误差在+500m
    【原创意】新浪微博都感到巨大鸭梨的全新创意 —— 二维码社区"神码"
  • 原文地址:https://www.cnblogs.com/lizanqirxx/p/4963127.html
Copyright © 2011-2022 走看看