日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

结对编程项目---四则运算

發(fā)布時(shí)間:2025/3/15 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 结对编程项目---四则运算 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

同組人:郝哲 黃云龍

評(píng)價(jià):在這次作業(yè)完成中我們都積極地查詢(xún)了有關(guān)資料,并向大神咨詢(xún)獲得了幫助,學(xué)習(xí)的過(guò)程中更更加深入的了解了C#的編寫(xiě)。

感謝:感謝同組同學(xué)的幫助,感謝大神的輔導(dǎo),感謝百度貼吧大神的講解。

//事件響應(yīng)

using?System;

using?System.Collections.Generic;

using?System.ComponentModel;

using?System.Data;

using?System.Drawing;

using?System.Linq;

using?System.Text;

using?System.Threading.Tasks;

using?System.Windows.Forms;

?

namespace?WindowsFormsApplication1

{

?

????public?partial?class?Form1?:?Form

????{??

????????private?int?a=0,b=0;//數(shù)據(jù)

????????private?string?op;//運(yùn)算符

????????private?int?result;///結(jié)果

????????private?Random?rd?=?new?Random();///隨機(jī)數(shù)

????????

????????public?Form1()

????????{

????????????InitializeComponent();

????????}

?

????????private?void?buttonQeustion_Click(object?sender,?EventArgs?e)

????????{?

?

????????????int?c?=?0;?

????????????c=rd.Next(4);

????????????a=rd.Next(9);

????????????b?=?rd.Next(9);

???????????/*while?(c!=0|c!=2){

????????????????if?(c?==?1)

????????????????{

????????????????????c?=?rd.Next(4);

????????????????}

????????????????else?if(b==0){

????????????????????b?=?rd.Next(9);

????????????????}

????????????}*/

???????????

????????????switch(c){

????????????????case?0:?op?=?"+";?result?=?a?+?b;?break;

????????????????case?1:?op?=?"-";?if?(a?>=?b)?//去除a-b小于0的情況

????????????????????????????????????{

????????????????????????????????????????result?=?a?-?b;

????????????????????????????????????}

????????????????????????????????????else

????????????????????????????????????{

????????????????????????????????????????a?+=?rd.Next(9,10);

????????????????????????????????????????result?=?a?-?b;

????????????????????????????????????};break;

????????????????case?2:?op?=?"*";?result?=?a?*?b;?break;

????????????????case?3:?op?=?"/";?if?(b?!=?0)///分母為零的情況

????????????????????????????????????{?

????????????????????????????????????????result?=?a?/?b;

????????????????????????????????????}

????????????????????????????????????else?

????????????????????????????????????{?

????????????????????????????????????????b?=?a;

????????????????????????????????????????result?=?a?/?b;

????????????????????????????????????};??break;

?

????????????}

????????????labela.Text?=?a.ToString();

????????????labelb.Text?=?b.ToString();

????????????labelop.Text?=?op;

????????????textAnswer.Text?=?"";

?

????????}

?

????????private?void?buttonJudge_Click(object?sender,?EventArgs?e)

????????{

????????????string?stringAnswer?=?textAnswer.Text;

????????????double?resultAnswer?=?double.Parse(stringAnswer);

????????????string?showStar?=?""?+?a?+?op?+?b?+?"="?+?stringAnswer;

????????????if?(textAnswer.Text?!=?"")

????????????{

????????????????if?(resultAnswer?==?result)

????????????????{

????????????????????showStar?+=?"???????*";

?

????????????????}

????????????????else

????????????????{

????????????????????showStar?+=?"???????X";

?

????????????????}

????????????}

????????????else?{?

?????????????????

?????????????????textAnswer.Text="答案欄目不能為空";

?????????????????return;

????????????}

????????????listBox1.Items.Add(showStar);

?

?

????????}

?

????????private?void?buttonClose_Click(object?sender,?EventArgs?e)

????????{

???????????Close();

????????}

?

???????

?

????}

}

?

/控件定義及其設(shè)置

?

namespace?WindowsFormsApplication1

{

????partial?class?Form1

????{

????????///?<summary>

????????///?必需的設(shè)計(jì)器變量。

????????///?</summary>

????????private?System.ComponentModel.IContainer?components?=?null;

?

????????///?<summary>

????????///?清理所有正在使用的資源。

????????///?</summary>

????????///?<param?name="disposing">如果應(yīng)釋放托管資源,為?true;否則為?false</param>

????????protected?override?void?Dispose(bool?disposing)

????????{

????????????if?(disposing?&&?(components?!=?null))

????????????{

????????????????components.Dispose();

????????????}

????????????base.Dispose(disposing);

????????}

?

????????#region?Windows?窗體設(shè)計(jì)器生成的代碼

?

????????///?<summary>

????????///?設(shè)計(jì)器支持所需的方法?-?不要

????????///?使用代碼編輯器修改此方法的內(nèi)容。

????????///?</summary>

????????private?void?InitializeComponent()

????????{

????????????this.labela?=?new?System.Windows.Forms.Label();

????????????this.labelop?=?new?System.Windows.Forms.Label();

????????????this.labelb?=?new?System.Windows.Forms.Label();

????????????this.buttonQeustion?=?new?System.Windows.Forms.Button();

????????????this.buttonJudge?=?new?System.Windows.Forms.Button();

????????????this.listBox1?=?new?System.Windows.Forms.ListBox();

????????????this.buttonClose?=?new?System.Windows.Forms.Button();

????????????this.textAnswer?=?new?System.Windows.Forms.TextBox();

????????????this.equals?=?new?System.Windows.Forms.Label();

????????????this.SuspendLayout();

????????????//?

????????????//?labela

????????????//?

????????????this.labela.AutoSize?=?true;

????????????this.labela.Location?=?new?System.Drawing.Point(40,?23);

????????????this.labela.Name?=?"labela";

????????????this.labela.Size?=?new?System.Drawing.Size(0,?12);

????????????this.labela.TabIndex?=?1;

????????????//?

????????????//?labelop

????????????//?

????????????this.labelop.AutoSize?=?true;

????????????this.labelop.Location?=?new?System.Drawing.Point(90,?25);

????????????this.labelop.Name?=?"labelop";

????????????this.labelop.Size?=?new?System.Drawing.Size(0,?12);

????????????this.labelop.TabIndex?=?2;

????????????//?

????????????//?labelb

????????????//?

????????????this.labelb.AutoSize?=?true;

????????????this.labelb.Location?=?new?System.Drawing.Point(139,?23);

????????????this.labelb.Name?=?"labelb";

????????????this.labelb.Size?=?new?System.Drawing.Size(47,?12);

????????????this.labelb.TabIndex?=?3;

????????????this.labelb.Text?=?"???????";

????????????//?

????????????//?buttonQeustion

????????????//?

????????????this.buttonQeustion.Location?=?new?System.Drawing.Point(38,?92);

????????????this.buttonQeustion.Name?=?"buttonQeustion";

????????????this.buttonQeustion.Size?=?new?System.Drawing.Size(75,?23);

????????????this.buttonQeustion.TabIndex?=?6;

????????????this.buttonQeustion.Text?=?"出題";

????????????this.buttonQeustion.UseVisualStyleBackColor?=?true;

????????????this.buttonQeustion.Click?+=?new?System.EventHandler(this.buttonQeustion_Click);

????????????//?

????????????//?buttonJudge

????????????//?

????????????this.buttonJudge.Location?=?new?System.Drawing.Point(154,?92);

????????????this.buttonJudge.Name?=?"buttonJudge";

????????????this.buttonJudge.Size?=?new?System.Drawing.Size(75,?23);

????????????this.buttonJudge.TabIndex?=?7;

????????????this.buttonJudge.Text?=?"判定";

????????????this.buttonJudge.UseVisualStyleBackColor?=?true;

????????????this.buttonJudge.Click?+=?new?System.EventHandler(this.buttonJudge_Click);

????????????//?

????????????//?listBox1

????????????//?

????????????this.listBox1.FormattingEnabled?=?true;

????????????this.listBox1.ItemHeight?=?12;

????????????this.listBox1.Location?=?new?System.Drawing.Point(38,?137);

????????????this.listBox1.Name?=?"listBox1";

????????????this.listBox1.Size?=?new?System.Drawing.Size(271,?112);

????????????this.listBox1.TabIndex?=?8;

????????????//?

????????????//?buttonClose

????????????//?

????????????this.buttonClose.Location?=?new?System.Drawing.Point(276,?91);

????????????this.buttonClose.Name?=?"buttonClose";

????????????this.buttonClose.Size?=?new?System.Drawing.Size(75,?23);

????????????this.buttonClose.TabIndex?=?9;

????????????this.buttonClose.Text?=?"關(guān)閉";

????????????this.buttonClose.UseVisualStyleBackColor?=?true;

????????????this.buttonClose.Click?+=?new?System.EventHandler(this.buttonClose_Click);

????????????//?

????????????//?textAnswer

????????????//?

????????????this.textAnswer.Location?=?new?System.Drawing.Point(254,?19);

????????????this.textAnswer.Name?=?"textAnswer";

????????????this.textAnswer.Size?=?new?System.Drawing.Size(100,?21);

????????????this.textAnswer.TabIndex?=?10;

????????????//?

????????????//?equals

????????????//?

????????????this.equals.AutoSize?=?true;

????????????this.equals.Location?=?new?System.Drawing.Point(200,?25);

????????????this.equals.Name?=?"equals";

????????????this.equals.Size?=?new?System.Drawing.Size(11,?12);

????????????this.equals.TabIndex?=?11;

????????????this.equals.Text?=?"=";

????????????//?

????????????//?Form1

????????????//?

????????????this.AutoScaleDimensions?=?new?System.Drawing.SizeF(6F,?12F);

????????????this.AutoScaleMode?=?System.Windows.Forms.AutoScaleMode.Font;

????????????this.ClientSize?=?new?System.Drawing.Size(393,?261);

????????????this.Controls.Add(this.equals);

????????????this.Controls.Add(this.textAnswer);

????????????this.Controls.Add(this.buttonClose);

????????????this.Controls.Add(this.listBox1);

????????????this.Controls.Add(this.buttonJudge);

????????????this.Controls.Add(this.buttonQeustion);

????????????this.Controls.Add(this.labelb);

????????????this.Controls.Add(this.labelop);

????????????this.Controls.Add(this.labela);

????????????this.Name?=?"Form1";

????????????this.Text?=?"小學(xué)四則運(yùn)算訓(xùn)練";

????????????this.ResumeLayout(false);

????????????this.PerformLayout();

?

????????}

?

????????#endregion

?

?????

????????private?System.Windows.Forms.Label?labela;

????????private?System.Windows.Forms.Label?labelop;

????????private?System.Windows.Forms.Label?labelb;

????

????????private?System.Windows.Forms.Button?buttonQeustion;

????????private?System.Windows.Forms.Button?buttonJudge;

????????private?System.Windows.Forms.ListBox?listBox1;

????????private?System.Windows.Forms.Button?buttonClose;

????????private?System.Windows.Forms.TextBox?textAnswer;

????????private?System.Windows.Forms.Label?equals;

????}

}

?

?

//主程序?

?

?

?

using?System;

using?System.Collections.Generic;

using?System.Linq;

using?System.Threading.Tasks;

using?System.Windows.Forms;

?

namespace?WindowsFormsApplication1

{

????static?class?Program

????{

????????///?<summary>

????????///?應(yīng)用程序的主入口點(diǎn)。

????????///?</summary>

????????[STAThread]

????????static?void?Main()

????????{

????????????Application.EnableVisualStyles();

????????????Application.SetCompatibleTextRenderingDefault(false);

????????????Application.Run(new?Form1());

????????}

????}

}

?

?

運(yùn)行效果圖

轉(zhuǎn)載于:https://www.cnblogs.com/HAOZHE/p/5357952.html

總結(jié)

以上是生活随笔為你收集整理的结对编程项目---四则运算的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。