C#应用程序设计教程 第二版+课后习题答案_c

其他范文 时间:2020-02-27 15:47:33 收藏本文下载本文
【www.daodoc.com - 其他范文】

C#应用程序设计教程 第二版+课后习题答案由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“c”。

第一章

1.判断题

(1)×(2)√(3)√(4)×(5)×

(6)√ 2.选择题

(1)C(2)B(3)B(4)C(5)D

(6)C 3.编程题

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication1 { cla Program { static void Main(string[] args){ Console.WriteLine(“Hello C#”);} } }

第二章

1.判断下列符号哪些是合法的C#变量名称

北京 abc _xyz x_y 2.根据要求写出C#表达式(1)N%3==0 & N%5==0(2)(char)new Random().Next(67,74)(3)Math.Pow(x,3)*y/(x+y)(4)Math.Sqrt(b*b-4*a*c)3.判断题

(1)×(2)√(3)√(4)√(5)√

(6)×(7)√(8)√(9)√(10)×(11)√(12)× 4.选择题

(1)B(2)C(3)B(4)B

(5)C

(6)B(7)D(8)B(9)C(10)A 5.分析并写出下列程序运行结果(1)a=21,b=9,c=16

y=4(2)b=41(3)s=6(4)a[0]=28

a[1]=15

a[2]=39

a[3]=48

a[4]=39 6.程序填空

(1)① 3 ② a[i] ③ a[i] ④ a[5-i] ⑤ a[5-i](2)① i % 5 == 0 | i % 7 == 0 ② s+ i 7.编程题(1)static void Main(string[] args){ int s,i,j;for(i = 2;i

static void Main(string[] args){ int a = 20, b = 16,i=20;do { if(i % a == 0 & i % b == 0)break;i++;} while(true);Console.WriteLine(“最小公倍数:{0}”,i);i = 16;do { if(a % i == 0 & b % i == 0)break;i--;} while(true);Console.WriteLine(“最大公约数:{0}”,i);}(4)

static void Main(string[] args){ int i, j,k;float s = 1.0f;for(i = 2;i

static void Main(string[] args){ String s = “a,b2>4[AG6p(”;int i, n1=0,n2=0,n3=0,n4=0;for(i=0;i=65 & s[i]=97 & s[i]=48 & s[i]

static void Main(string[] args){ int i,s = 1;for(i = 0;i

说明:由最后一天往前推算。后一天吃了前一天桃子数量的一半多1个,剩余桃子数量是前一天桃子数量的一半减1,则,前一天的桃子数量是后一天的桃子数量加1的2倍。

第三章

1.判断题

(1)√(2)×(3)√

(4)√(5)√(6)×(7)√(8)×(9)×

(10)√

(11)√(12)√(13)√(14)×(15)√(16)√(17)×(18)√(19)√(20)×(21)×(22)√(23)√(24)√(25)×(26)×(27)× 2.选择题

(1)C(2)B(3)C(4)D

(5)C

(6)B(7)D(8)C(9)A(10)A(11)B(12)A(13)D(14)B

(15)C

3.分析下列程序的运行结果(1)s=32,s1=32,s2=34

x=11,y=21(2)x1=3,x2=4

y1=1,y2=4 4.编程题(1)

cla Student { public string studentid;public string studentname;private string birthplace;private DateTime birthdate;public Student(string id, string name){ studentid = id;studentname = name;} public string StudentId { get { return studentid;} set { studentid = value;} } public string StudentName { get { return studentname;} set { studentname = value;} } public string BirthPlace { get { return birthplace;} set { birthplace = value;} } public DateTime BirthDate { get { return birthdate;} set { birthdate = value;} } public int Age { get { return DateTime.Now.Year1, p1.yp1.x)*(p2.xp1.y)*(p2.yv2;if(radioButton3.Checked ==true)v = v1 * v2;if(radioButton4.Checked ==true){ if(v2!= 0)v = v1 / v2;} textBox3.Text = v.ToString();} 3.利用4.6节知识,参考图4-29设计具有菜单、工具栏和状态栏的Windows窗口应用程序。

第五章

1.判断题

(1)√(2)×(3)√(4)√(5)×

(6)√(7)×

2.选择题

(1)A(2)无答案,应该是TextReader(3)A(4)C

(5)A(6)C 3.编程题

创建Windows窗口用于程序,在窗口上放置一个Button控件,名称为button1,编写其Click事件处理方法:

private void button1_Click(object sender, EventArgs e){ int i, j;int[,] a=new int[3,3];int[,] b = new int[3, 3];int[,] c = new int[3, 3];string s1;string[];FileStream fs = new FileStream(@“d:data1.txt”,FileMode.Open);StreamReader sr=new StreamReader(fs,Encoding.Default);StreamWriter sw;BinaryWriter bw;for(i = 0;i

第六章

1.判断题

(1)√(2)×(3)×(4)×(5)√

(6)√(7)√(8)×(9)×(10)√

2.选择题

(1)C(2)D(3)C(4)A

(5)B(6)C(7)B(8)D 3.编程题

创建Windows窗口应用程序,在窗口上放置一个toolStrip控件,并在其中添加两个组合框,名称分别为toolStripComboBox1和toolStripComboBox2,给toolStripComboBox1添加选项:短划线、点划线、双点划线、虚线、实线,给toolStripComboBox2添加选项:1、2、3、4。给窗口添加如下私有字段:

private Graphics g1;private DashStyle dashstyle=DashStyle.Solid;private float penwidth=1;private Pen pen1;private bool beDraw = false;private Point p1, p2;编写comboBox1和comboBox2的SelectedIndexChanged事件处理方法:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e){ dashstyle =(DashStyle)comboBox1.SelectedIndex;}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e){ penwidth =float.Parse(comboBox2.Text);} 编写Form3的Load、MouseDown、MouseMove和MouseUp以及工具栏上两个组合框的SelectedIndexChanged事件处理方法:

private void Form3_Load(object sender, EventArgs e){ toolStripComboBox1.SelectedIndex = toolStripComboBox1.Items.Count-1;toolStripComboBox2.SelectedIndex = 0;} private void Form3_MouseDown(object sender, MouseEventArgs e){ pen1 = new Pen(Color.Red, penwidth);pen1.DashStyle = dashstyle;beDraw = true;p1 = e.Location;g1 = this.CreateGraphics();} private void Form3_MouseMove(object sender, MouseEventArgs e){ if(beDraw == true){ p2 = e.Location;g1.DrawLine(pen1, p1, p2);p1 = p2;} } private void Form3_MouseUp(object sender, MouseEventArgs e){ beDraw = false;} private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e){ dashstyle =(DashStyle)toolStripComboBox1.SelectedIndex;} private void toolStripComboBox2_SelectedIndexChanged(object sender, EventArgs e){ penwidth = float.Parse(toolStripComboBox2.Text);}

第七章

1.判断题

(1)√(2)×(3)×(4)×(5)√

(6)×(7)√(8)×(9)√(10)×(11)√(12)×(13)√(14)√(15)√(16)√

2.选择题

(1)A(2)D(3)C(4)A

(5)D(6)B(7)C(8)D(9)B(10)C(11)C 12)C 13)A 14)B 15)D 16)D 3.编程题

(1)创建Windows窗口应用程序,在窗口上放置两个Button控件,名称分别为button1和button2,再放置一个ComboBox控件和DataGridView控件,名称分别为comboBox1和dataGridView1。

编写button1的Click事件处理方法:

private void button1_Click(object sender, EventArgs e){ OleDbConnection con = new OleDbConnection();OleDbCommand com = new OleDbCommand();con.ConnectionString =@“Provider=microsoft.jet.oledb.4.0;data source=d:aaa.mdb”;con.Open();com.CommandType = CommandType.Text;com.CommandText = “select * from Score where score>80”;com.Connection = con;OleDbDataReader dr = com.ExecuteReader();comboBox1.Items.Clear();while(dr.Read()== true){ if(dr.IsDBNull(dr.GetOrdinal(“StudentID”))== false)

comboBox1.Items.Add(dr[“StudentID”]);} } 说明:为了使用ADO.NET的OLEDB访问方式,需要添加下列引用:

using System.Data.OleDb;(2)界面与(1)相同。

编写button2的Click事件处理方法:

private void button2_Click(object sender, EventArgs e){ OleDbConnection con = new OleDbConnection();OleDbCommand com = new OleDbCommand();con.ConnectionString = @“Provider=microsoft.jet.oledb.4.0;data source=d:aaa.mdb”;con.Open();OleDbDataAdapter da = new OleDbDataAdapter(“select Cla as 班级,avg(Score)as 平均成绩 from Score group by Cla”, con);DataSet ds = new DataSet();da.Fill(ds, “平均成绩表”);dataGridView1.DataSource =ds.Tables[“平均成绩表”];}(3)参考7.7节的学生信息管理程序,编写通讯录管理程序,细节略。

下载C#应用程序设计教程 第二版+课后习题答案word格式文档
下载C#应用程序设计教程 第二版+课后习题答案.doc
将本文档下载到自己电脑,方便修改和收藏。
点此处下载文档

文档为doc格式

相关专题 c 课后 习题 应用程序
    热门文章
      整站推荐
        点击下载本文