欢迎来到冰点文库! | 帮助中心 分享价值,成长自我!
冰点文库
全部分类
  • 临时分类>
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • ImageVerifierCode 换一换
    首页 冰点文库 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    实验内容和答案.docx

    • 资源ID:10036400       资源大小:19.83KB        全文页数:21页
    • 资源格式: DOCX        下载积分:3金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要3金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    实验内容和答案.docx

    1、实验内容和答案实验三1. 编程实现数组的属性和方法a) getLength()b) Rankc) Lengthd) Sort()e) Copy() class Sample public static void Main() string str1 = abcdasdasda; Console.WriteLine(1) str1 = 0, str1); Console.WriteLine(str1.Length); Console.WriteLine(Copy.); string str2= String.Copy(str1); Console.WriteLine(2) str2= 0, st

    2、r2; int, a = new int, 10, 11, 12 ,11,11,22; Console.WriteLine(a.Length); Console.WriteLine(a.GetLength(0); Console.WriteLine(a.Rank); Console.Read();2. 枚举类型题目class Program enum direction east = 1, north, south, west struct name public int number; public int distance; static void Main(string args) na

    3、me q; q.number = 0; q.distance = 0; Console.WriteLine(请输入方向); q.number = Convert.ToInt32(Console.ReadLine(); Console.WriteLine(请输入距离); q.distance = Convert.ToInt32(Console.ReadLine(); direction number = (direction)q.number; Console.WriteLine(您输入的方向是0,您输入的距离是1,number ,q.distance); Console.Read(); 3.

    4、编程实现:12+22+2002(实现过程中请使用foreach)class Program static void Main(string args) int p=new int200; int sum=0; for(int i=1;i=200;i+) pi-1=i*i; foreach (int i in p) sum +=i; Console.WriteLine(sum); Console.Read(); 4. 使用多维数组实现以下表格,统计每个系各个职称的平均教师人数,以及每个职称在各个系的平均教师人数。计算机英语中文思政教授4524讲师91089助教119710class Progra

    5、m static void Main(string args) int, sum = 4, 5, 2, 4 , 9, 10, 8, 9 , 11, 9, 7, 10 ; string coureses = 计算机, 英语, 中文, 思政 ; string teacher = 教授, 讲师, 助教 ; int s = 0; Console.WriteLine(各职称tt平均人数); for (int i = 0; i sum.GetLength(0); i+) s = 0; for (int j = 0; j sum.GetLength(1); j+) s += sumi, j; sole.Wr

    6、iteLine(0tt1,couresesi,s/sum.GetLength(1); Console.WriteLine(nn个系数tt平均人数 ); for (int i = 0; i sum.GetLength(1); i+) s = 0; for (int j = 0; j 0; i+) int a = Convert.ToInt16(Console.ReadLine(); if (a 0 & a 5) Console.WriteLine(请输入距离:); double b = Convert.ToDouble(Console.ReadLine(); t.x = (disrection)

    7、a; t.y = b; Console.WriteLine(您所在的方位是:0,距离为:1KM !, t.x, t.y); i = -1; else Console.WriteLine(请重新输入一个数:); Console.ReadKey(); 2. 试试看:随机产生5个数,求其中最大值。(提示:Random number = new Random(); number.Next()产生下一个数)class Program static void Main(string args) int s = new int5;/s数组中存放着需要的数字 Random number = new Rando

    8、m(); for (int i = 0; i 5; i+)/遍历数组显示结果 si = number.Next(); Console.WriteLine(si); int max = s0; for (int i = 1; i = max) max = si; Console.WriteLine(max); Console.ReadKey(); 3. 求一个3阶数字矩阵对角线的和,数字矩阵如下:1 2 34 5 67 8 9要求先显示这个矩阵,然后再显示结果,此例结果应该为25. class Program static void Main(string args) int i, j,sum=

    9、0; int, a = 1, 2, 3 , 4, 5, 6 , 7, 8, 9 ; for ( i=0;i3;i+) for (j = 0; j 3; j+) Console.Write(0, ai, j); Console.Write( ); Console .Write (n); for (int z = 0; z 3; z+) sum = sum +az,z; sum = sum + a0, 2; sum = sum + a2, 0; Console.WriteLine(0,sum); Console.ReadKey(); 实验六1. 定义两个整型变量i=1,j=2,通过调用swap(i

    10、nt x,int y)来交换这两个变量的值,使得在主函数中输出交换后的值:i=2,j=1.class swap public int i; public int j; public swap(int x, int y) j = x; i = y; public string Display() return String.Format(i=0,j=1, i, j); class Program static void Main(string args) swap swaps = new swap(1, 2); Console.WriteLine(swaps.Display(); Console

    11、.ReadKey(); 2. 定义一个数组 sores = 95, 98, 89, 69, 100, 78, 60, 68, 49 ,通过调用MaxMinScore(int s)这个方法返回数组中的最大值和最小值,并在主函数中输出。 class sores public void MaxMinScore(int s, out int max , out int min ) max=s0; min=s0; for(int i=1;is.Length;i+) if (maxsi) min=si; class Program static void Main(string args) int sor

    12、es = 95, 98, 89, 69, 100, 78, 60, 68, 49 ; sores a=new sores( ); int m, n; a.MaxMinScore(sores, out m, out n); Console.WriteLine(最高分为0, m); Console.WriteLine(最低分为0, n); Console.ReadKey(); 3. 已知整型数组a= 1, 2, 3 ;要求调用函数F(),输出a的长度以及a中的各个元素,当整型数组变为b=10,20,30,40,再次调用函数F(),输出b的长度以及b中的各个元素.(params运用)class Pr

    13、ogram public static void F(params int args) Console.WriteLine(个数:0, args.Length); foreach (int i in args) Console.Write( 0, i); Console.WriteLine(); Console.ReadKey(); static void Main() int a = 1, 2, 3 ; F(a); F(10, 20, 30, 40); 4. 使用索引器初始化MyClass类中的public string FriendName = new string4这个字段以及输出这个数

    14、组里的每一个元素。class Program static void Main(string args) Test t = new Test(); t0 = 小红; t1 = 小黑; t2 = 小绿; t3 = 小桃; for (int i = 0; i 4; i+) Console.WriteLine(ti); class Test public string myData = new string4; public string thisint index get return myDataindex; set myDataindex = value; class MyClass publ

    15、ic string FriendName = new string4; public string thisint n get return FriendNamen; set FriendNamen = value; 试一试:试编程实现使用非整数下标访问索引器,在主函数中赋值如下:ttsom = 1234;并在控制台输出这个值。实验七1. 编写代码,定义一个基类MyClass,其中包含虚拟方法GetString().这个方法应返回存储在受保护字段myString中的字符串,该字段可以通过只写公共属性ContainedString来初始化。(初始化请通过控制台由用户来输入)2. 从类MyClas

    16、s中派生一个类MyDerivedClass.重写GetString()方法,使用该方法的基类执行代码从基类中返回一个字符串,但在返回的字符串中添加文本”output from derived class”.class Program static void Main(string args) MyDerivedClass cc = new MyDerivedClass(); MyClass ss = cc; ss.ContainedString = Console.ReadLine(); Console.WriteLine(ss.GetString(); Console.Read(); cla

    17、ss MyClass protected string myString; public virtual string GetString() return myString; public string ContainedString set myString = value; class MyDerivedClass : MyClass public override string GetString() return base.GetString() + (out put from derived class); 3. 利用多态性计算圆和三角形的面积以及周长。(半径、底以及高的值都通过实

    18、例化派生类的同时来指定)class Program static void Main(string args) Circle cc = new Circle(1); Shape ss = cc; Console.WriteLine(圆面积:0,ss.GetArea(); Console.WriteLine(圆周长:0,ss.GetPerimeter(); Cmj ff = new Cmj(1,3); Smj mj = ff; Console.WriteLine(三角形面积:0,mj.Getmj(); Czc zz = new Czc(1,2,3); Szc zc = zz; Console.W

    19、riteLine(三角形周长:0,zc.Getzc(); Console.ReadKey(); class Shape protected double radius; public Shape(double r) radius = r; public virtual double GetArea() return 0; public virtual double GetPerimeter() return 0; public virtual string Type get return Shape; public string Display() return String.Format(T

    20、ype, GetArea(), GetPerimeter(); class Circle:Shape public Circle(double r) : base(r) public override double GetArea() return Math.PI * radius * radius; public override double GetPerimeter() return Math.PI * radius * 2; public override string Type get return 圆;class Smj protected double dd, hh; publi

    21、c Smj(double d, double h) dd = d; hh = h; public virtual double Getmj() return 0; public virtual double Getzc() return 0; public virtual string Type get return Smj; public string Display() return String.Format(Type, Getmj(); class Cmj : Smj public Cmj(double d,double h):base(d,h) public override dou

    22、ble Getmj() return dd * hh / 2; public override string Type get return 三角形;class Szc protected double aa, bb, cc; public Szc(double a, double b, double c) aa = a; bb = b; cc = c; public virtual double Getzc() return 0; public virtual string Type get return Smj; public string Display() return String.

    23、Format(Type, Getzc(); class Czc : Szc public Czc(double a, double b, double c): base(a, b, c) public override double Getzc() return aa+bb +cc; public override string Type get return 三角周长;4. 利用抽象方法和抽象类编程实现圆和正方形的面积。(半径、长、宽的值通过实例化派生类的同时来指定)实验八1. 试着编程实现使用接口实现多态性:车辆有很多种,有自行车、三轮车、吉普车,当是自行车时,能够知道它有二个轮子,当是三

    24、轮车时能够知道它有三个轮子,而当是吉普车时,有四个轮子。class Program public static void Main() cheliang cl = new bicyle(); cl.wheel(); cl = new sanluan(); cl.wheel(); cl = new jeep(); cl.wheel(); Console.ReadKey(); interface cheliang void wheel(); class bicyle:cheliang public void wheel() Console.WriteLine(this is two wheels)

    25、; class sanluan : cheliang public void wheel() Console.WriteLine(this is three wheels); class jeep : cheliang public void wheel() Console.WriteLine(this is four wheels); 2. 定义一个泛型类栈Stack,包含四个成员:一个私有的数组items,一个pop方法,一个push方法实现进栈、出栈,一个构造函数,用来对数组items的大小进行初始化。接着在主函数中进行调用,第一次压栈:4,8,然后分别出栈,第二次压栈“aa”,”bb”

    26、,然后分别出栈。class Program public static void Main() Stack stack = new Stack(100); stack.Push(2); stack.Push(4); Console.WriteLine(stack.Pop(); Console.WriteLine(stack.Pop(); Stack stack2 = new Stack(100); stack2.Push(aa); stack2.Push(bb); Console.WriteLine(stack2.Pop(); Console.WriteLine(stack2.Pop(); Conso


    注意事项

    本文(实验内容和答案.docx)为本站会员主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2023 冰点文库 网站版权所有

    经营许可证编号:鄂ICP备19020893号-2


    收起
    展开