C#基础编程设计实验报告_第1页
C#基础编程设计实验报告_第2页
C#基础编程设计实验报告_第3页
C#基础编程设计实验报告_第4页
已阅读5页,还剩37页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、本文格式为word版,下载可任意编辑c#基础编程设计实验报告 c# 基础编程 设计试验报告 一、试验目的 1、熟识 visual studio .net 开发环境。 2、把握 c#应用程序的基本操作过程。 3、把握 c#的数据类型,运算符以及表达式的使用。 4、把握分支和循环语句的使用方法。 5、把握一维数组,二维数组及数组型数组的使用。 二、试验要求 (1)编写程序要规范、正确,上机调试过程和结果要有记录 (2)做完试验后给出本试验的试验报告。 三、试验设备、环境 安装有 visual studio .net 软件。 四、试验步骤 1、分析题意。 2、依据题目要求,新建项目。 3、编写并输入

2、相关的程序代码。 5、运行与调试项目。 6、保存项目。 五、试验内容 1、编写一个简洁的掌握台应用程序,打印一行文字(如你的姓名)。 using system; using system.collections.generic; using system.linq; using system.text; namespace one.first class program static void main(string args) system.console.writeline(quot;我叫王蕾!quot;); 2、编写一个简洁的 windows 应用程序,在窗体 load 大事中书写代码,

3、标签中显示你的姓名。 using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; namespace one.second public partial class form1 : form public form1() initializecomponent(); private void

4、 form1_load(object sender, eventargs e) this.text = quot;windows 程序quot; label lblshow = new label(); lblshow.location = new point(20, 30); lblshow.autosize = true; lblshow.text = quot;王蕾!quot; this.controls.add(lblshow); 3、编写一个一个程序,用来推断输入的是大写字母,小写字母,数字还是其他的字符。 using system; using system.collections

5、.generic; using system.text; namespace one.third class program static void main(string args) console.writeline(quot;请输入一个字符:quot;); char c = convert.tochar(console.readline(); if (cgt;="a"amp;amp;clt;="z")|(cgt;="a"amp;amp;clt;="z") console.writeline(quot;这是一个

6、字母quot;); if (char.isdigit(c) console .writeline(quot;这是一个数字quot;); 4、分别用 while,do-while,for 循环求 1 到 100 的和。 using system; using system.collections.generic; using system.text; namespace one.forth.one class program static void main(string args) int i = 1, sum = 0; while (i lt;= 100) sum = sum + i; i+

7、; console.writeline(quot;1 到 100 的自然数之和为:quot; + sum); using system; using system.collections.generic; using system.text; namespace one.forth.two class program static void main(string args) int i = 1, sum = 0; do sum = sum + i; i+; while (i lt;= 100); console .writeline(quot;1 到 100 的自然数的和为:quot; +

8、sum ); using system; using system.collections.generic; using system.text; namespace one.forth.three class program static void main(string args) int i , sum = 0; for (i = 1; i lt;= 100; i+) sum = sum + i; console.writeline(quot;1 到 100 的自然数的和为:quot; + sum); 5、定义一个一维数组,用随机数为此赋值,用 foreach 循环输 出其中的内容。 u

9、sing system; using system.collections.generic; using system.linq; using system.text; namespace first.five class program static void main(string args) int a = 0,1,2,3,4; foreach (int i in a) console.writeline(ai); 6、实现二维数组的输入和输出。 using system; using system.collections.generic; using system.linq; usin

10、g system.text; namespace first.six class program static void main(string args) int, a = new int2, 3 1, 2, 3 , 4, 5, 6 ; for (int i = 0; i lt; 2; i+) for (int j = 0; j lt; 3; j+) console.writeline(ai, j); 7、实现数组型数组的输入和输出。 using system; using system.collections.generic; using system.linq; using system

11、.text; namespace first.seven class program static void main(string args) int a = new int new int 1, 2, 3 , new int 4, 5, 6 ; for (int i = 0; i lt; a.length; i+) for (int j = 0; j lt; ai.length; j+) console.writeline(aij); 六、试验体会(遇到问题及解决方法,编程后的心得体会) 刚开头编程的时候觉得无从下手,尽管我们已经学了好几种高级编程语言,但每个都有其独特的地方,稍不留神就会

12、混淆。 通过这次试验,我体会到课后复习巩固的重要性。在编程的时候,许多内容都不记得,需要去翻书。不得不说,试验是巩固课程的好方法!本次试验,我熟识 visual studio .net 开发环境;把握了 c#应用程序的基本操作过程;把握了 c#的数据类型,运算符以及表达式的使用;把握了分支和循环语句的使用方法以及一维数组,二维数组及数组型数组的使用。 试验项目名称: 类与对象 试验学时: 6 同组同学姓名: 试验地点: 1318 试验日期: 10 月 26 日-11 月 9 日 试验成果: 批改老师: 批改时间: 试验 2 类与对象 一、试验目的、要求 (1)把握类的定义和使用; (2)把握类

13、的数据成员,属性的定义和使用; (3)把握方法的定义,调用和重载以及方法参数的传递; (4)把握构造函数的定义和使用。 二、试验要求 (1)编写程序要规范、正确,上机调试过程和结果要有记录; (2)做完试验后给出本试验的试验报告。 三、试验设备、环境 安装有 visual studio .net 软件。 四、试验步骤 1、分析题意; 2、依据题目要求,新建项目; 3、编写并输入相关的程序代码; 5、运行与调试项目; 6、保存项目。 五、试验内容 1、定义一个方法,实现两个数的交换(分别把参数按值传递和按引用传递)。 using system; using system.collections.

14、generic; using system.text; namespace second.one class program static void main(string args) swaper s = new swaper(); console.writeline(quot;输入 x 的值:quot;); int a = convert.toint32(console.readline(); console.writeline(quot;输入 y 的值:quot;); int b=convert.toint32(console.readline(); console.writeline(

15、s.swap(a, b); console.writeline(s.swap(ref a,ref b); class swaper public string swap(int x, int y) int temp; temp = x; x = y; y = temp; return string.format(quot;按值传参交换之后:x=0,y=1quot;,x,y); public string swap(ref int x, ref int y) int temp; temp = x; x = y; y = temp; return string.format(quot;按引用传参交

16、换之后:x=0,y=1quot;, x, y); 2、定义一个方法,实现数组的排序。 using system; using system.collections.generic; using system.text; namespace second.two class program public class sort public void change(int a) console.writeline(quot;排序前,数组挨次为:quot;); show(a); int i, j, m; for (i = 0; i lt; 10; i+) m = ai; j = i - 1; /aj

17、为数组前一个值 while (j gt;= 0 amp;amp; m gt; aj)/推断 i 下标的数是否大于 j 下标的数 aj + 1 = aj;/假如 i 下标大于j 把 j 往后移一个位 j-; aj+1 = m; /当不大于 j 的时候就把 m的值放到 i 下标下面 j+1 是为了下标减到最前时考虑 -1 + 1 还是下标的最前面 console.writeline(quot;排序后,数组挨次为:quot;); show(a); void show(int a) int i; for (i = 0; i lt; 10; i+) console.write(quot;0 quot;,

18、 ai); console.writeline(); static void main(string args) int a = 4, 7, 1, 2, 5, 8, 9, 10, 3, 6 ; sort s=new sort(); s.change(a); 3、定义一个同学类,把同学类当作对象来传递。 using system; using system.collections.generic; using system.linq; using system.text; namespace second.three class program public class student publ

19、ic void st() int a = 999; public class st public void aa(student s) console.writeline(s); static void main(string args) student s=new student(); st s1 = new st(); s1.aa(s); 4、定义一个方法,求两个数的和和差,通过参数把这两个值带回。 using system; using system.collections.generic; using system.linq; using system.text; namespace

20、second.four class program public class sum public void ab(out int m, out int n,int a, int b) m = a + b; n = a - b; static void main(string args) sum s = new sum(); int a = 10; int b = 3; int m, n; s.ab(out m, out n, a, b); console.writeline(quot;0+1=2;0- 1=3quot;,a,b,m,n); 5、用构造函数重载,实现矩形的面积,圆的面积,梯形的

21、面积; using system; using system.collections.generic; using system.linq; using system.text; namespace secong.five class program public class square public double area; public square() public square(double a) area = a * a * 3.14; public square(double a, double b) area = a * b; public square(double a, d

22、ouble b, double h) area = (a + b) / 2 * h; static void main(string args) double a, b, h,area; a = 2; b = 5; h = 3; square s = new square(a,b); console.writeline(quot;求矩形面积,长为 a=0,宽为 b=1,面积 area=2quot;,a,b,s.area); square i = new square(a); console.writeline(quot;求圆形面积,半径 a=0,面积 area=1quot;, a, i.are

23、a); square j = new square(a, b, h); console.writeline(quot;求梯形面积,上底为a=0,下底为 b=1,高为 h=2面积 area=3quot;, a, b,h, j.area); 6、设计一个 windows 应用程序,在该程序中定义一个同学类和班级类,以处理每个同学的学号,姓名,语文,数学和英语成果,要求: 1)能查询每个同学的总成果。 2)能显示全班前三名的.。 3)能显示单科成果最高分和不及格的同学.。 4)能统计全班同学的平均成果。 5)能显示各科成果不同分数段的同学人数的百分比。 student 类: using system

24、; using system.collections.generic; using system.text; namespace test2_6 public class student public string stuno; public string name; public double chinese; public double math; public double english; public double sumscore get return chinese + math + english; studentlist 类: using system; using syst

25、em.collections.generic; using system.text; namespace test2_6 public class studentlist:student int snums; public student stu=new student50; public studentlist() snums = 0; public void addstu(student s) stusnums = s; snums+; public int searchstu(string name) int i; for (i = 0; i lt; snums; i+) if (stu

26、 = name) break; if (i = snums) return -1; else return i; /给全部成果排序,用后面实现前三名的排名 public void prothree() for (int i = 0; i lt; snums; i+) int k = i; for (int j = i + 1; j lt; snums; j+) if (stuj.sumscore gt; stuk.sumscore) k = j; if (k != i) student temp; temp = stuk; stuk = stui; stui = temp; /显示

27、单科成果的最高分 public int highscore(int k) int p = 0; if (k = 0) for (int i = 1; i lt; snums; i+) if (stui.math gt; stup.math) p = i; else if (k = 1) for (int i = 1; i lt; snums; i+) if (stui.chinese gt; stup.chinese) p = i; else for (int i = 1; i lt; snums; i+) if (stui.chinese gt; stup.chinese) p = i; r

28、eturn p; /显示不及格. public string buhgname(int k) string name=quot; quot; if (k = 0) for (int i = 0; i lt; snums; i+) if (stui.math lt; 60) name +=+quot;nquot; else if (k = 1) for (int i = 0; i lt; snums; i+) if (stui.chinese lt; 60) name += + quot;nquot; else for (int i = 0; i lt; s

29、nums; i+) if (stui.english lt; 60) name += + quot;nquot; return name; public string gethl() string maxer = quot; quot;, loser = quot; quot; maxer += quot; 单 科 数 学 最 高 : quot; + stuhighscore(0).name + quot;nquot; maxer += quot; 单 科 语 文 最 高 : quot; + stuhighscore(1).name + quot;nquot; maxer

30、+= quot; 单 科 英 语 最 高 : quot; + stuhighscore(2).name + quot;nquot; loser += quot;单科数学挂科.:quot; +buhgname(0) + quot;nquot; loser += quot;单科语文挂科.:quot; + buhgname(1) + quot;nquot; loser += quot;单科英语挂科.:quot; + buhgname(2) + quot;nquot; return maxer + quot;nquot; + loser; /全班的平均成果 public string sumscore

31、() double sum = 0; double avg=0; for (int i = 0; i lt; snums; i+) sum = sum + stui.sumscore; avg = sum / snums; return quot;班级总分平均分:quot;+avg; /各科成果不同分数段的同学百分比 /英语成果各分数段百分比 public string perc() double per1, per2, per3, per4, per5; double sumc1 = 0, sumc2 = 0, sumc3 = 0, sumc4 = 0, sumc5 = 0; for (in

32、t i = 0; i lt; snums; i+) if (stui.chinese gt; 90) amp;amp; (stui.chinese lt;= 100) sumc1+; else if (80 lt;= stui.chinese) amp;amp; (stui.chinese lt; 90) sumc2+; else if(70lt;=stui.chinese)amp;amp; (stui.chinese lt; 80) sumc3+; else if(60lt;=stui.chinese)amp;amp;(stui.chinese lt; 70) sumc4+; else su

33、mc5+; per1 = sumc1 / snums; per2 = sumc2 / snums; per3 = sumc3 / snums; per4 = sumc4 / snums; per5 = sumc5 / snums; return quot; 语 文 成 绩 百 分 比 :quot;+quot;nquot;+quot;90100:quot;+per1+quot; 8090:quot;+per2+quot; 8070:quot;+per3+quot; 7060:quot;+per4+quot; 60 以下的:quot;+per5; /数学成果各分数段百分比 public strin

34、g perm() double per1, per2, per3, per4, per5; double sumc1 = 0, sumc2 = 0, sumc3 = 0, sumc4 = 0, sumc5 = 0; for (int i = 0; i lt; snums; i+) if (stui.mathgt; 90) amp;amp;(stui.math lt;= 100) sumc1+; else if (80 lt;= stui.math) amp;amp; (stui.math lt; 90) sumc2+; else if (70 lt;= stui.math) amp;amp;

35、(stui.math lt; 80) sumc3+; else if (60 lt;= stui.math) amp;amp; (stui.math lt; 70) sumc4+; else sumc5+; per1 = sumc1 / snums; per2 = sumc2 / snums; per3 = sumc3 / snums; per4 = sumc4 / snums; per5 = sumc5 / snums; return string.format(quot;数学成果百分比:quot; + quot;nquot; + quot;90100:quot; + per1 + quot

36、; 8090:quot; + per2 + quot; 8070:quot; + per3 + quot; 7060:quot; + per4 + quot; 60 以下的:quot; + per5); /英语成果各分数段百分比 public string pere() double per1, per2, per3, per4, per5; double sumc1 = 0, sumc2 = 0, sumc3 = 0, sumc4 = 0, sumc5 = 0; for (int i = 0; i lt; snums; i+) if (stui.english gt; 90) amp;amp

37、; (stui.english lt;= 100) sumc1+; else if (80 lt;= stui.english) amp;amp; (stui.english lt; 90) sumc2+; else if (70 lt;= stui.english) amp;amp; (stui.english lt; 80) sumc3+; else if (60 lt;= stui.english) amp;amp; (stui.english lt; 70) sumc4+; else sumc5+; per1 = sumc1 / snums; per2 = sumc2 / snums;

38、 per3 = sumc3 / snums; per4 = sumc4 / snums; per5 = sumc5 / snums; return string.format(quot;数学成果百分比:quot; + quot;nquot; + quot;90100:quot; + per1 + quot; 8090:quot; + per2 + quot; 8070:quot; + per3 + quot; 7060:quot; + per4 + quot; 60 以下的:quot; + per5); from 窗体代码: using system; using system.collect

39、ions.generic; using system.componentmodel; using system.data; using system.drawing; using system.text; using system.windows.forms; namespace test2_6 public partial class form1 : form public form1() initializecomponent(); public studentlist sl = new studentlist(); private void btnadd_click(object sen

40、der, eventargs e) student s = new student(); s.stuno = txtstuno.text; = txtname.text; s.chinese = convert.todouble(txtchina.text); s.math = convert.todouble(txtmath.text); s.english = convert.todouble(txteng.text); sl.addstu(s); messagebox.show(quot;添加胜利quot;); private void btnsearch_click(ob

41、ject sender, eventargs e) int pos = sl.searchstu(this.textbox1.text); if (pos != -1) label7.text = this.textbox1.text + quot;的总成果:quot; + sl.stupos.sumscore; else messagebox.show(quot;不存在这个人!quot;); private void btnfinish_click(object sender, eventargs e) label7.text = quot;前 3 名:quot;+quot;nquot; f

42、or (int i = 0; i lt; 3; i+) sl.prothree(); label7.text+= +quot;nquot; label7.text += sl.gethl()+quot;nquot; label7.text += convert.tostring(sl.sumscore()+quot;nquot; label7.text += sl.perc()+quot;nquot; label7.text += sl.perm()+quot;nquot; label7.text += sl.pere()+quot;nquot; 六、试验体会(遇到问题

43、及解决方法,编程后的心得体会) 通过本次试验,我把握了类的定义与使用;把握了类的数据成员,属性的定义和使用;把握了方法的定义,调用和重载以及方法参数的传递以及构造函数的定义和使用。值得留意的是:本次试验中 return的使用以及所在的位置,类型转换时也常常用到 试验项目名称: 继承与多态 试验学时: 6 同组同学姓名: 试验地点: 1318 试验日期: 11 月 16 日-11 月 30 日 试验成果: 批改老师: 批改时间: 试验 3 继承与多态 一、试验目的、要求 (1)把握类的继承性与多态性; (2)把握虚方法的定义以及如何使用虚方法实现多态; (3)把握抽象类的定义以及如何使用抽象方法

44、实现多态; 二、试验要求 (1)编写程序要规范、正确,上机调试过程和结果要有记录; (2)做完试验后给出本试验的试验报告。 三、试验设备、环境 安装有 visual studio .net 软件。 四、试验步骤 1、分析题意; 2、依据题目要求,新建项目; 3、编写并输入相关的程序代码; 5、运行与调试项目; 6、保存项目。 五 、试验内容 1、设计一个 windows 应用程序,在该程序中首先构造一个同学基本类,再分别构造学校生、中同学、高校生派生类,当输入相关数据,单击不用的按钮时,将分别创建不同的同学类对象,并输出当前同学的总人数,该同学的姓名,同学类型,平均成果。 student 类: using system; using system.collections.generic; using system.text; namespace test3_1 public abstract class student protected string name; protected i

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论