C#程序设计实验报告

上传人:仙*** 文档编号:194217185 上传时间:2023-03-13 格式:DOCX 页数:55 大小:49.78KB
收藏 版权申诉 举报 下载
C#程序设计实验报告_第1页
第1页 / 共55页
C#程序设计实验报告_第2页
第2页 / 共55页
C#程序设计实验报告_第3页
第3页 / 共55页
资源描述:

《C#程序设计实验报告》由会员分享,可在线阅读,更多相关《C#程序设计实验报告(55页珍藏版)》请在装配图网上搜索。

1、C#程序设计实验报告实验报告书写要求实验报告原则上要求学生手写,要求书写工整。若因课程特点需打印的,标题采用四号黑体,正文采用小四号宋体,单倍行距。纸张一律采用A4的纸张。 实验报告书写说明 实验报告中实验目的和要求、实验仪器和设备、实验内容与过程、实验结果与分析这四项内容为必需项。教师可根据学科特点和实验具体要求增加项目。 填写注意事项 细致观察,及时、准确、如实记录。 准确说明,层次清晰。 尽量采用专用术语来说明事物。 外文、符号、公式要准确,应使用统一规定的名词和符号。 应独立完成实验报告的书写,严禁抄袭、复印,一经发现,以零分论处。 实验报告批改说明 实验报告的批改要及时、认真、仔细,

2、一律用红色笔批改。实验报告的批改成绩采用五级记分制或百分制,按金陵科技学院课堂教学实施细则中作业批阅成绩评定要求执行。 实验报告装订要求 实验批改完毕后,任课老师将每门课程的每个实验项目的实验报告以自然班为单位、按学号升序排列,装订成册,并附上一份该门课程的实验大纲。金陵科技学院实验报告 实验项目名称: C#基础编程 实验学时: 6 同组学生姓名: 实验地点: 1318 实验日期: x月x日-x月x日 实验成绩: 批改教师: 批改时间: 金陵科技学院实验报告 实验1 C#基础编程 一、实验目的 1、熟悉Visual Studio .NET开发环境。 2、掌握C#应用程序的基本操作过程。 3、掌

3、握C#的数据类型,运算符以及表达式的使用。 4、掌握分支和循环语句的使用方法。 5、掌握一维数组,二维数组及数组型数组的使用。 二、实验要求 编写程序要规范、正确,上机调试过程和结果要有记录 做完实验后给出本实验的实验报告。 三、实验设备、环境 安装有Visual Studio .NET软件。 四、实验步骤 1、分析题意。 2、根据题目要求,新建项目。 3、编写并输入相关的程序代码。 5、运行与调试项目。 6、保存项目。 五、实验内容 1、编写一个简单的控制台应用程序,打印一行文字(如你的姓名)。 using System; using System.Collections.Generic;

4、using System.Linq; using System.Text; namespace one.first class Program static void Main(string args) System.Console.WriteLine(我叫王蕾!); 2、编写一个简单的Windows应用程序,在窗体Load事件中书写代码,标签中显示你的姓名。 using System; using System.Collections.Generic; using System.ComponentModel; 1 金陵科技学院实验报告 using System.Data; using Sys

5、tem.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 sender, EventArgs e) this.Text = Windows 程序; Label lblShow = new Label; lblShow.Location = new Point(

6、20, 30); lblShow.AutoSize = true; lblShow.Text = 王蕾!; this.Controls.Add(lblShow); 3、编写一个一个程序,用来判断输入的是大写字母,小写字母,数字还是其他的字符。 using System; using System.Collections.Generic; using System.Text; namespace one.third class Program static void Main(string args) Console.WriteLine(请输入一个字符:); char c = Convert.T

7、oChar(Console.ReadLine); if (c=a&c=A&c=Z) Console.WriteLine(这是一个字母); if (char.IsDigit(c) Console .WriteLine(这是一个数字); 2 金陵科技学院实验报告 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)

8、int i = 1, sum = 0; while (i = 100) sum = sum + i; i+; 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 .Wr

9、iteLine(1到100的自然数的和为: + sum ); 3 金陵科技学院实验报告 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、定义一个一维数组,用随机数为此赋值,用f

10、oreach循环输出其中的内容。 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

11、 System.Linq; 4 金陵科技学院实验报告 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 Sy

12、stem.Linq; using 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); 六、实验体会 刚开始编程的时候觉得无从下手,尽管我们已经学了好几种高级编程语言,但每个都5 金陵科技学院实验报告 有其独特的地

13、方,稍不留神就会混淆。 通过这次实验,我体会到课后复习巩固的重要性。在编程的时候,很多内容都不记得,需要去翻书。不得不说,实验是巩固课程的好方法!本次实验,我熟悉Visual Studio .NET开发环境;掌握了C#应用程序的基本操作过程;掌握了C#的数据类型,运算符以及表达式的使用;掌握了分支和循环语句的使用方法以及一维数组,二维数组及数组型数组的使用。 6 金陵科技学院实验报告 实验项目名称: 类与对象 实验学时: 6 同组学生姓名: 实验地点: 1318 实验日期: x月x日-x月x日 实验成绩: 批改教师: 批改时间: 7 金陵科技学院实验报告 实验2 类与对象 一、实验目的、要求

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

15、stem.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); 8 金陵科技学院实验报告 Console.WriteLine(s.Swap(a, b); Console.WriteLine(

16、s.Swap(ref a,ref b); class Swaper public string Swap(int x, int y) int temp; temp = x; x = y; y = temp; return 后:x=0,y=1,x,y); public string Swap(ref int x, ref int y) int temp; temp = x; x = y; y = temp; return string.Format(按引用传参交换之后:x=0,y=1, x, y); 2、定义一个方法,实现数组的排序。 using System; using System.Col

17、lections.Generic; using System.Text; namespace second.two class Program string.Format(按值传参交换之9 金陵科技学院实验报告 public class sort public void change(int a) Console.WriteLine(排序前,数组顺序为:); show(a); int i, j, m; for (i = 0; i = 0 & m aj)/判断i下标的数是否大于j下标的数 aj + 1 = aj;/如果i下标大于j把j往后移一个位 j-; aj+1 = m; /当不大于j的时候就

18、把M的值放到i下标下面 j+1 是为了下标减到最前时考虑 -1 + 1 还是下标的最前面 Console.WriteLine(排序后,数组顺序为:); show(a); void show(int a) int i; for (i = 0; i 10; i+) Console.Write(0 , ai); Console.WriteLine; 10 金陵科技学院实验报告 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、定义一个学生类,把学生

19、类当作对象来传递。 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 = 999; public class st public void aa(student s) Console.WriteLine(s); static void Main(string args) 11 金陵科技学院实验报告 student s=

20、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 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(st

21、ring 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,a,b,m,n); 12 金陵科技学院实验报告 5、用构造函数重载,实现矩形的面积,圆的面积,梯形的面积; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace secong.five class Program public

22、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) area = (a + b) / 2 * h; static void Main(string args) double a, b, h,area; a = 2; b = 5; h = 3; 13 金陵科技学院实验报告 square

23、 s = new square(a,b); Console.WriteLine(求矩形面积,长为a=0,宽为b=1,面积area=2,a,b,s.area); square i = new square(a); Console.WriteLine(求圆形面积,半径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应用程序,在该程序中定义一个学生类和班级类,以处理每个

24、学生的学号,姓名,语文,数学和英语成绩,要求: 1)能查询每个学生的总成绩。 2)能显示全班前三名的名单。 3)能显示单科成绩最高分和不及格的学生名单。 4)能统计全班学生的平均成绩。 5)能显示各科成绩不同分数段的学生人数的百分比。 Student类: using System; using System.Collections.Generic; using System.Text; namespace Test2_6 public class Student public string stuNo; public string name; public double chinese; pu

25、blic double math; public double english; public double sumScore 14 金陵科技学院实验报告 get return chinese + math + english; StudentList类: using System; using System.Collections.Generic; using System.Text; namespace Test2_6 public class StudentList:Student int snums; public Student stu=new Student50; public S

26、tudentList snums = 0; public void addstu(Student s) stusnums = s; snums+; public int searchstu(string name) int i; for (i = 0; i snums; i+) if (stui.name = name) break; if (i = snums) return -1; else return i; /给所有成绩排序,用后面实现前三名的排名 15 金陵科技学院实验报告 public void ProThree for (int i = 0; i snums; i+) int k

27、 = i; for (int j = i + 1; j stuk.sumScore) k = j; if (k != i) Student temp; temp = stuk; stuk = stui; stui = temp; /显示单科成绩的最高分 public int HighScore(int k) int p = 0; if (k = 0) for (int i = 1; i stup.math) p = i; else if (k = 1) for (int i = 1; i stup.chinese) p = i; else for (int i = 1; i stup.chin

28、ese) p = i; 16 金陵科技学院实验报告 return p; /显示不及格名单 public string BuhgName(int k) string name= ; if (k = 0) for (int i = 0; i snums; i+) if (stui.math 60) name +=stui.name+n; else if (k = 1) for (int i = 0; i snums; i+) if (stui.chinese 60) name += stui.name + n; else for (int i = 0; i snums; i+) if (stui.

29、english 60) name += stui.name + n; return name; public string getHL string Maxer = , Loser = ; Maxer += 单科数学最高: + stuHighScore(0).name + n; Maxer += 单科语文最高: + stuHighScore(1).name + n; Maxer += 单科英语最高: + stuHighScore(2).name + n; Loser += 单科数学挂科名单: +BuhgName(0) + n; Loser += 单科语文挂科名单: + BuhgName(1)

30、+ n; Loser += 单科英语挂科名单: + BuhgName(2) + n; 17 金陵科技学院实验报告 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 per

31、1, per2, per3, per4, per5; double sumC1 = 0, sumC2 = 0, sumC3 = 0, sumC4 = 0, sumC5 = 0; for (int i = 0; i 90) & (stui.chinese = 100) sumC1+; else if (80 = stui.chinese) & (stui.chinese 90) sumC2+; 18 金陵科技学院实验报告 else if(70=stui.chinese)& (stui.chinese 80) sumC3+; else if(60=stui.chinese)&(stui.chine

32、se 70) sumC4+; else sumC5+; per1 = sumC1 / snums; per2 = sumC2 / snums; per3 = sumC3 / snums; per4 = sumC4 / snums; per5 = sumC5 / snums; return 语文成绩百分比:+n+90100:+per1+ 8090:+per2+ 8070:+per3+ 7060:+per4+ 60以下的:+per5; /数学成绩各分数段百分比 public string PerM double per1, per2, per3, per4, per5; double sumC1

33、= 0, sumC2 = 0, sumC3 = 0, sumC4 = 0, sumC5 = 0; for (int i = 0; i 90) &(stui.math = 100) sumC1+; else if (80 = stui.math) & (stui.math 90) 19 金陵科技学院实验报告 sumC2+; else if (70 = stui.math) & (stui.math 80) sumC3+; else if (60 = stui.math) & (stui.math 70) sumC4+; else sumC5+; per1 = sumC1 / snums; per

34、2 = sumC2 / snums; per3 = sumC3 / 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, per2, per3, per4, per5; double sumC1 = 0, sumC2 = 0, sumC

35、3 = 0, sumC4 = 0, sumC5 = 0; for (int i = 0; i 90) & (stui.english = 100) sumC1+; 20 金陵科技学院实验报告 else if (80 = stui.english) & (stui.english 90) sumC2+; else if (70 = stui.english) & (stui.english 80) sumC3+; else if (60 = stui.english) & (stui.english 70) sumC4+; else sumC5+; per1 = sumC1 / snums; p

36、er2 = sumC2 / snums; per3 = sumC3 / snums; per4 = sumC4 / snums; per5 = sumC5 / snums; return string.Format(数学成绩百分比: + n + 90100: + per1 + 8090: + per2 + 8070: + per3 + 7060: + per4 + 60以下的: + per5); From窗体代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.

37、Data; using System.Drawing; using System.Text; 21 金陵科技学院实验报告 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) Student s = new Student; s.stu

38、No = txtStuNo.Text; s.name = 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(添加成功); private void btnSearch_Click(object sender, EventArgs e) int pos = sl.searchstu(this.textBox1.Text); if (pos != -1) label7.Text = this.textBox1.Text + 的总成绩:sl.stupos.sumScore; else MessageBox.Show(不存在这个人!); private void btnFinish_Click(object sender, EventArgs e) label7.Text = 前3名:+n; 22

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

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


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