| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 530 人关注过本帖
标题:我的一个冗余程序
只看楼主 加入收藏
tty1960
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-10-16
收藏
 问题点数:0 回复次数:0 
我的一个冗余程序

using System; \\这是个出题的小程序.
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 算术题2
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 32);
this.label1.TabIndex = 0;
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(136, 16);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(128, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(392, 16);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 24);
this.button1.TabIndex = 2;
this.button1.Text = "确定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(464, 16);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(72, 24);
this.button2.TabIndex = 3;
this.button2.Text = "计分";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(328, 200);
this.label2.TabIndex = 4;
//
// button3
//
this.button3.Location = new System.Drawing.Point(304, 16);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(88, 24);
this.button3.TabIndex = 5;
this.button3.Text = "开始";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(392, 72);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(80, 64);
this.button4.TabIndex = 6;
this.button4.Text = "结束";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(544, 266);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.label2);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary///
///
public static int Num1,Num2;
public static string SExp;
public static int Result;
double NOk,NError;
public class ChuTi{
public string Chuti()
{
int NOp;
string Op="o";
string s;
Random random=new Random();
Num1=random.Next(1,10);
Num2=random.Next(1,10);
NOp=random.Next(1,4);
SExp="";
switch(NOp)
{
case 1:
{
Op="+";
Result=Num1+Num2;break;}
case 2:
{
Op="*";
Result=Num1*Num2;break;}
case 3:
{
Op="-";
Result=Num1-Num2;break;}
case 4:
{
Op="/";
Result=Num1/Num2;break;}
}
s=Num1.ToString();
SExp+=s;
SExp+=Op;
s=Num2.ToString();
SExp+=s;
SExp+="=";
return SExp;}
}
static void Main()
{ ChuTi b=new ChuTi();
b.Chuti();
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{

}

private void label1_Click(object sender, System.EventArgs e)
{

}

private void button1_Click(object sender, System.EventArgs e)
{
string s;
if(Convert.ToInt32(textBox1.Text)==Result)
{
label2.Text+=label1.Text;
label2.Text+=textBox1.Text;
label2.Text+=" T";
label2.Text+="\n";
NOk++;

}
else
{
label2.Text+=SExp;
label2.Text+=textBox1.Text;
label2.Text+=" F";
label2.Text+="\n";
NError++;
}
textBox1.Text="";
int NOp;          \\这块冗余,我想调用ChuTI方法,可是不行,能不能帮忙,简化一下.
string Op="o";
Random random=new Random();
Num1=random.Next(1,10);
Num2=random.Next(1,10);
NOp=random.Next(1,4);
SExp="";
switch(NOp)
{
case 1:
{
Op="+";
Result=Num1+Num2;break;}
case 2:
{
Op="*";
Result=Num1*Num2;break;}
case 3:
{
Op="-";
Result=Num1-Num2;break;}
case 4:
{
Op="/";
Result=Num1/Num2;break;}
}
s=Num1.ToString();
SExp+=s;
SExp+=Op;
s=Num2.ToString();
SExp+=s;
SExp+="=";
label1.Text=SExp;

}

private void button2_Click(object sender, System.EventArgs e)
{
double t=NOk+NError;
int f=Convert.ToInt32(NOk/(NOk+NError)*100);
f.ToString();
t.ToString();
label2.Text+="\n*************************"+"\n一共计算了"+t+"道题,得"+f+"分\n";
}

private void button3_Click(object sender, System.EventArgs e)
{
label1.Text=SExp;

}

private void button4_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}

搜索更多相关主题的帖子: 冗余 
2006-10-30 13:14
快速回复:我的一个冗余程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023313 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved