ImageVerifierCode 换一换
格式:DOCX , 页数:46 ,大小:30.97KB ,
资源ID:28308750      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/28308750.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C#课后参考答案.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

C#课后参考答案.docx

1、C#课后参考答案C#教程习题参考答案第一章(1) .NET Framework是平台,Visual Studio.NET是集成开发环境,C#是一种.NET平台下的开发语言(2) 易于掌握、支持跨平台、面向对象、与XML相融合(3) 组织资源、避免命名冲突(4) (5) 第二章上机练习(1) 输出结果为:(2) . (3) 使用Checked运算符可以抛出运算异常(4) Result:5050(5) 程序为:/*using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication1

2、 class Program static void Main(string args) string str = Console.ReadLine(); char ch = str.ToCharArray(); /字符串转换为字符数组 /输出转换结果 foreach(char c in ch) Console.WriteLine(0,c); /实现反转 char chtemp = str.ToCharArray(); int longs = ch.GetLength(0); for(int i = 0 ; i = longs-1 ; i+) chtempi = chlongs-i-1; /

3、/使用修改后的字符数组构造新字符串 string str2 = new string(chtemp); Console.WriteLine(str2); Console.ReadLine(); /*习题1、选择题(1) BD (2) D (3) ADE (4)ABC (5)ABD 2、填空题(1) -123 (2) delegate (3) 装箱 (4) n (5)堆内存 (6) 隐式转换和显式转换(7) ToCharArray(8) 编译错误:运算符“&”无法应用于“int”和“bool”类型的操作数; True;(9) ()3、简答题(1) 数据存放的位置与使用方式不同。(2) 装箱的过程

4、首先创建一个引用类型的实例,然后将值类型变量的内容复制给该引用类型实例.(3) 变量名必须以字母开头; 变量名只能由字母、数字和下划线组成,而不能包含空格、标点符号、运算符等其他符号; 变量名不能与C#中的关键字名称相同; 变量名不能与C#的库函数名称相同。(4) 小数类型较浮点类型而言,具有更大的精确度,但是数值范围相对小了很多。将浮点类型的数向小数类型的数转化时会产生溢出错误,将小数类型的数向浮点类型的数转化时会造成精确度的损失。因此,两种类型不存在隐式或显式转换。(5) 在需要实例化出一个引用类型的对象时使用。第三章上机练习(1) .(2) 六行杨辉三角(3) 五行杨辉三角(4) usi

5、ng System;class Test public static int max(int a, int b, int c, int d) int tempmax = a; if (tempmax b) tempmax = b; if (tempmax c) tempmax = c; if (tempmax b) tempmin = b; if (tempmin c) tempmin = c; if (tempmin d) tempmin = d; return tempmin; public static void Main() Console.WriteLine(Please input

6、 four number:); int x1 = Convert.ToInt32(Console.ReadLine(); int x2 = Convert.ToInt32(Console.ReadLine(); int x3 = Convert.ToInt32(Console.ReadLine(); int x4 = Convert.ToInt32(Console.ReadLine(); Console.WriteLine(The Max Number is :0, max(x1, x2, x3, x4); Console.WriteLine(The Min Number is :0, min

7、(x1, x2, x3, x4); Console.ReadLine(); (5) using System;class Test public static int addfor() int sum = 0; for(int i = 0 ; i = 50 ; i+ ) sum += i; return sum; public static int adddo() int sum = 0; int i = 0; do sum += i; i+; while (i = 50); return sum; public static int addwhile() int sum = 0; int i

8、 = 0; while (i = 50) sum += i; i+; return sum; public static void Main() Console.WriteLine(The Sum for is:0,addwhile(); Console.WriteLine(The Sum do is:0, addwhile(); Console.WriteLine(The Sum while is:0, addwhile(); Console.ReadLine(); 习题1、选择题(1) B (2) ACD (3) D (4) D (5) A 2、填空题(1) 顺序、分支、循环(2) bre

9、ak;reuturn;goto;continue(3) 3(4) 集合中元素的类型(5) 在C#语句和表达式的处理过程中激发了某个异常的条件,使得操作无法正常结束,引发异常、抛出异常3、简答题(1) 判断表达式一定要合法(2) 计算表达式的值;与分支进行匹配;执行分支语句;结束。(3) 提高程序的可读性和健壮性(4) Try块的代码是程序中可能出现错误的操作部分。Catch块的代码是用来处理各种错误的部分(可以有多个)。必须正确排列捕获异常的catch子句,范围小的Exception放在前面的catch。即如果Exception之间存在继承关系,就应把子类的Exception放在前面的catc

10、h子句中。Finally块的代码用来清理资源或执行要在try块末尾执行的其他操作(可以省略)。且无论是否产生异常,Finally块都会执行第四章上机练习(1) (2) using System;class MainClass public static void Main(string args) int sum = 0; int, , Score = 1, 2 , 3, 4 , 5,6 , 7,8 ; for (int i = 0; i 2; i+) for (int j = 0; j 2; j+) for (int k = 0; k 2; k+) sum += Scorei, j, k;

11、Console.WriteLine(The sum is :0, sum); Console.ReadLine(); (3)using System;class MainClass public static void Main(string args) int, arr = new int3, 3; int i, j, t, m=0, k=0, flag = 0; for(i = 0 ; i 3 ; i +) for(j=0 ; j 3 ; j +) arri,j = Convert.ToInt32(Console.ReadLine(); /* 求出每一行的最大值,并判断它是否为所在列的最小

12、值 */ for(i=0;i3;i+) t=arri,0; for(j=0;j3;j+) if(t=arri,j) t=arri,j; m=i; k=j; for(i=0;iarri,k) flag=1; /* 鞍点存在,查找是否有多个鞍点 */ if(flag=0) /* 找出鞍点个数并打印出来 */ for(j=0;j3;j+) if(arrm,j=arrm,k) /printf(the saddle point a%d%d= %dn,m,j,amj); Console.WriteLine(The saddle point a01=2n,m,j,arrm,j); else Console.

13、WriteLine(there are no saddle point); Console.ReadLine(); (4) using System;class MainClass public static void Main(string args) int, arr = new int3, 3; int sum = 0; for (int i = 0; i 3; i+) for (int j = 0; j 0) ai = b % 2; b /= 2; i+; j+; Console.WriteLine(The result is :); for (k = j - 1; k = 0; k-

14、) Console.WriteLine(0, ak); Console.ReadLine(); (6) using System;using System.Collections;using System.Collections.Generic;class friend string name=; string telephone=; string group=; public string Name get return name; set name = value; public string Telephone get return telephone; set telephone =

15、value; public string Group get return group; set group = value; public friend(string n,string t,string g) name = n; telephone = t; group = g; public friend(string n) name = n; telephone = ; group = ; public void Display() Console.WriteLine(-); Console.WriteLine(姓名:0n,this.Name); Console.WriteLine(电话

16、:0n,this.telephone); Console.WriteLine(组:0n,this.group); class telephonebook private ArrayList tele; public telephonebook() this.tele = new ArrayList(); public void Add(friend f) this.tele.Add(f); public void Delete(string na) friend temp=null; foreach (friend f in this.tele) if (friend)f).Name = na

17、) temp = f; if(temp != null) this.tele.Remove(temp); public void Edit(string na) string name, tele, group; Console.WriteLine(请输入修改后的名称:); name = Console.ReadLine(); Console.WriteLine(请输入修改后的电话:); tele = Console.ReadLine(); Console.WriteLine(请输入修改后的组:); group = Console.ReadLine(); this.Delete(na); fr

18、iend temp = new friend(name, tele, group); this.tele.Add(temp); public friend SearchByName(string na) foreach (friend f in this.tele) if (f.Name = na) return f; return null; public friend SearchByTele(string tel) foreach (friend f in this.tele) if (f.Telephone = tel) return f; return null; public vo

19、id display() foreach (friend f in this.tele) f.Display(); class MainClass public static void Main(string args) telephonebook tb = new telephonebook(); friend zangsan = new friend(zs, 123, jiaren); zangsan.Display(); tb.Add(zangsan); friend temp = tb.SearchByTele(123); if (temp != null) temp.Display(

20、); else Console.WriteLine(查无此人!); tb.display(); Console.ReadLine(); 习题1、选择题(1) D (2) C (3) A (4) ABC (5) C2、填空题(1) Sort() (2) 抛出异常、集合已修改;可能无法执行枚举操作。(3) 获取头部元素数据(4) Peek方法仅获取栈顶元素数据,Pop方法删除栈顶元素(5) 实现System.IEnumerable接口或实现集合模式(6) 名值对(7) SortedList中的Key数组排好序的第五章上机练习(1) (2) class student public string n

21、ame; private int age; private int heigh; private string grade; public student() this.name = ; this.age = 18; this.heigh = 180; this.grade = 0604; public student(string na, int a, int h, string g) this.grade = g; this.name = na; this.heigh = h; this.age = a; student() (3)using System;using System.Col

22、lections.Generic;class Employee private string name; private string ID; public static float TotalSalary; /定义实例构造函数,用来初始化实例中成员 public Employee() this.name = ; this.price = 0000; public Employee(string n,string i) this.name = n; this.ID = i; /定义静态构造函数 static Employee() TotalSalary = 0; /定义析构函数 Employe

23、e() public void printName() Console.WriteLine(this.name); (4)using System;using System.Collections.Generic;class Employee private string name; private string ID; public static float TotalSalary; private float Salary; /定义实例构造函数,用来初始化实例中成员 public Employee() this.name = ; this.ID = 0000; this.Salary =

24、0; public Employee(string n,string i,float s) this.name = n; this.ID = i; this.Salary =s; TotalSalary += this.Salary; /定义静态构造函数 static Employee() TotalSalary = 0; /定义析构函数 Employee() public void printName() Console.WriteLine(this.name); public static void DisplayTotalSalary() Console.WriteLine(总薪水为:0

25、,TotalSalary); (5) using System;using System.Collections.Generic;class Account private string ID; private string PSW; private string Name; private float Balance; public static float TotalBalance; /定义实例构造函数,用来初始化实例中成员 public Account(string i, string p, string n, float b) this.Balance = b; this.ID = i; this.Name = n; this.PSW = p; TotalBalance += this.Balance; s

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1