




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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("我叫王蕾!"); 2、编写一个简单的 windows 应用程序,在窗体 load 事件中书写代码,标签中显示你的姓名。 using
3、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 form1load(object
4、 sender, eventargs e) this.text = "windows 程序" label lblshow = new label(); lblshow.location = new point(20, 30); lblshow.autosize = true; lblshow.text = "王蕾!" this.controls.add(lblshow); 3、编写一个一个程序,用来判断输入的是大写字母,小写字母,数字还是其他的字符。 using system; using system.collections.generic; usin
5、g system.text; namespace one.third class program static void main(string args) console.writeline("请输入一个字符:"); char c = convert.tochar(console.readline(); if (c>="a"&&c<="z")|(c>="a"&&c<="z") console.writeline("这是一个字母&
6、quot;); if (char.isdigit(c) console .writeline("这是一个数字"); 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 <= 100) sum = sum + i; i
7、+; console.writeline("1 到 100 的自然数之和为:" + 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 <= 100); console .writeline("1 到 100 的自然数的和为:&qu
8、ot; + 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 <= 100; i+) sum = sum + i; console.writeline("1 到 100 的自然数的和为:" + sum); 5、定义一个一维数组,用随机数为此赋值,用 foreach 循环输
9、出其中的内容。 using 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.l
10、inq; using 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 < 2; i+) for (int j = 0; j < 3; j+) console.writeline(ai, j); 7、实现数组型数组的输入和输出。 using system; using system.collections.generic; using system.linq; u
11、sing system.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 < a.length; i+) for (int j = 0; j < ai.length; j+) console.writeline(aij); 六、实验体会(遇到问题及解决方法,编程后的心得体会) 刚开始编程的时候觉得无从下手,尽管我们已经学了好几种高级编程语言,但每个都有
12、其独特的地方,稍不留神就会混淆。 通过这次实验,我体会到课后复习稳固的重要性。在编程的时候,很多内容都不记得,需要去翻书。不得不说,实验是稳固课程的好方法!本次实验,我熟悉 visual studio .net 开发环境; 掌握了 c#应用程序的根本操作过程;掌握了 c#的数据类型,运算符以及表达式的使用;掌握了分支和循环语句的使用方法以及一维数组,二维数组及数组型数组的使用。 实验工程名称: 类与对象 实验学时: 6 同组学生姓名: 实验地点: 1318 实验日期: 10 月 26 日-11 月 9 日 实验成绩: 批改教师: 批改时间: 实验 2 类与对象 一、实验目的、要求 (1)掌握类
13、的定义和使用; (2)掌握类的数据成员,属性的定义和使用; (3)掌握方法的定义,调用和重载以及方法参数的传递; (4)掌握构造函数的定义和使用。 二、实验要求 (1)编写程序要标准、正确,上机调试过程和结果要有记录; (2)做完实验后给出本实验的实验报告。 三、实验设备、环境 安装有 visual studio .net 软件。 四、实验步骤 1、分析题意; 2、根据题目要求,新建工程; 3、编写并输入相关的程序代码; 5、运行与调试工程; 6、保存工程。 五、实验内容 1、定义一个方法,实现两个数的交换(分别把参数按值传递和按引用传递)。 using system; using syste
14、m.collections.generic; using system.text; namespace second.one class program static void main(string args) swaper s = new swaper(); console.writeline("输入 x 的值:"); int a = convert.toint32(console.readline(); console.writeline("输入 y 的值:"); int b=convert.toint32(console.readline();
15、console.writeline(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("按值传参交换之后:x=0,y=1",x,y); public string swap(ref int x, ref int y) int temp; temp = x; x = y; y = temp; return strin
16、g.format("按引用传参交换之后:x=0,y=1", 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("排序前,数组顺序为:"); show(a); int i, j, m; for (i = 0; i < 10; i
17、+) m = ai; j = i - 1; /aj为数组前一个值 while (j >= 0 && m > aj)/判断 i 下标的数是否大于 j 下标的数 aj + 1 = aj;/如果 i 下标大于j 把 j 往后移一个位 j-; aj+1 = m; /当不大于 j 的时候就把 m的值放到 i 下标下面 j+1 是为了下标减到最前时考虑 -1 + 1 还是下标的最前面 console.writeline("排序后,数组顺序为:"); show(a); void show(int a) int i; for (i = 0; i < 10;
18、 i+) console.write("0 ", 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
19、 program public class student public 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.l
20、inq; using system.text; namespace 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("0+1=2;0- 1=3",
21、a,b,m,n); 5、用构造函数重载,实现矩形的面积,圆的面积,梯形的面积; 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) are
22、a = a * b; public square(double a, double 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("求矩形面积,长为 a=0,宽为 b=1,面积 area=2",a,b,s.area); square i = new square(a); console.writeline(&quo
23、t;求圆形面积,半径 a=0,面积 area=1", a, i.area); square j = new square(a, b, h); console.writeline("求梯形面积,上底为a=0,下底为 b=1,高为 h=2面积 area=3", a, b,h, j.area); 6、设计一个 windows 应用程序,在该程序中定义一个学生类和班级类,以处理每个学生的学号,姓名,语文,数学和英语成绩,要求: 1)能查询每个学生的总成绩。 2)能显示全班前三名的。 3)能显示单科成绩最高分和不及格的学生。 4)能统计全班学生的平均成绩。 5)能显示各科成
24、绩不同分数段的学生人数的百分比。 student 类: using system; using system.collections.generic; using system.text; namespace test26 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;
25、studentlist 类: using system; using system.collections.generic; using system.text; namespace test26 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
26、; for (i = 0; i < snums; i+) if ( = name) break; if (i = snums) return -1; else return i; /给所有成绩排序,用后面实现前三名的排名 public void prothree() for (int i = 0; i < snums; i+) int k = i; for (int j = i + 1; j < snums; j+) if (stuj.sumscore > stuk.sumscore) k = j; if (k != i) student temp;
27、temp = stuk; stuk = stui; stui = temp; /显示单科成绩的最高分 public int highscore(int k) int p = 0; if (k = 0) for (int i = 1; i < snums; i+) if (stui.math > stup.math) p = i; else if (k = 1) for (int i = 1; i < snums; i+) if (stui.chinese > stup.chinese) p = i; else for (int i = 1; i < snums;
28、i+) if (stui.chinese > stup.chinese) p = i; return p; /显示不及格 public string buhgname(int k) string name=" " if (k = 0) for (int i = 0; i < snums; i+) if (stui.math < 60) name +=+"n" else if (k = 1) for (int i = 0; i < snums; i+) if (stui.chinese < 60) name
29、+= + "n" else for (int i = 0; i < snums; i+) if (stui.english < 60) name += + "n" return name; public string gethl() string maxer = " ", loser = " " maxer += " 单 科 数 学 最 高 : " + stuhighscore(0).name + "n" maxer +=
30、" 单 科 语 文 最 高 : " + stuhighscore(1).name + "n" maxer += " 单 科 英 语 最 高 : " + stuhighscore(2).name + "n" loser += "单科数学挂科:" +buhgname(0) + "n" loser += "单科语文挂科:" + buhgname(1) + "n" loser += "单科英语挂科:" + buhgname(
31、2) + "n" return maxer + "n" + loser; /全班的平均成绩 public string sumscore() double sum = 0; double avg=0; for (int i = 0; i < snums; i+) sum = sum + stui.sumscore; avg = sum / snums; return "班级总分平均分:"+avg; /各科成绩不同分数段的学生百分比 /英语成绩各分数段百分比 public string perc() double per1, pe
32、r2, per3, per4, per5; double sumc1 = 0, sumc2 = 0, sumc3 = 0, sumc4 = 0, sumc5 = 0; for (int i = 0; i < snums; i+) if (stui.chinese > 90) && (stui.chinese <= 100) sumc1+; else if (80 <= stui.chinese) && (stui.chinese < 90) sumc2+; else if(70<=stui.chinese)&&
33、 (stui.chinese < 80) sumc3+; else if(60<=stui.chinese)&&(stui.chinese < 70) sumc4+; else sumc5+; per1 = sumc1 / snums; per2 = sumc2 / snums; per3 = sumc3 / snums; per4 = sumc4 / snums; per5 = sumc5 / snums; return " 语 文 成 绩 百 分 比 :"+"n"+"90100:"+per1+&q
34、uot; 8090:"+per2+" 8070:"+per3+" 7060:"+per4+" 60 以下的:"+per5; /数学成绩各分数段百分比 public string perm() double per1, per2, per3, per4, per5; double sumc1 = 0, sumc2 = 0, sumc3 = 0, sumc4 = 0, sumc5 = 0; for (int i = 0; i < snums; i+) if (stui.math> 90) &&(stu
35、i.math <= 100) sumc1+; else if (80 <= stui.math) && (stui.math < 90) sumc2+; else if (70 <= stui.math) && (stui.math < 80) sumc3+; else if (60 <= stui.math) && (stui.math < 70) sumc4+; else sumc5+; per1 = sumc1 / snums; per2 = sumc2 / snums; per3 = sumc3
36、/ snums; per4 = sumc4 / snums; per5 = sumc5 / snums; return string.format("数学成绩百分比:" + "n" + "90100:" + per1 + " 8090:" + per2 + " 8070:" + per3 + " 7060:" + per4 + " 60 以下的:" + per5); /英语成绩各分数段百分比 public string pere() double per1
37、, per2, per3, per4, per5; double sumc1 = 0, sumc2 = 0, sumc3 = 0, sumc4 = 0, sumc5 = 0; for (int i = 0; i < snums; i+) if (stui.english > 90) && (stui.english <= 100) sumc1+; else if (80 <= stui.english) && (stui.english < 90) sumc2+; else if (70 <= stui.english) &a
38、mp;& (stui.english < 80) sumc3+; else if (60 <= stui.english) && (stui.english < 70) sumc4+; else sumc5+; per1 = sumc1 / snums; per2 = sumc2 / snums; per3 = sumc3 / snums; per4 = sumc4 / snums; per5 = sumc5 / snums; return string.format("数学成绩百分比:" + "n" + &qu
39、ot;90100:" + per1 + " 8090:" + per2 + " 8070:" + per3 + " 7060:" + per4 + " 60 以下的:" + per5); from 窗体代码: using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.text; using system.
40、windows.forms; namespace test26 public partial class form1 : form public form1() initializecomponent(); public studentlist sl = new studentlist(); private void btnaddclick(object sender, eventargs e) student s = new student(); s.stuno = txtstuno.text; = txtname.text; s.chinese = convert.todou
41、ble(txtchina.text); s.math = convert.todouble(txtmath.text); s.english = convert.todouble(txteng.text); sl.addstu(s); messagebox.show("添加成功"); private void btnsearchclick(object sender, eventargs e) int pos = sl.searchstu(this.textbox1.text); if (pos != -1) label7.text = this.textbox1.text
42、 + "的总成绩:" + sl.stupos.sumscore; else messagebox.show("不存在这个人!"); private void btnfinishclick(object sender, eventargs e) label7.text = "前 3 名:"+"n" for (int i = 0; i < 3; i+) sl.prothree(); label7.text+= +"n" label7.text += sl.gethl()
43、+"n" label7.text += convert.tostring(sl.sumscore()+"n" label7.text += sl.perc()+"n" label7.text += sl.perm()+"n" label7.text += sl.pere()+"n" 六、实验体会(遇到问题及解决方法,编程后的心得体会) 通过本次实验,我掌握了类的定义与使用; 掌握了类的数据成员,属性的定义和使用;掌握了方法的定义,调用和重载以及方法参数的传递以及构造函数的定义和使用。值得注意的是
44、:本次实验中 return的使用以及所在的位置,类型转换时也经常用到 实验工程名称: 继承与多态 实验学时: 6 同组学生姓名: 实验地点: 1318 实验日期: 11 月 16 日-11 月 30 日 实验成绩: 批改教师: 批改时间: 实验 3 继承与多态 一、实验目的、要求 (1)掌握类的继承性与多态性; (2)掌握虚方法的定义以及如何使用虚方法实现多态; (3)掌握抽象类的定义以及如何使用抽象方法实现多态; 二、实验要求 (1)编写程序要标准、正确,上机调试过程和结果要有记录; (2)做完实验后给出本实验的实验报告。 三、实验设备、环境 安装有 visual studio .net 软
45、件。 四、实验步骤 1、分析题意; 2、根据题目要求,新建工程; 3、编写并输入相关的程序代码; 5、运行与调试工程; 6、保存工程。 五 、实验内容 1、设计一个 windows 应用程序,在该程序中首先构造一个学生根本类,再分别构造小学生、中学生、大学生派生类,当输入相关数据,单击不用的按钮时,将分别创立不同的学生类对象,并输出当前学生的总人数,该学生的姓名,学生类型,平均成绩。 student 类: using system; using system.collections.generic; using system.text; namespace test31 public abst
46、ract class student protected string name; protected int age; public static int number; public student(string name, int age) = name; this.age = age; number+; public string name get return name; public abstract double average(); public class pupil : student protected double chinese; protecte
47、d double math; public pupil(string name, int age, double chinese, double math) : base(name, age) this.chinese = chinese; this.math = math; public override double average() return (chinese + math) / 2; public class middle : student protected double chinese; protected double math; protected double eng
48、lish; public middle(string name, int age, double chinese, double math, double english) : base(name, age) this.chinese = chinese; this.math = math; this.english = english; public override double average() return (chinese + math + english) / 3; public class college : student protected double required;
49、 protected double elective; public college(string name, int age, double required, double elective) : base(name, age) this.required = required; this.elective = elective; public override double average() return (required + elective) / 2; form 窗体内的代码: using system.collections.generic; using system.comp
50、onentmodel; using system.data; using system.drawing; using system.text; using system.windows.forms; namespace test31 public partial class form1 : form public form1() initializecomponent(); private void btnsmallclick(object sender, eventargs e) pupil p = new pupil(txtname.text,convert.toint32(txtage.
51、text),convert.todouble(txtchinese.text),convert.todouble(txtmath.text); lblshow.text += " 总 人 数 :" +convert.tostring( student.number) + "," + "姓名:" + p.name + "," + "小学生" + "," + "平均成绩为:" + p.average() +"n" private void
52、btnmiddleclick(object sender, eventargs e) middle m = new middle(txtname.text, convert.toint32(txtage.text), convert.todouble(txtchinese.text), convert.todouble(txtmath.text),convert.todouble(txtenglish.text); lblshow.text += " 总 人 数 :" + convert.tostring(student.number) + "," +
53、"姓名:" + m.name + "," + "中学生" + "," + "平均成绩为:" + m.average() + "n" private void btnbigclick(object sender, eventargs e) college c = new college(txtname.text, convert.toint32(txtage.text), convert.todouble(txtchinese.text), convert.todouble(t
54、xtmath.text); lblshow.text += " 总 人 数 :" + convert.tostring(student.number) + "," + "姓名:" + c.name + "," + "大学生" + "," + "平均成绩为:" + c.average() + "n" 2、设计一个 windows 应用程序,在该程序中定义平面图形抽象类和派生类圆,矩形和三角形。 figure 类代码: using syst
55、em; using system.collections.generic; using system.text; namespace test32 public abstract class figure public abstract double area(); public class circle:figure double radius; public circle(double r) radius = r; public override double area() return radius * radius * 3.14; public class juxing:figure double chang; double kuan; public juxing(double c, double k) this.chang = c; this.kuan = k; public override double area() return chang * kuan; public class san:figure double bian; double heigth; public san(double b, double h)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 机械厂机床安装技术方案
- 地基土性测试与处理工艺方案
- 低洼地区排涝系统升级改造方案
- 高层建筑电气工程施工方案
- 变压器散热片生产线项目建筑工程方案
- 大豆蛋白生产线自动化控制系统搭建方案
- 磷石膏无害化处置项目建设规划方案
- 重庆温泉设计咨询方案
- 市政管网改造及换热站更新项目可行性研究报告
- 跨境职业技能培训市场2025年机遇与挑战分析
- 电商税务筹划课件模板
- 系统测量msa培训课件
- 2025年中国冷冻熟虾数据监测研究报告
- 护理陪检课件
- 律师行业税务问题课件
- 2025年4月自考00831英语语法试题及答案含评分参考
- 招商局集团招聘考试真题2024
- 政府融资帮扶协议书
- 2025公需课《新质生产力与现代化产业体系》考核试题库及答案
- 《提升思维高度:战略思维培养与应用》课件
- 教官聘用合同协议
评论
0/150
提交评论