国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C#窗體隨機四則運算(第四次作業)

2019-11-14 13:52:02
字體:
來源:轉載
供稿:網友

---恢復內容開始---

增量內容:1)處理用戶的錯誤輸入,比如輸入字母或符號等,處理除法運算中分母為0的情況,處理結果為負數的情況,保證是小學水平不出現負數,比如不能出現5-8=-3這種情況;2)用戶可以設定倒計時;  3)用戶可以設定隨機整數的范圍和題目數量;4)用戶可以選擇哪種計算類型,比如加減乘除,或可選擇軟件隨機生成四則運算中的一種;  5)用戶可以選擇隨機生成的題目中是否帶有小括號,比如(2+3)*5,如果是gui程序,添加這個功能可以用復選框實現;    6)保證生成過的題目不再重復出現。

設計思路:上次作業我們用的是控制臺,這次原本還想用控制臺,但是我的隊友洪亮建議我用窗體,所以這次做這道題完全是把開始的作業都做了一遍,開始的時候其實還蠻順利的,知道要實現用戶可以輸入范圍的時候遇到了一些小問題,但是很快就解決了,完成其它實現的時候我們也會有一些分歧,不如要不要做個提示告訴用戶在同一個界面上出現你已經做了多少道題,我說不要,他要,但是還是寫上了,但是等到界面全部完成后,感覺加上還蠻合適的,就這樣我們每個人負責一些任務,遇到問題我們就在一起解決,然而比一個

人做輕松了好多。下面是我們結對時的照片!!!

需求分析:增加的內容前幾個還好啦,不是很難,但是要實現混合運算有點想不到方法,我們也上查了一下,但是網上介紹的方法比如棧,樹的方式不是很懂,我們也實驗了好多可是都沒成功,有好多疑問,因為時間比較緊,所以課后做好了。

namespace _000000{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        public static int Count = 0;        public static int right = 0;        public static int fault = 0;  
PRivate void RandomNum() { Random ran = new Random(); int a, b; string m; a = ran.Next(int.Parse(textBox4.Text), int.Parse(textBox5.Text)); b = ran.Next(int.Parse(textBox4.Text), int.Parse(textBox5.Text)); if (a >= b) { textBox1.Text = a.ToString(); textBox2.Text = b.ToString(); textBox3.Text = ""; Count++; textBox6.Text = Form1.Count.ToString(); if (textBox7.Text == textBox6.Text) { MessageBox.Show("你已做完計算!"); } } else if (a < b) { m = b.ToString(); textBox2.Text = a.ToString(); textBox1.Text = m; textBox3.Text = ""; Count++; textBox6.Text = Form1.Count.ToString(); if (textBox7.Text == textBox6.Text) { MessageBox.Show("你已做完計算!"); } } } private void timer1_Tick(object sender, EventArgs e) { if (Convert.ToInt32(textBox8.Text) <= 0) {

                  timer1.Enabled = false;
                  textBox3.Enabled = false;
                  MessageBox.Show("時間到!");
                  textBox3.Enabled = false;
                  Form2 frm2 = new Form2();
                  frm2.ShowDialog()

            }

              int t = Convert.ToInt32(textBox8.Text);

              t = t - 1;

              textBox8.Text = t.ToString();

        }

private void textBox3_KeyDown(object sender, KeyEventArgs e)        {            int sum = 0;            string m = label3.Text;            if (m == "+")            {                sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);                if (e.KeyCode == Keys.Enter)                {                    if (textBox3.Text == sum.ToString())                    {                        right++;                        RandomNum();                    }                    else                    {                        fault++;                        RandomNum();                    }                }            }            else if (m == "-")            {                sum = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);                if (e.KeyCode == Keys.Enter)                {                    if (textBox3.Text == sum.ToString())                    {                        right++;                        RandomNum();                    }                    else                    {                        fault++;                        RandomNum();                    }                }            }            else if (m == "x")            {                sum = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);                if (e.KeyCode == Keys.Enter)                {                    if (textBox3.Text == sum.ToString())                    {                        right++;                        RandomNum();                    }                    else                    { fault++;                    RandomNum();                    }                }            }            else            {                sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);            }                    }        private void button1_Click(object sender, EventArgs e)        {            label3.Text = "+";
int t = Convert.ToInt32(textBox8.Text); label2.Text
= t.ToString(); timer1.Enabled = true; timer1.Interval = 1000; timer1.Start(); RandomNum(); } private void button2_Click(object sender, EventArgs e) { label3.Text = "-";
int t = Convert.ToInt32(textBox8.Text); label2.Text
= t.ToString(); timer1.Enabled = true; timer1.Interval = 1000; timer1.Start(); RandomNum(); } private void button3_Click(object sender, EventArgs e) { label3.Text = "x";
int t = Convert.ToInt32(textBox8.Text); label2.Text
= t.ToString(); timer1.Enabled = true; timer1.Interval = 1000; timer1.Start(); RandomNum(); } private void button4_Click(object sender, EventArgs e) { label3.Text = "/";
int t = Convert.ToInt32(textBox8.Text); label2.Text
= t.ToString(); timer1.Enabled = true; timer1.Interval = 1000; timer1.Start(); Random ran = new Random(); int a, b; string m; a = ran.Next(int.Parse(textBox4.Text), int.Parse(textBox5.Text)); b = ran.Next(int.Parse(textBox4.Text), int.Parse(textBox5.Text)); if (b != 0) { textBox1.Text = a.ToString(); textBox2.Text = b.ToString(); textBox3.Text = ""; Count++; textBox6.Text = Form1.Count.ToString(); if (textBox7.Text == textBox6.Text) { MessageBox.Show("你已做完計算!"); } } else { m = b.ToString(); textBox2.Text = a.ToString(); textBox1.Text = m; textBox3.Text = ""; Count++; textBox6.Text = Form1.Count.ToString(); if (textBox7.Text == textBox6.Text) { MessageBox.Show("你已做完計算!"); } } } private void button7_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); frm2.ShowDialog(); } private void textBox4_TextChanged(object sender, EventArgs e) { int result; if (int.TryParse(textBox4.Text, out result) == false) { if (!(textBox4.Text == "")) { MessageBox.Show("請輸入數字!", "提示"); textBox4.Clear(); } } } private void textBox5_TextChanged(object sender, EventArgs e) { int result; if (int.TryParse(textBox5.Text, out result) == false) { if (!(textBox5.Text == "")) { MessageBox.Show("請輸入數字!", "提示"); textBox5.Clear(); } } } private void textBox7_TextChanged(object sender, EventArgs e) { int result; if (int.TryParse(textBox7.Text, out result) ==false) { if (!(textBox7.Text == "")) { MessageBox.Show("請輸入數字!", "提示"); textBox7.Clear(); } } } private void button5_Click(object sender, EventArgs e) { textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); textBox5.Clear(); textBox7.Clear(); } } }

 

PsP耗時

總結:沒到看到和自己的伙伴完成一個項目時,頓時感覺付出的辛苦和努力都很值得,特別是看到隊友那嘴角上揚的笑容,他心里應該會很自豪吧,但我也會感到非常快樂。結對編程是第二次做,比起第一次感覺配合的更默契一點,希望以后還是結對編程。

最后有一個小小的請求,希望老師能提示一下實現混合運算的方法如果老師能有個例子就更好了!!!

 

 

 

 


             
           
             

           

         

---恢復內容結束---


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 湘阴县| 宁强县| 山丹县| 平南县| 五家渠市| 蒙山县| 阿瓦提县| 宽城| 个旧市| 阜阳市| 二连浩特市| 鹿邑县| 灌阳县| 资兴市| 潞西市| 三原县| 东兴市| 常山县| 饶阳县| 阳原县| 特克斯县| 南溪县| 高平市| 九寨沟县| 彰武县| 尉犁县| 鹤岗市| 望城县| 海晏县| 开鲁县| 瑞金市| 衢州市| 锡林浩特市| 乐陵市| 邢台县| 岑巩县| 逊克县| 佛山市| 河西区| 青田县| 建阳市|