c#程序设计之画图小程序(5)

2019-03-03 11:55

} }

控制台程序,学生排序

namespace ch2Exe {

class Program {

static void Main(string[] args) {

String[,] Score = new String[5, 3];

Console.WriteLine(\请输入姓名,学号和C#课程的考试成绩(以回车键结束!):\); for (int i = 0; i < 5; i++) {

Console.WriteLine(\第{0}个学生:\, i); for (int j = 0; j < 3; j++) {

Score[i, j] = Console.ReadLine();

} }

//排序算法

for (int i = 0; i < 4; i++) {

for (int j = i+1; j < 5; j++) {

if(double.Parse ( Score [i,2])>=double.Parse ( Score [j,2])) {//交换两个成绩的位置,同时交换姓名和学号的位置 string temp;

for (int k = 0; k < 3; k++) {

temp = Score[i, k];

Score[i, k] = Score[j, k]; Score[j, k] = temp;

} }

} }

//输出结果

Console.WriteLine(\姓名 学号 课程的考试成绩\); for (int i = 0; i < 5; i++) {

for (int j = 0; j < 3; j++) {

Console.Write(Score[i, j]+\);

}

Console.WriteLine(\); }

Console.ReadKey(); }

} }

Using 命令

namespace 计算器 //本程序有很多重复啰唆的地方,以后有时间再改! {

public partial class Form1 : Form {

public double dblFirst = 0; public double dblSecond = 0; public bool blnFirstOpen = true; public bool blnClear = false; public string strOper; public Form1() {

InitializeComponent(); }

private void button0_Click_1(object sender, EventArgs e) {

if (sender == button0) append_num(0); }

private void button4_Click(object sender, EventArgs e) {

if (sender == button4) append_num(1); }

private void button8_Click(object sender, EventArgs e) {

if (sender == button8) append_num(2); }

private void button12_Click(object sender, EventArgs e) {

if (sender == button12) append_num(3); }

private void button3_Click(object sender, EventArgs e) {

if (sender == button3) append_num(4); }

private void button7_Click(object sender, EventArgs e) {

if (sender == button7) append_num(5); }

private void button11_Click(object sender, EventArgs e) {

if (sender == button11) append_num(6); }

private void button2_Click(object sender, EventArgs e) {

(计算器)

if (sender == button2) append_num(7); }

private void button6_Click(object sender, EventArgs e) {

if (sender == button6) append_num(8); }

private void button10_Click(object sender, EventArgs e) {

if (sender == button10) append_num(9); }

private void append_num(int i) {

if(blnClear) {

if(blnFirstOpen==true)

dblFirst=Convert.ToDouble(textBox1.Text); else

dblSecond=Convert.ToDouble(textBox1.Text); textBox1.Text=\; blnClear=false; }

if(((i==0)&&(textBox1.Text!=\))||(i!=0)) textBox1.Text=textBox1.Text+i.ToString(); }

private void btn_equ_Click_1(object sender, EventArgs e)//等号的处理 {

if (textBox1.Text != \)

if (blnFirstOpen == true)

dblFirst = Convert.ToDouble(textBox1.Text); else

dblSecond = Convert.ToDouble(textBox1.Text); switch (strOper) {

case \:

dblFirst += dblSecond; break; case \:

dblFirst -= dblSecond; break; case \:

dblFirst *= dblSecond; break; case \:

dblFirst /= dblSecond; break; }

strOper = \;

blnFirstOpen = false;

textBox1.Text = Convert.ToString(dblFirst); blnClear = true; }

private void btn_clear_Click(object sender, EventArgs e)//清空文本框 {

dblFirst = 0; dblSecond = 0;

blnFirstOpen = true; blnClear = false; textBox1.Text = \; textBox1.Focus(); }

private void btn_dot_Click_1(object sender, EventArgs e)//小数点的处理办法 {

if (textBox1.Text == \) textBox1.Text = \;

else if(textBox1.Text==\)

MessageBox.Show(\小数不能函数两个小数点!\); else

textBox1.Text = textBox1.Text + \; blnClear = false; }

private void btn_plus_Click_1(object sender, EventArgs e)//加法的实现函数 {

if (textBox1.Text != \)

if (blnFirstOpen == true)

dblFirst = Convert.ToDouble(textBox1.Text); else

dblSecond = Convert.ToDouble(textBox1.Text);

if (sender == btn_plus) strOper = \;

else if (sender == btn_minus) strOper = \; if (sender == btn_mul) strOper = \; if (sender == btn_div) strOper = \; blnFirstOpen = false;

textBox1.Text = Convert.ToString(dblFirst); blnClear = true; }

private void btn_minus_Click(object sender, EventArgs e)//减法的实现函数 {

if (textBox1.Text != \)

if (blnFirstOpen == true)

dblFirst = Convert.ToDouble(textBox1.Text); else

dblSecond = Convert.ToDouble(textBox1.Text);

if (sender == btn_plus) strOper = \;

else if (sender == btn_minus) strOper = \; if (sender == btn_mul) strOper = \; if (sender == btn_div) strOper = \; blnFirstOpen = false;

textBox1.Text = Convert.ToString(dblFirst); blnClear = true; }

private void btn_mul_Click(object sender, EventArgs e)//乘法的实现函数 {

if (textBox1.Text != \)

if (blnFirstOpen == true)

dblFirst = Convert.ToDouble(textBox1.Text); else

dblSecond = Convert.ToDouble(textBox1.Text);

if (sender == btn_plus) strOper = \;

else if (sender == btn_minus) strOper = \; if (sender == btn_mul) strOper = \; if (sender == btn_div) strOper = \; blnFirstOpen = false;

textBox1.Text = Convert.ToString(dblFirst); blnClear = true; }

private void btn_div_Click(object sender, EventArgs e)//除法的实现 {

if (textBox1.Text != \)

if (blnFirstOpen == true)

dblFirst = Convert.ToDouble(textBox1.Text); else

dblSecond = Convert.ToDouble(textBox1.Text);

if (sender == btn_plus) strOper = \;

else if (sender == btn_minus) strOper = \; if (sender == btn_mul) strOper = \; if (sender == btn_div) strOper = \; blnFirstOpen = false;

textBox1.Text = Convert.ToString(dblFirst); blnClear = true; }

} }

(显示)

private void XS_Click(object sender, EventArgs e)

{ //显示

SqlConnection cnn = new SqlConnection(); cnn.ConnectionString = cnntxt.Text; DataSet ds = new DataSet(); string sqlstr = sqltxt.Text;

SqlDataAdapter da = new SqlDataAdapter(sqlstr, cnn); da.Fill(ds, \);

dgw.DataSource = ds.Tables[\]; }


c#程序设计之画图小程序(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:拌合站安全、质量、环境、职业健康目标

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: