天津理工大学C#试验一.doc

上传人:豆**** 文档编号:33454832 上传时间:2022-08-11 格式:DOC 页数:12 大小:330.50KB
返回 下载 相关 举报
天津理工大学C#试验一.doc_第1页
第1页 / 共12页
天津理工大学C#试验一.doc_第2页
第2页 / 共12页
点击查看更多>>
资源描述

《天津理工大学C#试验一.doc》由会员分享,可在线阅读,更多相关《天津理工大学C#试验一.doc(12页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、精品文档,仅供学习与交流,如有侵权请联系网站删除实验报告 学院(系)名称:计算机科学与工程学院姓名*学号*专业计算机科学与技术班级2015级 班实验项目实验一:C#的数据类型和控制结构课程名称. NET程序设计课程代码0667066实验时间2017年3月30日 12:45-15:45实验地点7-215批改意见成绩教师签字: 一、 实验目的(1) 熟悉Visual Studio 2010开发环境,掌握C#数据类型;(2) 掌握分支语句、循环语句、跳转语句及异常处理语句;(3) 掌握数组的使用;(4) 掌握面向对象的编程思想:类、接口等的使用;(5) 字符串的常用方法。二、 实验环境n 开发环境:

2、PC机,Windows 7操作系统;n 开发工具:Visual Studio 2010以上。三、 实验要求(1) 认真完成实验内容,编写程序代码;(2) 要求所有程序有测试数据,并输出实验的正确结果;(3) 书写并提交实验报告。四、 实验内容(将代码与运行结果展示在此)1、using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 实验1.1 class Program static void Main(string args) Console.WriteLine(第一?

3、个?C#程序!?!?); Console.ReadLine(); 2、using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 实验1.2 class Program static void Main(string args) int a = 345; float b = 15.3f; bool c = true; char d = t; string e = 12345; Console.WriteLine(int a = + a); Console.WriteLin

4、e(float b = + b); Console.WriteLine(bool c = + c); Console.WriteLine(char d = + d); Console.WriteLine(string e = + e); /转a换? Console.WriteLine(n类型转a换?n); Console.WriteLine(n整?型转a化为a长整?型:on); long l = a; Console.WriteLine(long l = a = + l); Console.WriteLine(n字?符?串?转a化为a整?型:oParse()n); int transform

5、= int.Parse(e); Console.WriteLine(int transform = e = + transform); Console.WriteLine(n字?符?型转a化为a整?型:on); char h = r; int chartoint = h; Console.WriteLine(r的?ASCLL码?为a:o + chartoint); /Convert Console.WriteLine(nConvert类:四?舍六入?五?取?偶?); Console.WriteLine(10.4 = + Convert.ToInt32(10.4); Console.WriteL

6、ine(10.6 = + Convert.ToInt32(10.6); Console.WriteLine(10.5 = + Convert.ToInt32(10.5); Console.WriteLine(11.5 = + Convert.ToInt32(11.5); /显?式?转a换? Console.WriteLine(显?式?转a换?:o浮?点?型-整?型); double d1 = 10.4, d2 = 10.5, d3 = 10.6; Console.WriteLine(10.4 = + (int)d1); Console.WriteLine(10.5 = + (int)d2);

7、Console.WriteLine(10.6 = + (int)d3); 3、using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 实验1._3 class Program public static void swamp(ref int x,ref int y) int temp = x; x = y; y = temp; static void Main(string args) int i = 1; int sum1 = 0; while (i = 100)

8、sum1 += i; i+; Console.WriteLine(1-100所有D整?数y和为a: + sum1); int j = 0; int sum2 = 0; while (j 100) j+; if (j % 2 = 0) continue; sum2 += j; Console.WriteLine(1-100所有D奇?数y和为a:o + sum2); Console.WriteLine(nnswitch()算?成绩); int Grade = int.Parse(Console.ReadLine(); int gg = (int)(Grade / 10); switch (gg)

9、case 10: case 9: Console.WriteLine(优?秀?); break; case 8: Console.WriteLine(良?好?); break; case 7: Console.WriteLine(中D等); break; case 6: Console.WriteLine(及格?); break; default: Console.WriteLine(不?及格?); break; Console.WriteLine(nntry-catch-finally:); int bDiv = int.Parse(Console.ReadLine(); int Div =

10、 int.Parse(Console.ReadLine(); int result = 0; try result = bDiv / Div; Console.WriteLine(result); catch (Exception ex) Console.WriteLine(0不?能做?除y数y!? + ex); Console.WriteLine(nn引y用?类型:o); Console.WriteLine(1、数y组引y用?); int arr = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ;

11、 Console.WriteLine(处|理之?前的?数y组:o); for (int m = 0; m arr.Length; m+) Console.Write(arrm + ); for (int k = 0; k arr.Length; k+) if (arrk % 7 = 0) arrk = 0; Console.WriteLine(n处|理之?后的?数y组为a:o); for (int n = 0; n arr.Length; n+) Console.Write(arrn + ); Console.WriteLine(n2、ref引y用?:o); int a = 13; int b

12、 = 18; Console.WriteLine(a = + a + ,b = + b); Console.WriteLine(引y用?交?换?a和b的?值:o); swamp(ref a, ref b); Console.WriteLine(交?换?后:oa = + a + ,b = + b); 4、using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 实验1._4 class MainClass public interface Body float area(

13、); class Cube : Body public Cube(float x1) a = x1; public float a; void setA(float x) a = x; public float area() return 6 * a * a; class Ball : Body public Ball(float r1) r = r1; float r; void setR(int r1) r = r1; public float area() return (float)(4 * 3.14 * r * r); public static float getArea(Body

14、 b) return b.area(); static void Main(string args) Cube c1 = new Cube(2); Ball b1 = new Ball(3); Console.WriteLine(Cube.area = + getArea(c1); Console.WriteLine(Ball.area = + getArea(b1); 5、using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 试?验1._5 class Progr

15、am public static int add(int a, int b) return a + b; public static int add(int a, int b,int c) return a + b + c; public static float add(float a, float b) return a + b; public static double add(double a, double b) return a + b; static void Main(string args) int i = 1; int j = 2; int k = 3; float m =

16、 2.5f; float n = 3.7f; double r = 5.0569; double s = 8.2365; Console.WriteLine(0,add(i, j); Console.WriteLine(0, add(i, j,k); Console.WriteLine(0, add(m, n); Console.WriteLine(0, add(r, s); 6、using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 实验1._6 class Pro

17、gram static void Main(string args) /Contains string s = 葫芦?娃T,?葫芦?娃T,?一?根藤上?七?朵?花; bool b = s.Contains(葫芦?娃T); Console.WriteLine(b); bool c = s.Contains();/空?字?符?串?也2返回?True Console.WriteLine(c); bool d = s.Contains(哪?吒?); Console.WriteLine(d); /Split string data = 2017-4-16; string t = data.Split(-

18、); foreach(string str in t) Console.WriteLine(str); /join string time = string.Join(/,t); Console.WriteLine(time); string s1 = 猴?哥?,; string s2 = 你?真?了?不?得?; Console.WriteLine(string.Concat(s1, s1, s2); /IndexOf Console.WriteLine(data.IndexOf(4); /Copy string s3 = 天苍?苍?,?野茫茫,?风?吹草Y低见?牛羊; string d4 =

19、 string.Copy(s3); Console.WriteLine(d4); /Clone string s4 = 猴?哥?,?猴?哥?,?你?真?了?不?得?; object s5 = s4.Clone(); Console.WriteLine(s5.ToString(); 五、 心得体会自从上了大学也学了几门计算机语言了,感觉基础操作大同小异。C#前几章的内容和其他语言也没太大差别,其中的一些方法记住就好了。只不过时间久了不用会忘掉,拿起来看看就会了。C#的过人之处应该就是后边几章吧,记得之前学前端,各种界面都是用代码画出来的,C#中只要添加各种元素就好了,真的好方便。虽然是一门选修,但是老师讲的特别好,希望跟着老师能学到点东西,以后不会丢老师的脸,不丢理工的脸。六、【精品文档】第 12 页

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 小学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com