C # Four random operations on the form (fourth job ),

Source: Internet
Author: User

C # Four random operations on the form (fourth job ),

--- Restore content start ---

Incremental content: 1) handle incorrect user input, such as input letters or symbols. handle the case where the denominator is 0 in the division operation and the result is negative, ensure that there is no negative number at the primary level, for example, 5-8 =-3 is not allowed; 2) users can set the countdown; 3) users can set the range of random integers and the number of questions; 4) You can select a computing type, such as addition, subtraction, multiplication, division, or one of the four random generation operations. 5) You can choose whether the randomly generated questions contain parentheses, for example (2 + 3) * 5. If it is a gui program, you can use the check box to add this function. 6) Ensure that generated questions are no longer repeated.

Design Concept: We used the console for the last job. We still wanted to use the console this time. However, my teammate Hong Liang suggested that I use the form, this is why I did all the homework I started and it was quite smooth at the beginning, we have encountered some minor problems when we want to implement the scope that users can enter, but it will soon be solved. When other implementations are completed, we will also have some differences, do you want to make a prompt to tell the user how many questions you have already done on the same interface? I say no, he wants it, but I still write it, but after the interface is complete, I feel that it is quite appropriate. In this way, each of us is responsible for some tasks and we will solve problems together.

People have made it easier. The following is a picture of pairing !!!

Requirement analysis: the first few items added are okay, but it is not very difficult. However, we also checked the method to implement hybrid operations. However, the methods introduced on the Internet, such as stacks, the method of tree learning is not very understandable. We have tried a lot but we have not succeeded. We have many questions. because of the tight schedule, we have done a good job after class.

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 =. toString (); textBox2.Text = B. toString (); textBox3.Text = ""; Count ++; textBox6.Text = Form1.Count. toString (); if (textBox7.Text = textBox6.Text) {MessageBox. sho W ("You have finished computing! ") ;}} Else if (a <B) {m = B. toString (); textBox2.Text =. toString (); textBox1.Text = m; textBox3.Text = ""; Count ++; textBox6.Text = Form1.Count. toString (); if (textBox7.Text = textBox6.Text) {MessageBox. show ("You have finished computing! ") ;}} Private void timereffectick (object sender, EventArgs e) {if (Convert. ToInt32 (textBox8.Text) <= 0 ){

Timer1.Enabled = false;
TextBox3.Enabled = false;
MessageBox. Show ("time is up! ");
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 button#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 =. toString (); textBox2.Text = B. toString (); textBox3.Text = ""; Count ++; textBox6.Text = Form1.Count. toString (); if (textBox7.Text = textBox6.Text) {MessageBox. show ("You have finished computing! ") ;}} Else {m = B. toString (); textBox2.Text =. toString (); textBox1.Text = m; textBox3.Text = ""; Count ++; textBox6.Text = Form1.Count. toString (); if (textBox7.Text = textBox6.Text) {MessageBox. show ("You have finished computing! ") ;}} 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 ("enter a number! "," Prompt "); 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 ("enter a number! "," Prompt "); 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 ("enter a number! "," Prompt "); textBox7.Clear () ;}} private void button5_Click (object sender, EventArgs e) {textBox1.Clear (); textBox2.Clear (); textBox3.Clear (); textBox4.Clear (); textBox5.Clear (); textBox7.Clear ();}}}

 

PsP time consumption

Conclusion: when I didn't see my partner complete a project, I suddenly felt that the hard work and hard work were worthwhile, especially when I saw my teammates smile, he should be very proud, but I will also feel very happy. Pair programming is the second time. It is a bit more tacit than the first time, and I hope to end up with Pair programming later.

Finally, I had a small request. I hope the teacher could prompt me how to implement the hybrid operation. It would be better if the teacher had an example !!!

 

 

 

 




--- Restore content end ---

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.