典型用户和场景代码的实现

摘要:
老陈希望通过一款软件来储存自己出的题,然后让孩子自己去做并给出评价,1,用户可以输入题。3,可以通过用户输入的题进行出题。4,可以做出评价。1,创建windows窗体,设计窗体,并根据窗体进行编码。4,然后是读出用户所出的题。5,写一个判断正误的方法。form1的代码usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;namespace出题{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidbutton1_Click//写入{stringfnm=@"one";StreamWriteraaa=newStreamWriter;aaa.WriteLine;aaa.Close();stringfnmm=@"tow";StreamWriterddd=newStreamWriter;ddd.WriteLine;ddd.Close();stringfnmn=@"fuhao";StreamWriterfff=newStreamWriter;fff.WriteLine;fff.Close();textBox1.Clear();textBox2.Clear();}privatevoidbutton2_Click{Form2fam=newForm2();fam.ShowDialog();}privatevoidbutton3_Click//清空题库{stringfnmm=@"tow";StreamWriterddd=newStreamWriter;ddd.WriteLine("");ddd.Close();stringfnm=@"one";StreamWriteraaa=newStreamWriter;aaa.WriteLine("");aaa.Close();stringfnmn=@"fuhao";StreamWriterfff=newStreamWriter;fff.WriteLine("");fff.Close();}}}form2的代码usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;namespace出题{publicpartialclassForm2:Form{publicForm2(){InitializeComponent();}privateintsun;privateinti=1;publicstaticintcount;publicstaticintright;privatevoidtimer1_Tick{try{intt=int.Parse;if{timer1.Enabled=false;textBox5.Enabled=false;MessageBox.Show("时间到了!");Form3fr3=newForm3();fr3.ShowDialog();}t=t-1;textBox5.Text=t.ToString();}catch{}}privatevoidbutton1_Click//开始{butt();try{stringt=textBox5.Text;textBox5.Text=t;timer1.Enabled=true;timer1.Interval=1000;timer1.Start();}catch{}}privatevoidtextBox4_KeyDown{if{stringf=textBox2.Text;inta=int.Parse;intb=int.Parse;calcula;if{MessageBox.Show("回答正确!

<需求分析>

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

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

<测试>

典型用户和场景代码的实现第1张典型用户和场景代码的实现第2张典型用户和场景代码的实现第3张典型用户和场景代码的实现第4张

<总结>

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

免责声明:文章转载自《典型用户和场景代码的实现》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇DS18B20温度传感器知识点总结Qt 信息提示框 QMessageBox下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

(转)string中的format

JDK1.5中,String类新增了一个很有用的静态方法String.format():format(Locale l, String format, Object... args) 使用指定的语言环境、格式字符串和参数返回一个格式化字符串。format(String format, Object... args) 使用指定的格式字符串和参数返回一个格式...

springboot中json转换LocalDateTime失败的bug解决过程

环境:jdk1.8、maven、springboot 问题:前端通过json传了一个日期:date:2019-03-01(我限制不了前端开发给到后端的日期为固定格式,有些人就是这么不配合),  而springboot中默认使用jackson做json序列化和反序列化,后台接收数据时将日期字符串转成LocalDateTime时,会报错: 1 Caused b...

delphi RTTI 反射技术

[delphi]view plaincopy unitUnit_main; interface uses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms, Dialogs,StdCtrls,TypInfo; type TForm_main=class...

[Java] 判断一个list是否包含于另一个list,如果没有,输出没包含的

ArrayList<String> actualList = ["1","2","3"] ArrayList<String> expectList = ["1","5","6"] containsList(actualList, expectList ) //Check the expectList in actualList s...

DICOM文件修改方法

/// <summary> /// 读取dicom文件 /// </summary> /// <param name="srcdirectory"></param> /// <param name="desdirectory"></param> public static void R...

ExecuteReader: Connection 属性尚未初始化。错误解决

读取student表中的数据打印到屏幕,代码 1 class Program 2 { 3 static void Main(string[] args) 4 { 5 string sqlc = @"server=.\sqlexpress;database=MyDataBase1...