数据结构C学生成绩表实验报告

上传人:无*** 文档编号:135831907 上传时间:2022-08-15 格式:DOC 页数:15 大小:161.50KB
收藏 版权申诉 举报 下载
数据结构C学生成绩表实验报告_第1页
第1页 / 共15页
数据结构C学生成绩表实验报告_第2页
第2页 / 共15页
数据结构C学生成绩表实验报告_第3页
第3页 / 共15页
资源描述:

《数据结构C学生成绩表实验报告》由会员分享,可在线阅读,更多相关《数据结构C学生成绩表实验报告(15页珍藏版)》请在装配图网上搜索。

1、琼州学院实验报告课程名称数据结构实验项目名称用单链表解决线性表问题实验项目序号1实验类型验证性实验地点6607专业班级09数媒实验日期2011/3/10指导教师签名姓名周凌峰学号09217046成绩评定一、实验目的1、初步掌握接口的定义及使用方法;2、初步掌握范型的定义及使用方法;3、掌握链表结构的定义及使用方法;4、了解线性表的定义及操作。二、实验内容及要求有一个学生成绩表,以升序的方式存储着N位学生的成绩,如下表:学号 姓名 考试成绩 071133106 吴宾 76 071133104 张立 78 071133105 徐海 86 。 。现需要编写一个学生成绩管理系统,实现如下的功能: 1)

2、对学生成绩表,可以插入、删除学生成绩,并要保持成绩按升序排列;2)可以按给定的姓名或学号查询指定学生的信息;3)可以按升序或降序显示所有学生的成绩。要求:1)使用链表以及C#接口和范型技术实现通用的线性表功能;2)利用1)实现学生成绩线性表,并完成相应功能。三、实验设备环境仪器:计算机;实验环境:Microsoft Visual Studio 2008四、实验原理1、线性表接口定义及说明;2、范型链表实现线性表接口;3、主程序流程图。1、接口:一个接口可从一个或多个基接口继承。其成员只能是一般方法、属性、和索引函数,而不能有字段和构造函数。线性表接口如下:interface ILinarLis

3、t void InsertNode(T a);/在链表末尾插入元素 void InsertNode(T a, int i);/在指定的位置i插入元素 void DeleteNode(int i);/删除操作 T SearchNode(int i);/查找表元素 T SearchNode(T value);/定位元素 /T PreviousNode(T value);/求前驱元素 /T NextNode(T value);/求后继元素 int GetLength();/求表长度 void Clear(); /清空操作 bool IsEmpty(); /判断线性表是否为空 2、泛型:使用泛型类型可

4、以最大限度地重用代码、保护类型的安全以及提高性能。通过泛型可以定义类型安全的并且对性能或工作效率无损害的类。T可以是任意参数类型。3、主程序流程:a.初始化单链表,空链表,length=0,start=null;b.对学生成绩表进行操作,输入选择的操作项数来执行不同的方法,选择1.添加学生成绩,依次输入学号、姓名、学生成绩,将成绩表中的数据输入到其中来构建链表,判断新元素插入链表的位置,若成功则创建结点,插入新数据,若还有学生成绩要输入就重复以上步骤五、实验步骤及调试分析进入主程序调试(F10或F11)后:1 首先进入初始化单链表,stuList = new SLinkList();lengt

5、h=0,start=null 。初始化线性表public SLinkList() start = null;把线性表插入到单链表当中,tuList = new SLinkList();2学生成绩表进行操作,按选择的操作来执行不同的方法或构造函数,一一对应的。while (true) Console.WriteLine(请输入操作选项:); Console.WriteLine(1.添加学生成绩); Console.WriteLine(2.删除学生成绩); Console.WriteLine(3.按姓名查询学生成绩); Console.WriteLine(4.按学号查询学生成绩); Console

6、.WriteLine(5.按升序显示所有的学生成绩); Console.WriteLine(6.按降序显示所有的学生成绩); Console.WriteLine(7.退出); seleflag = Convert.ToChar(Console.ReadLine();添加学生信息,char flag; do string stu_no; string stu_name; int stu_score; Console.Write(请输入学号:); stu_no = Console.ReadLine(); Console.Write(请输入姓名:); stu_name = Console.ReadL

7、ine(); Console.Write(请输入学生成绩:); stu_score = Convert.ToInt32(Console.ReadLine();3.入的学生结点,StuNode newNode = new StuNode(stu_no, stu_name, stu_score);4.判断要插入新元素的位置if (stuList.GetLength () = 0) stuList.InsertNode(newNode, 1); else if (newNode.Stu_score (stuList.SearchNode(stuList.GetLength().Stu_score)

8、stuList.InsertNode(newNode, stuList.GetLength()+1); else for (int i = 1; i =stuList.GetLength (); i+) if (newNode.Stu_score =(stuList.SearchNode(i).Stu_score) stuList.InsertNode(newNode, i); break; 5.判断是否还有学生信息加入,重复以上执行,将成绩信息都输入完为止,按7退出。六、实验结果及分析依次按提示输入3个学生的学号、姓名、成绩后输入N,再按提示选择5,即得到结果如上图七、附录:源程序using

9、 System;using System.Collections.Generic;using System.Text;namespace ListDs interface ILinarList void InsertNode(T a);/在链表末尾插入元素 void InsertNode(T a, int i);/在指定的位置i插入元素 void DeleteNode(int i);/删除操作 T SearchNode(int i);/查找表元素 T SearchNode(T value);/定位元素 /T PreviousNode(T value);/求前驱元素 /T NextNode(T

10、value);/求后继元素 int GetLength();/求表长度 void Clear(); /清空操作 bool IsEmpty(); /判断线性表是否为空 class SLinkList : ILinarList private SNode start;/单链表的头引用 int length;/单链表的长度 /初始化线性表 public SLinkList() start = null; /在单链表的末尾追加数据元素 public void InsertNode(T a) if (start = null) start = new SNode(a); return; SNode cu

11、rrent = start; while (current.Next != null) current = current.Next; current.Next = new SNode(a); length+; /在单链表的第i个数据元素的位置前插入一个数据元素 public void InsertNode(T a, int i) SNode current; SNode previous; if (i 1) Console.WriteLine(Position is error!); return; SNode newnode = new SNode(a); /在空链表或第一个元素前插入第一

12、个元素 if (i = 1) newnode.Next = start; start = newnode; length+; return; /单链表的两个元素间插入一个元素 current = start; previous = null; int j = 1; while (current!= null & j i) previous = current; current = current.Next; j+; if (j = i) previous.Next = newnode; newnode.Next = current; length+; /删除单链表的第i个数据元素 public

13、 void DeleteNode(int i) if (IsEmpty() | i 1) Console.WriteLine(Link is empty or Position is error!); SNode current = start; if (i = 1) start = current.Next; length-; return; SNode previous=null; int j = 1; while (current.Next != null & j i) previous = current; current = current.Next; j+; if (j = i)

14、previous.Next = current.Next; current = null; length-; else Console.WriteLine(The ith node is not exist!); /获得单链表的第i个数据元素 public T SearchNode(int i) if (IsEmpty() Console.WriteLine(List is empty!); return default(T); SNode current =start; int j = 1; while (current.Next != null & j i) current = curre

15、nt.Next; j+; if (j = i) return current.Data; else Console.WriteLine(The ith node is not exist!); return default(T); /在单链表中查找值为value的数据元素 public T SearchNode(T value) if (IsEmpty() Console.WriteLine(List is Empty!); return default(T); SNode current = start; int i = 1; while (!current.Data.ToString().

16、Contains(value.ToString() & current!= null) current = current.Next; i+; if (current != null) return current.Data; else return default(T); /求单链表的长度 public int GetLength() return length; /清空单链表 public void Clear() start = null; /判断单链表是否为空 public bool IsEmpty() if (start = null) return true; else retur

17、n false; class StuNode private string stu_no; private string stu_name; private int stu_score; public string Stu_no get return stu_no; set stu_no=value; public string Stu_name get return stu_name; set stu_name = value; public int Stu_score get return stu_score; set stu_score = value; public StuNode(s

18、tring stu_no, string stu_name, int stu_score) this.stu_no = stu_no; this.stu_name = stu_name; this.stu_score = stu_score; public override string ToString() return stu_no + Stu_name; private T data; /数据域 private SNode next; /引用域 public SNode(T val, SNode p) data = val; next = p; public SNode(SNode p)

19、 next = p; public SNode(T val) data = val; next = null; public SNode() data = default(T); next = null; /数据域属性 public T Data get return data; set data = value; /引用域属性 public SNode Next get return next; set next = value; public static void Main() ILinarList stuList = null; /*初始化单链表*/ case 2: stuList =

20、 new SLinkList(); break; /*对学生成绩表进行操作*/ while (true) Console.WriteLine(请输入操作选项:); Console.WriteLine(1.添加学生成绩); Console.WriteLine(2.删除学生成绩); Console.WriteLine(3.按姓名查询学生成绩); Console.WriteLine(4.按学号查询学生成绩); Console.WriteLine(5.按升序显示所有的学生成绩); Console.WriteLine(6.按降序显示所有的学生成绩); Console.WriteLine(7.退出); s

21、eleflag = Convert.ToChar(Console.ReadLine(); switch (seleflag) /*添加学生成绩*/ case 1: char flag; do string stu_no; string stu_name; int stu_score; Console.Write(请输入学号:); stu_no = Console.ReadLine(); Console.Write(请输入姓名:); stu_name = Console.ReadLine(); Console.Write(请输入学生成绩:); stu_score = Convert.ToInt3

22、2(Console.ReadLine(); StuNode newNode = new StuNode(stu_no, stu_name, stu_score); if (stuList.GetLength () = 0) stuList.InsertNode(newNode, 1); else if (newNode.Stu_score (stuList.SearchNode(stuList.GetLength().Stu_score) stuList.InsertNode(newNode, stuList.GetLength()+1); else for (int i = 1; i =st

23、uList.GetLength (); i+) if (newNode.Stu_score =(stuList.SearchNode(i).Stu_score) stuList.InsertNode(newNode, i); break; Console.Write(还有学生成绩输入吗(Y/N):); flag = Convert.ToChar(Console.ReadLine(); while (flag = Y); break; /*按学号删除学生的成绩*/ case 2: StuNode temp; Console.Write(请输入要删除学生的学号:); string stu_no =

24、 Console.ReadLine(); for (int i = 1; i = stuList.GetLength (); i+) temp=stuList.SearchNode(i); if (temp.Stu_no = stu_no) stuList.DeleteNode(i); break; break; /*按姓名查询学生成绩*/ case 3: StuNode temp; Console.Write(请输入要查询的学生姓名:); string stu_name = Console.ReadLine(); for (int i = 1; i = stuList.GetLength (

25、); i+) temp = stuList.SearchNode(i); if (temp.Stu_name = stu_name) Console.WriteLine(0的成绩是:1, stu_name, temp.Stu_score); break; break; /*按学号查询学生成绩*/ case 4: StuNode temp; Console.Write(请输入要查询的学生学号:); string stu_no = Console.ReadLine(); for (int i = 1; i = stuList.GetLength (); i+) temp = stuList.Sea

26、rchNode(i); if (temp.Stu_no = stu_no) Console.WriteLine(学号为0的成绩是:1, stu_no, temp.Stu_score); break; break; /*按升序显示所有的学生的成绩*/ case 5: StuNode temp = null; for (int i = 1; i =1; i-) temp = stuList.SearchNode(i); Console.WriteLine(0t1t2, temp.Stu_no, temp.Stu_name, temp.Stu_score); break; /*退出应用程序*/ case 7: return; Console.Write(按任意键继续.); Console.ReadLine(); 15

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