《最新C#操作题答案.doc》由会员分享,可在线阅读,更多相关《最新C#操作题答案.doc(106页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateC#操作题答案编写一个控制台应用程序,输入任意的10个整数,输出这10个数中的最大值和最小值。5. 编写一个控制台应用程序,输入任意的10个整数,输出这10个数中的最大值和最小值。static void Main(string args) Console.WriteLine(请输入任意的10个整数:); int input = new int10; for (int
2、i = 0; i 10; i+) inputi = Convert.ToInt32(Console.ReadLine(); int min = input0; int max = input9; foreach (int temp in input) if (max temp) min = temp; Console.WriteLine(最小值:); Console.WriteLine(min); Console.WriteLine(最大值:); Console.WriteLine(max); Console.ReadLine(); 编写一个控制台应用程序,要求输入X的值,计算下面分段函数的Y
3、的值。class Program static double Calculate(double x) double y; if(x 100) y = 10 * Math.Pow(x,3)+ 5*x*x+3*x+2; else if( x = -100 & x = 0; i-) Console.Write(stri); Console.Write(n); foreach (char c in str) if (char.IsDigit(c) len1+; else if (char.IsLower(c) len2+; else if (char.IsUpper(c) len3+; Console
4、.WriteLine(该字符串的数字有:+len1+,小写字母有:+len2+,大写字母有:+len3); Console.ReadKey(); 编写一个Windows应用程序,界面如下图所示,其中个的所得税、社保、房租和水电分别占工资的3%、4%、2%和1%。 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) float percent = 0; float sum; for (int i
5、= 1; i = 4; i+) switch (i) case 1: if (checkBox1.Checked = true) percent += 0.03f; break; case 2: if (checkBox2.Checked = true) percent += 0.04f; break; case 3: if (checkBox3.Checked = true) percent += 0.02f; break; case 4: if (checkBox4.Checked = true) percent += 0.01f; break; sum = (float.Parse(te
6、xtBox1.Text) * percent; textBox2.Text = sum.ToString(); 编写一个Windows应用程序,界面如下图所示,要求运行时左边列表框能出现100、200到1000之间的10个选项,并实现相应命令按钮的功能。namespace _3._5 public partial class Form1 : Form public Form1() InitializeComponent(); int arry = new int10; for (int i = 0; i 10; i+) arry0 = 100; arry1 = 200; arry2 = 300
7、; arry3 = 400; arry4 = 500; arry5 = 600; arry6 = 700; arry7 = 800; arry8 = 900; arry9 = 1000; for (int i = 0; i 10; i+) listBox1.Items.Add(arryi); private void button1_Click(object sender, EventArgs e) object Item = (object)textBox1.Text; listBox1.Items.Add(Item); private void listBox1_SelectedIndex
8、Changed(object sender, EventArgs e) private void button2_Click(object sender, EventArgs e) object SettleOnItem =listBox1.SelectedItem; if (listBox2.Items.Contains(SettleOnItem) MessageBox.Show(SettleOnItem.ToString()+已存在!,提示信息,MessageBoxButtons.OK,MessageBoxIcon.Warning); else listBox1.Items.Remove(
9、SettleOnItem); listBox2.Items.Add(SettleOnItem); private void button3_Click(object sender, EventArgs e) object SettleOnItem = listBox2.SelectedItem; if (listBox1.Items.Contains(SettleOnItem) MessageBox.Show(SettleOnItem.ToString() + 已存在!, 提示信息, MessageBoxButtons.OK, MessageBoxIcon.Warning); else lis
10、tBox2.Items.Remove(SettleOnItem); listBox1.Items.Add(SettleOnItem); private void button4_Click(object sender, EventArgs e) this.Dispose(); 要求在窗体界面中实现使用不保持连接的方式编写程序,并在各个文本框中分别显示表的当前记录的学生的学号,姓名,性别,成绩信息,并在相应的命令按钮中输入代码能实现显示第一条、上一条、下一条和最后一条记录的信息的功能。namespace _4._4 public partial class Form1 : Form DataSe
11、t data; OleDbDataAdapter adapter; int i = 0; public Form1() InitializeComponent(); string sqlstr = select * from score; string strPath = AppDomain.CurrentDomain.BaseDirectory + ./score.mdb; string str = Provider=Microsoft.Jet.OLEDB.4.0;Data Source= + strPath + ;Persist Security Info=False; OleDbConn
12、ection conn = new OleDbConnection(str); adapter = new OleDbDataAdapter(sqlstr, conn); OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter); data = new DataSet(); adapter.Fill(data, score); this.textBox1.Text = data.Tablesscore.Rowsi学号.ToString(); this.textBox2.Text = data.Tablesscore.Rowsi
13、姓名.ToString(); this.textBox3.Text = data.Tablesscore.Rowsi性别.ToString(); this.textBox4.Text = data.Tablesscore.Rowsi成绩.ToString(); label6.Text = (i + 1).ToString() + / + data.Tablesscore.Rows.Count; button1.Enabled = false; button2.Enabled = false; private void button2_Click(object sender, EventArgs
14、 e) button3.Enabled = true; button4.Enabled = true; i-; this.textBox1.Text = data.Tablesscore.Rowsi学号.ToString(); this.textBox2.Text = data.Tablesscore.Rowsi姓名.ToString(); this.textBox3.Text = data.Tablesscore.Rowsi性别.ToString(); this.textBox4.Text = data.Tablesscore.Rowsi成绩.ToString(); label6.Text
15、= (i + 1).ToString() + / + data.Tablesscore.Rows.Count; if (i = 0) button2.Enabled = false; button1.Enabled = false; private void button3_Click(object sender, EventArgs e) button2.Enabled = true; button1.Enabled = true; i+; this.textBox1.Text = data.Tablesscore.Rowsi学号.ToString(); this.textBox2.Text
16、 = data.Tablesscore.Rowsi姓名.ToString(); this.textBox3.Text = data.Tablesscore.Rowsi性别.ToString(); this.textBox4.Text = data.Tablesscore.Rowsi成绩.ToString(); label6.Text = (i + 1).ToString() + / + data.Tablesscore.Rows.Count; if (i = data.Tablesscore.Rows.Count - 1) button3.Enabled = false; button4.En
17、abled = false; private void button4_Click(object sender, EventArgs e) button1.Enabled = true; button2.Enabled = true; i = data.Tablesscore.Rows.Count - 1; this.textBox1.Text = data.Tablesscore.Rowsi学号.ToString(); this.textBox2.Text = data.Tablesscore.Rowsi姓名.ToString(); this.textBox3.Text = data.Tab
18、lesscore.Rowsi性别.ToString(); this.textBox4.Text = data.Tablesscore.Rowsi成绩.ToString(); label6.Text = (i + 1).ToString() + / + data.Tablesscore.Rows.Count; button3.Enabled = false; button4.Enabled = false; 使用保持连接的方式编写程序,查询符合应用程序界面所选的条件的SCORE数据库中的score表的学生的学号,姓名,性别,成绩,并将结果在列表框中显示出来,要求在列表框中首先显示表的所有字段信息
19、,排序字段选用学号。namespace _4._3 public partial class Form1 : Form public Form1() InitializeComponent(); button1.Enabled = false; boBox1.SelectedIndex = 0; boBox2.SelectedIndex = 0; listBox1.Items.Add( + 学号 + tt + 姓名 + t + 性别 + t + 成绩); listBox1.Items.Add( ); string sqlstr = select * from score where 成绩= 0
20、; i-) listBox1.Items.RemoveAt(i); string sqlstr; listBox1.Items.Add( + 学号 + tt + 姓名 + t + 性别 + t + 成绩); listBox1.Items.Add( ); if (radioButton1.Checked) sqlstr = select * from score where 成绩 + comboBox1.Text + + textBox1.Text + order by + comboBox2.Text + asc; else sqlstr = select * from score where
21、 成绩 + comboBox1.Text + + textBox1.Text + order by + comboBox2.Text + desc; string strPath = AppDomain.CurrentDomain.BaseDirectory + ./score.mdb; string str = Provider=Microsoft.Jet.OLEDB.4.0;Data Source= + strPath + ;Persist Security Info=False; OleDbConnection conn = new OleDbConnection(str); conn.
22、Open(); OleDbCommand command = new OleDbCommand(sqlstr, conn); OleDbDataReader dr1 = command.ExecuteReader(); while (dr1.Read() listBox1.Items.Add(dr10.ToString() + t + dr11.ToString() + t + dr12.ToString() + t + dr13.ToString(); conn.Close(); private void textBox1_TextChanged_1(object sender, Event
23、Args e) if (textBox1.Text = ) button1.Enabled = false; else button1.Enabled = true; 8.设计一个DNS解析的程序界面,输入一个网址,在列表框中显示出网站所在的所有IP地址,主机名和别名。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Win
24、dows.Forms;using System.Net;namespace _3 public partial class Form1 : Form public Form1() InitializeComponent(); private void textBox1_TextChanged(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e) listBox1.Items.Clear(); string name = textBox1.Text; IPHostEntry me =
25、Dns.Resolve(name); listBox1.Items.Add(me.HostName); foreach (IPAddress ip in me.AddressList) listBox1.Items.Add( ip.ToString(); for (int i = 0; i 255 | a2 255 | a3 255 | a4 255 | a5 255 | a6 255 | a7 255 | a8 255 | a9 255 | a10 255 | a11 255 | a12 255) MessageBox.Show(请输入正确的ip地址); Application.Exit(); a13 = byte.Parse(textBox13.Text); if (a13 = 8) b1 = Convert.ToByte(256 - Math.Pow(2, a13 % 8); b2 = 0;