小学四则运算界面版
李永豪 201421123117 鄭靖濤 201421123114
coding 地址:https://git.coding.net/ras/work2.git
一、題目描述
我們在個人作業1中,用各種語言實現了一個命令行的四則運算小程序。進一步,本次要求把這個程序做成GUI(可以是Windows PC 上的,也可以是Mac、Linux,web,手機上的),成為一個有基本功能、一定價值的程序。在下面的功能需求中實現兩個:
二、題目要求
在兩人合作的過程中, 請看下面的內容
a. 滿足代碼風格規范和代碼設計規范(參考書第4章4.1-4.3內容)http://www.cnblogs.com/xinz/archive/2011/11/20/2255971.html
- 請重視這點,在開發時兩個人要有口頭上的溝通:“好的,我們一起在開發中遵守一起認可的編碼規范”
- 請把你們約定的編碼規范文檔也提交到git
c. 理解領航員和駕駛員兩種角色關系,并在結對編程中兩個人輪流做對方的角色。兩人都必須參與本次作業的編碼工作,并在git提交日志上體現這點。
三、功能分析
四、思維導圖
五、代碼分析
1.使用MFC實現GUI界面
2.點擊生成按鈕自動生成式子
void C第二周Dlg::OnBnClickedButton1() {CString num1;CString num2, result;CString oper;CString s1, s2;int b, c;char a;s1 = "正確答案";s2 = "判斷對錯";a = getopre();b = random(0, 20);c = random(1, 20);oper.Format(_T("%c"), a);num1.Format(_T("%d"), b);num2.Format(_T("%d"), c);switch (a){case '+': GetDlgItem(IDC_STA1)->SetWindowTextW(num1);GetDlgItem(IDC_STA2)->SetWindowTextW(oper);GetDlgItem(IDC_STA3)->SetWindowTextW(num2);break;case '-': GetDlgItem(IDC_STA1)->SetWindowTextW(num1);GetDlgItem(IDC_STA2)->SetWindowTextW(oper);GetDlgItem(IDC_STA3)->SetWindowTextW(num2);break;case '*': GetDlgItem(IDC_STA1)->SetWindowTextW(num1);GetDlgItem(IDC_STA2)->SetWindowTextW(oper);GetDlgItem(IDC_STA3)->SetWindowTextW(num2);break;case '/': b = c*b;num1.Format(_T("%d"), b);GetDlgItem(IDC_STA1)->SetWindowTextW(num1);GetDlgItem(IDC_STA2)->SetWindowTextW(oper);GetDlgItem(IDC_STA3)->SetWindowTextW(num2);break;}GetDlgItem(IDC_STA4)->SetWindowTextW(s1);GetDlgItem(IDC_STA5)->SetWindowTextW(s2);// TODO: 在此添加控件通知處理程序代碼 }3.點擊計算按鈕,計算出正確答案并顯示
void C第二周Dlg::OnBnClickedButton2() {CString num1, oper, num2,s1,s2,s3,s4,answer;int result;GetDlgItem(IDC_STA1)->GetWindowText(num1);GetDlgItem(IDC_STA2)->GetWindowText(oper);GetDlgItem(IDC_STA3)->GetWindowText(num2);int a = _tstoi(LPCTSTR(num1));int b = _tstoi(LPCTSTR(num2));s1 = "+";s2 = "-";s3 = "*";s4 = "/";if (oper == s1) {result = a + b;}else if (oper == s2) {result = a - b;}else if (oper == s3) {result = a*b;}else {result = a / b;}answer.Format(_T("%d"), result);GetDlgItem(IDC_STA4)->SetWindowTextW(answer);// TODO: 在此添加控件通知處理程序代碼 }4.輸入用戶計算結果后點擊檢驗按鈕,可以判斷對錯,并且記錄保存對錯數量
void C第二周Dlg::OnBnClickedButton5() {CString num1, oper, num2, s1, s2, s3, s4,s5,s6,s7, answer,key,rights,mistakes;int result,right,mistake,i=0,t=0;CString strline;CStdioFile File1;CStdioFile File2;File1.Open(_T("TRUE.txt"), CFile::modeReadWrite);File2.Open(_T("FALSE.txt"), CFile::modeReadWrite);while (File1.ReadString(strline))i++;while (File2.ReadString(strline))t++;rights.Format(_T("%d"), i);mistakes.Format(_T("%d"), t);GetDlgItem(IDC_STA1)->GetWindowText(num1);GetDlgItem(IDC_STA2)->GetWindowText(oper);GetDlgItem(IDC_STA3)->GetWindowText(num2);int a = _tstoi(LPCTSTR(num1));int b = _tstoi(LPCTSTR(num2));s1 = "+";s2 = "-";s3 = "*";s4 = "/";s5 = "true";s6 = "false";s7 = "恭喜";if (oper == s1) {result = a + b;}else if (oper == s2) {result = a - b;}else if (oper == s3) {result = a*b;}else {result = a / b;}answer.Format(_T("%d"), result);GetDlgItem(IDC_EDIT1)->GetWindowText(key);if (key == answer) {GetDlgItem(IDC_STA5)->SetWindowTextW(s5);GetDlgItem(IDC_STA4)->SetWindowTextW(s7);GetDlgItem(IDC_STA10)->SetWindowTextW(rights);File1.SeekToEnd();File1.WriteString(rights);File1.Write("\n", 1);}else {GetDlgItem(IDC_STA5)->SetWindowTextW(s6);GetDlgItem(IDC_STA4)->SetWindowTextW(answer);GetDlgItem(IDC_STA11)->SetWindowTextW(mistakes);File2.SeekToEnd();//文件尾部 File2.WriteString(mistakes);File2.Write("\n", 1);}File1.Close();File2.Close();// TODO: 在此添加控件通知處理程序代碼 }5.點擊開始按鈕開始計時,點擊暫停按鈕暫停計時
void C第二周Dlg::OnTimer(UINT_PTR nIDEvent) {// TODO: 在此添加消息處理程序代碼和/或調用默認值 CDialogEx::OnTimer(nIDEvent);static UINT mm = 0;static UINT ss = 0;static UINT mss = 0;CString str2;switch (nIDEvent){case 1:mss++;if (mss == 60) { mss = 0; ss++; }if (ss == 60) { ss = 0; mm++; }str2.Format(_T("%02i:%02i:%02i"), mm, ss, mss);m_time.SetWindowTextW(str2);break;} } void C第二周Dlg::OnStnClickedSta6() {// TODO: 在此添加控件通知處理程序代碼 } void C第二周Dlg::OnBnClickedButton4() {// TODO: 在此添加控件通知處理程序代碼SetTimer(1, 1000, NULL); }void C第二周Dlg::OnBnClickedButton7() {// TODO: 在此添加控件通知處理程序代碼KillTimer(1); }六、PSP展示
| PSP2.1 | Personal Software Process Stages | Time (%) Senior Student | Time (%) |
| Planning | 計劃 | 2h | 2.5h |
| · Estimate | 估計這個任務需要多少時間 | 36h | 41h |
| · Analysis | 需求分析 (包括學習新技術) | 1h | 2h |
| · Coding?Standard | 代碼規范 | 1h | 1h |
| · Design | 具體設計 | 2h | 3h |
| · Coding | 具體編碼 | 30h | 32h |
| · Test | 測試(自我測試,修改代碼,提交修改) | 1.5h | 2h |
| Reporting | 報告 | 1h | 1h ? |
?七、總結
第一次嘗試結對的方法進行編程,可以說是很不習慣的,因為從來編程都是一個人來完成的,兩個人本來是可以分開寫兩個不同的模塊,加快完成的速度,可是這樣有的時候自己的思路和同伴的思路不相符,還需要解釋,這樣大大拉長了完成的時間。可有利有弊,有一個人在旁邊復審,一段代碼經過兩雙眼睛,這樣減少了錯誤的發生,也可以集思廣益想出更多的解決方法。但是即便如此我還是比較習慣于自己寫代碼,因為有個人在旁邊看著讓我感覺很不習慣,而且每一次的編程都需要調節兩個人都有空的時間,感覺很麻煩。
?
轉載于:https://www.cnblogs.com/lyh117/p/6550323.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
- 上一篇: JAVA -Xms -Xmx -XX:P
- 下一篇: js闭包绑定元素