User requirements:

Requirements to prepare a 0-10 between the integer for four operations, the program can receive input integer answers, and judge right and wrong, at the end of the program, the statistics of the answer, the number of wrong questions! Integers from 0 to 10 are randomly generated, and the user can select one of four operations using keyboard input. For example, if you type 1 for addition, the user uses the keyboard to enter a character to end the program and display it! Count the results!

 

Design idea:

1. Since I’m writing an integer between 0 and 10, I’ll define three variables of type int, two to hold the integer and one to hold the final result. If (){}… if(){}… Else {} to determine. 3, the end of the program requires counting the number of correct and wrong answers, so define two variables of int type to store the number, and use “increment” to achieve each count. 4. 0-10 is Random, so I use Random() to generate it. Since it is used to perform four operations, I declare four operations. 6, use the keyboard to select one of the operations, you can use switch(){case: break; } to make a choice.

Specific code implementation:

1, This is used to display the menu bar, we can select ‘1’ ‘2’ ‘3’… Wait to decide which algorithm to use! \

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _Random { class Program { static void Main(string[] args) { mathvoid op = new mathvoid(); string Z = ""; Do {Console. WriteLine (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - arithmetic -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "); Console.WriteLine(""); Console.WriteLine(" Please select the operation you use :1. Addition 2. subtraction 3. multiplication 4. division 5. quit!" ); Z = Console.ReadLine(); switch (Z) { case "1": op.mathjia(); continue; case "2": op.mathjian(); continue; case "3": op.mathcheng(); continue; case "4": op.mathchu(); continue; case "5": op.result(); break; Default: Console.WriteLine(" Input invalid!" ); continue; } break; } while (true); }}}Copy the code

 

2, this is the method used to call!

 

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _Random { public class mathvoid { public static int right = 0; // Record the total number of correct answers! public static int wrong = 0; // Record the total number of wrong answers! Public void mathJia () // Add! { int a, b; int result; Random rd = new Random(); a = rd.Next(0, 11); b = rd.Next(0, 11); Console.WriteLine(" Please calculate: {0}+{1}=?" , a, b); result = Convert.ToInt32(Console.ReadLine()); If (result == a + b) {Console. ); right++; } else {console. WriteLine(" Error, keep trying!" ); wrong++; }} public void mathjian(); { int a, b; int result; Random rd = new Random(); a = rd.Next(0, 11); b = rd.Next(0, 11); Console.WriteLine(" Please calculate: {0}-{1}=?" , a, b); result = Convert.ToInt32(Console.ReadLine()); If (result == a-b) {Console.WriteLine(" answer right!" ); right++; } else {console. WriteLine(" Error, keep trying!" ); wrong++; }} public void mathcheng(); { int a, b; int result; Random rd = new Random(); a = rd.Next(0, 11); b = rd.Next(0, 11); Console.WriteLine(" Please calculate: {0}*{1}=?" , a, b); result = Convert.ToInt32(Console.ReadLine()); If (result == a * b) {Console. ); right++; } else {console. WriteLine(" Error, keep trying!" ); wrong++; }} public void mathchu(); { int a, b; int result; Random rd = new Random(); a = rd.Next(0, 11); b = rd.Next(0, 11); if (b ! = 0) {console. WriteLine(" Please calculate: {0}/{1}=?" , a, b); result = Convert.ToInt32(Console.ReadLine()); If (result == a/b) {Console.WriteLine(" answer correct! ); right++; } else {console. WriteLine(" Error, keep trying!" ); wrong++; } } else { if (a ! = 0) {console. WriteLine(" Please calculate: {0}/{1}=?" , b, a); result = Convert.ToInt32(Console.ReadLine()); If (result == b/a) {Console.WriteLine(" answer correct! ); right++; } else {console. WriteLine(" Error, keep trying!" ); wrong++; }}}} public void result() // Statistics result! {Console.WriteLine(" Total {0} questions: you got {1} questions right and got {2} questions wrong." ,right+wrong,right,wrong); }}}Copy the code

 

3. The last one is the running console!

 

PSP Time analysis:

1. First of all, I predicted that it would take me 12 hours to complete the task, but it actually took me about 9 hours. 3. Generating design documents: When I first received this assignment, I drew a rough sketch on paper of what methods were needed and what was needed. The plan took about 20 minutes to draw up a rough sketch. 4, design review: carefully check, feel that do not need to put aside the first place, the first time did not think of plus to go. This is an idea that will change! 5, code specification: this is easy to browse the whole structure frame body, not too much time 10 minutes or so. 6. Specific design: it takes about 1 hour! 7, specific coding: this is the most time-consuming, because you have to keep changing, every time there is a mistake to carefully check the specific reason for the error. That’s how you solve the problem! And where exactly the methods should be called and what should be put is coded according to your original plan. There are also occasional changes. When a mistake is not passed, it takes a long time to solve it! It takes about 4.5 hours. 8. Code review: This one is ok. Go through it carefully and take about 20 minutes. 9. Testing: Because only testing can know where there are deficiencies, it took me some time to make changes. It took over an hour!

Conclusion:

When receiving a project, take a general look at what the client is looking for! Make an estimate of how long it will take, as a standard for yourself.

Then according to the specific needs of customers, to carry out careful analysis. Probably need to use what method, column a scheme, generate design document! Then according to their own design ideas to code, code writing may have new ideas, it is flexible. What the customer needs, we do. If you have a new idea and you want to add new features to your customers, I think it’s best not to do it, because it’s a waste of time and energy, and it can cause unnecessary trouble. All we need to do is fulfill the customer’s requirements.



My question:

In the division method, it produces something like 9/7=? In this case, the task is to ask the user to accept integer results, so 9/7=1, which is the correct answer. But in real life, it does not accord with our habits! If I set result to double, what should I do?

 

Consider:

How the program should handle extensibility if the user requests processing in a range of 0-100.

Rd = new Random(); a = rd.Next(0, 101); b = rd.Next(0, 101); Additional questions:

The program can handle incorrect user input, such as a decimal or a character

A: In switch() {case:}, I added default, if the input is not the switch character, will say: “input invalid!”