



版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、c#基础编程设计实验报告 c# 基础编程 设计实验报告 一、实验目的 1、熟悉 visual studio .net 开发环境。 2、掌握 c#应用程序的基本操作过程。 3、掌握 c#的数据类型,运算符以及表达式的使用。 4、掌握分支和循环语句的使用方法。 5、掌握一维数组,二维数组及数组型数组的使用。 二、实验要求 (1)编写程序要规范、正确,上机调试过程和结果要有记录 (2)做完实验后给出本实验的实验报告。 三、实验设备、环境 安装有 visual studio .net 软件。 四、实验步骤 1、分析题意。 2、根据题目要求,新建项目。 3、编写并输入相关的程序代码。 5、运行与调试项目
2、。 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 事件中书写代码,标签中显示你的姓名。 using s
3、ystem; 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 form1_load(object
4、 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.generic; using sy
5、stem.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;这是一个字母quot;); if (char
6、.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+; console.writelin
7、e(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; + sum ); using syste
8、m; 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 循环输 出其中的内容。 using system; using
9、 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; using system.text; nam
10、espace 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.text; namespace f
11、irst.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)掌握类的数据成员,属性的定义和使用; (3
13、)掌握方法的定义,调用和重载以及方法参数的传递; (4)掌握构造函数的定义和使用。 二、实验要求 (1)编写程序要规范、正确,上机调试过程和结果要有记录; (2)做完实验后给出本实验的实验报告。 三、实验设备、环境 安装有 visual studio .net 软件。 四、实验步骤 1、分析题意; 2、根据题目要求,新建项目; 3、编写并输入相关的程序代码; 5、运行与调试项目; 6、保存项目。 五、实验内容 1、定义一个方法,实现两个数的交换(分别把参数按值传递和按引用传递)。 using system; using system.collections.generic; using sys
14、tem.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(s.swap(a, b); cons
15、ole.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;按引用传参交换之后:x=0,y=1quot;,
16、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为数组前一个值 while (j g
17、t;= 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;, ai); console.writ
18、eline(); 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 public void st() int a
19、 = 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 second.four class
20、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、用构造函数重载,实现矩形的面积,圆的面积,梯形的面积; using system;
21、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, double b, double h)
22、 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.area); square j = new
23、 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; using system.col
24、lections.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 system.collections.gen
25、eric; 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 ( = name) bre
26、ak; 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; /显示单科成绩的最高分 public in
27、t 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; return p; /显示不及格. p
28、ublic 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; snums; i+) if (stui
29、.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 += quot; 单 科 英 语 最
30、 高 : 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() double sum = 0;
31、 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 (int i = 0; i lt; snu
32、ms; 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 sumc5+; per1 = sumc1
33、 / 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 string perm() double pe
34、r1, 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; (stui.math lt; 80)
35、 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; 8090:quot; + per
36、2 + 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; (stui.english lt
37、;= 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; per3 = sumc3 / sn
38、ums; 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.collections.generic; usin
39、g 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 sender, eventargs e)
40、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(object sender, event
41、args 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; for (int i = 0; i l
42、t; 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)掌握抽象类的定义以及如何使用抽象方法实现多态; 二、实验要求 (1)编写
44、程序要规范、正确,上机调试过程和结果要有记录; (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 int age; public stati
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年四川宜宾三江投资建设集团有限公司员工招聘真题
- 2025典当车辆合同范本
- 2025中外合资企业劳动合同
- 2024年鞍山市铁西区事业单位招聘真题
- 2025春季中国石油高校毕业生招聘考前自测高频考点模拟试题及一套答案详解
- 2025甘肃平凉市灵台县公安局面向社会招聘警务辅助人员28人模拟试卷附答案详解(模拟题)
- 2025项目管理工程师劳动合同
- 2025河南新乡市开发公益性岗位招聘25人考前自测高频考点模拟试题附答案详解(模拟题)
- 2025广西桂林市灵川县发展和改革局公开招聘6人考前自测高频考点模拟试题及答案详解参考
- 2025广西南宁市消防救援支队政府专职消防员招聘3人考前自测高频考点模拟试题及一套参考答案详解
- 南通蓝浦环评报告书
- 商户维护与管理办法
- 2025至2030中国金属铬行业产业运行态势及投资规划深度研究报告
- 2025年陕西省中考英语试题卷(含答案及解析)
- cma资料培训课件
- 专利代理所管理制度
- 农村道路交通宣传课件
- DZ/T 0275.5-2015岩矿鉴定技术规范第5部分:矿石光片鉴定
- 2025年新教材道德与法治三年级上册第二单元《学科学爱科学》教案设计
- 陕煤集团运销合同协议
- 行政管理毕业论文-我国地方政府行政机构改革问题研究
评论
0/150
提交评论