Second assignment: arithmetic

Source: Internet
Author: User

Requirements Analysis :

Write a "software" program that can arithmetic the integers (randomly generated) between the 0--10 to receive the integer answer of the user input, and judge the number of correct and wrong answers when the wrong program ends.

Design ideas:

I'm using a Windows Forms application that has 3 form forms,

Set 3 TextBox controls in Form1, representing random numbers and output results, two label controls, representing operators and "=", and 7 button controls representing "+ 、-、 *,/, start, description, End";

FORM2 4 Label controls, 4 TextBox controls, representing "Total answer, correct number, error number, and correct rate";

Form3

Code:

Form1 Code:

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceArithmetic { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }         Public Static intCount =0;  Public Static intright =0; Private voidButton1_Click (Objectsender, EventArgs e)        {Randomnum (); }        Private voidRandomnum () {random random=NewRandom (); intNumber1, number2; Number1= Random. Next (1, One); Number2= Random. Next (1, One); TextBox1.Text=Number1.            ToString (); TextBox2.Text=number2.            ToString (); TextBox3.Text=""; Count++; }        Private voidTextbox3_keydown (Objectsender, KeyEventArgs e) {            intsum; stringn=Label1.            Text; Switch(n) { Case "+": Sum=int. Parse (TextBox1.Text) +int.                    Parse (TextBox2.Text);  Break;  Case "-": Sum=int. Parse (TextBox1.Text)-int.                    Parse (TextBox2.Text);  Break;  Case "*": Sum=int. Parse (TextBox1.Text) *int.                    Parse (TextBox2.Text);  Break; default: Sum=int. Parse (TextBox1.Text)/int.                    Parse (TextBox2.Text);  Break; }            if(E.keycode = =keys.enter) {if(TextBox3.Text = =sum. ToString ()) right++;            Randomnum (); }        }        Private voidButton2_Click (Objectsender, EventArgs e) {textbox3.enabled=true; Form2 Frm2=NewForm2 (); Frm2.                   ShowDialog (); }        Private voidButton3_Click (Objectsender, EventArgs e) {Label1. Text="+"; }        Private voidButton4_Click (Objectsender, EventArgs e) {Label1. Text="-"; }        Private voidButton5_click (Objectsender, EventArgs e) {Label1. Text="*"; }        Private voidButton6_click (Objectsender, EventArgs e) {Label1. Text="/"; }        Private voidButton7_click (Objectsender, EventArgs e) {            NewForm3 ().        Show (); }    }}

Form2 Code:

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceArithmetic { Public Partial classForm2:form { PublicForm2 () {InitializeComponent (); }        Private voidForm2_load (Objectsender, EventArgs e) {TextBox1.Text=Form1.Count.ToString (); TextBox2.Text=Form1.right.ToString (); TextBox3.Text= (Form1.count-(Double) (Form1.right)).            ToString (); Textbox4.text= ((Form1.right/(Double) (Form1.count)) * -). ToString () +"%"; }    }}

Operation Result:

PSP Time-consuming analysis:

Summarize:

This is the first time in the case of the book is not according to the design of the program, see the topic requirements after the feeling that they will not do, and later found that the previous homework and this similar, I modeled a few, but there are some places do not understand, after consulting others to solve. But the results of the operation found that because the program automatically generated next, there is always a wrong, can not solve the hope that the teacher can help!

Second assignment: arithmetic

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.