一、程序設計題目要求和設計思想
1、題目
(1)、題目避免重復; (2)、可定制(數量/打印方式); (3)、可以控制下列參數: 是否有乘除法、是否有括號、 數值范圍、加減有無負數、除法有無余數、否支持分數 (真分數, 假分數, …)、是否支持小數 (精確到多少位)、打印中每行的間隔可調整;
2、設計思想
要求1:題目避免重復 設計思想:(1)通過srand(time(NULL));來控制。 要求2:可以定制(數量/打印方式) 設計思想:(1)定義一個參數,利用用戶輸入的數量來控制數量; 設計思想:(2)輸出格式可以目前可以設置兩個方式,一個方式是縱向X道,另一個是X*Y格式輸出,其中X、Y可以由用戶選擇來控制。 要求3:控制參數 設計思想:(1)所有的參數控制都要通過用戶來選擇,控制實現在主函數里,打印函數另行設計 設計思想:(2)數值范圍可以設置幾個輸出函數,用戶進行選擇 設計思想:(3)是否有乘除法,可以在輸出函數里控制,用戶進行選擇 設計思想:(4)加減有無負數可以用參數比較大小來實現 總體設計:程序里要涉及到很多條件判斷,一層一層的設計,先把在所有要求都滿足的情況下的結果輸出,然后在一步步的展開,一項一項的完成。
二、程序源代碼
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace sizeyunsuanqi 11 { 12 public partial class Form1 : Form 13 { 14 int shitishumu = 0; 15 int shuzhifanwei1 = 0; 16 int shuzhifanwei2 = 0; 17 string suoyoufuhao; 18 string fuhao; 19 string d; 20 21 public Form1() 22 { 23 InitializeComponent(); 24 } 25 PRivate void Form1_Load(object sender, EventArgs e)//通常初始化在Form1_Load事件中完成 26 { 27 richTextBox1.Clear(); 28 textBox1.Clear(); 29 } 30 private void button2_Click(object sender, EventArgs e)//button2(清除按鈕)的單擊事件:清除功能,清除已選擇選項內容 31 { 32 richTextBox1.Clear(); 33 textBox4.Text = ""; 34 textBox2.Text = ""; 35 textBox3.Text = ""; 36 checkBox3.Checked = false; 37 checkBox2.Checked = false; 38 checkBox1.Checked = false; 39 } 40 private void button1_Click(object sender, EventArgs e) //button2(確認按鈕)的單擊事件:單擊后,輸出題目 41 { 42 shitishumu = int.Parse(textBox4.Text);//用戶控制輸入試題數目 43 shuzhifanwei2 = int.Parse(textBox3.Text);//用戶控制輸入數值范圍(大) 44 shuzhifanwei1 = int.Parse(textBox2.Text);//用戶控制輸入數值范圍(?。?45 richTextBox1.Text += "尊敬的用戶您好,您的請求已經得到確認"+"/r/n"; 46 richTextBox1.Text += "您將打印 " + shitishumu + " 道題目" + "/r/n"; 47 richTextBox1.Text += "您打印試題的數值范圍是: " + shuzhifanwei1 + "-" + shuzhifanwei2 + "/r/n"; 48 if (checkBox3.Checked == true) 49 { 50 richTextBox1.Text += "試題輸出結果存在括號" + "/n"; 51 } 52 if (checkBox3.Checked == false) 53 { 54 richTextBox1.Text += "試題輸出結果不存在括號" + "/n"; 55 } 56 if (checkBox2.Checked == true) 57 { 58 richTextBox1.Text += "試題輸出結果中減法的結果存在負數" + "/n"; 59 } 60 if (checkBox2.Checked == false) 61 { 62 richTextBox1.Text += "試題輸出結果中減法的結果不存在負數" + "/n"; 63 } 64 if (checkBox1.Checked == true) 65 { 66 richTextBox1.Text += "試題輸出結果存在乘除法" + "/n"; 67 } 68 if (checkBox1.Checked == false) 69 { 70 richTextBox1.Text += "試題輸出結果不存在乘除法" + "/n"; 71 } 72 73 74 System.Random number = new Random(System.DateTime.Now.Millisecond); 75 //循環輸出題目 76 for (int i = 0; i < shitishumu; i++) 77 { 78 int num1 = number.Next(shuzhifanwei1, shuzhifanwei2); 79 int num2 = number.Next(shuzhifanwei1, shuzhifanwei2); 80 int num3 = number.Next(shuzhifanwei1, shuzhifanwei2); 81 int yunsuan1 = number.Next(0, 4); 82 int yunsuan2 = number.Next(0, 2); 83 int fuhaonum = number.Next(0, 2); 84 if (fuhaonum == 0)//符號進行隨機 85 { 86 fuhao = "+"; 87 }; 88 if (fuhaonum == 1) 89 { 90 fuhao = "-"; 91 }; 92 int suoyoufuhaonum = number.Next(0, 4); 93 if (suoyoufuhaonum == 0) 94 { 95 suoyoufuhao = "+"; 96 }; 97 if (suoyoufuhaonum == 1) 98 { 99 suoyoufuhao = "-";100 };101 if (suoyoufuhaonum == 2)102 {103 suoyoufuhao = "*";104 };105 if (suoyoufuhaonum == 3) 106 {107 suoyoufuhao = "/"; 108 };109 110 if (checkBox3.Checked == true)//有括號情況111 {112 textBox1.Text += num3;113 if (checkBox1.Checked == true)//有乘除法114 {115 if (checkBox2.Checked == true)//減法有負數116 {117 if (yunsuan1 == 0) { textBox1.Text += suoyoufuhao + "(" + num1 + "+" + num2 + ")" + "=" + "/r/n"; }118 else if (yunsuan1 == 1) { textBox1.Text += suoyoufuhao + "(" + num1 + "*" + num2 + ")" + "=" + "/r/n"; }119 else if (yunsuan1 == 2) { textBox1.Text += suoyoufuhao + "(" + num1 + "-" + num2 + ")" + "=" + "/r/n"; }//減法有負數120 else if (yunsuan1 == 3 && num2 != 0) { textBox1.Text += suoyoufuhao + "(" + num1 + "/" + num2 + ")" + "=" + "/r/n"; }//除法有余數121 }122 else if (checkBox2.Checked == false)//減法沒有負數123 {124 if (yunsuan1 == 0) { textBox1.Text += suoyoufuhao + "(" + num1 + "+" + num2 + ")" + "=" + "/r/n"; }125 else if (yunsuan1 == 1) { textBox1.Text += suoyoufuhao + "(" + num1 + "*" + num2 + ")" + "=" + "/r/n"; }126 else if (yunsuan1 == 2 && num1 > num2) { textBox1.Text += suoyoufuhao + "(" + num1 + "-" + num2 + ")" + "=" + "/r/n"; }//減法沒有負數127 else if (yunsuan1 == 2 && num1 <= num2) { textBox1.Text += suoyoufuhao + "(" + num2 + "-" + num1 + ")" + "=" + "/r/n"; }//減法沒有負數128 else if (yunsuan1 == 3 && num2 != 0) { textBox1.Text += suoyoufuhao + "(" + num1 + "/" + num2 + ")" + "=" + "/r/n"; }//除法有余數129 130 }131 }132 else if (checkBox1.Checked == false)//沒有乘除法133 {134 if (checkBox2.Checked == true)//減法有負數135 {136 if (yunsuan2 == 0) { textBox1.Text += fuhao + "(" + num1 + "+" + num2 + ")" + "=" + "/r/n"; }137 else if (yunsuan2 == 1) { textBox1.Text += fuhao + "(" + num1 + "-" + num2 + ")" + "=" + "/r/n"; }//減法有負數138 }139 else if (checkBox2.Checked == false)//減法沒有負數140 {141 if (yunsuan2 == 0) { textBox1.Text += fuhao + "(" + num1 + "+" + num2 + ")" + "=" + "/r/n"; }142 else if (yunsuan2 == 1 && num1 > num2) { textBox1.Text += fuhao + "(" + num1 + "-" + num2 + ")" + "=" + "/r/n"; }//減法沒有負數143 else if (yunsuan2 == 1 && num1 <= num2) { textBox1.Text += fuhao + "(" + num2 + "-" + num1 + ")" + "=" + "/r/n"; }//減法沒有負數144 }145 }146 147 }148 else if (checkBox3.Checked == false)//沒有括號149 {150 if (checkBox1.Checked == true)//有乘除法151 {152 if (checkBox2.Checked == true)//減法有負數153 {154 if (yunsuan1 == 0) { textBox1.Text += num1 + "+" + num2 +"=" + "/r/n"; }155 else if (yunsuan1 == 1) { textBox1.Text += num1 + "*" + num2 + "=" + "/r/n"; }156 else if (yunsuan1 == 2) { textBox1.Text +
新聞熱點
疑難解答