




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C+课程设计参考程序源码main.cpp#include student.h/* 课程设计题目:学生信息管理系统 班级:0601 学号:200605112 姓名:xxx */使用链表存储学生数据链式存储int main() Student s; char i=9; s.showMenu(); couti; system(cls); /清除屏幕 s.showMenu(); s.doMenu(i); s.showTip(); link.h#ifndef LINK_H_INCLUDED#define LINK_H_INCLUDED#include#include#include#include #include#includeusing namespace std;/结点类,用于存放学生的各种数据class Nodepublic: int id; /学号 string name; /姓名 Node *next; /指向下一结点的指针 Node(int nid=0,string nname=noname);/构造函数,初始化变量;/Link类,把数据以链表的形式存储,链表的每个结点为一个Node对象class Linkprivate: Node *head; /链表的头指针,为Node对象类型的指针public : Link();/构造函数,初始化变量 bool linkIsEmpty();/判断链表是否为空 void linkInsert(Node *newnode);/向链表中插入新的结点 bool linkDelete(int nid);/从链表中删除的结点 void linkClear();/清空链表中数据 void linkView();/查看链表中数据 Node* linkFind(int nid);/在链表中查找id为nid结点,返回指向该结点的指针 Node* getHead();/获取头指针;#endif / LINK_H_INCLUDEDlink.cpp#include link.hNode:Node(int nid,string nname) id=nid; name=nname; next=NULL;Link:Link() /构造函数,初始化链表为空 head=NULL;bool Link:linkIsEmpty() /判断链表是否为空,空则返回true return(head=NULL);void Link:linkInsert(Node *newnode) /按id值从小到大的顺序,插入新的结点 Node *p1; if(!head)/链表为空的情况 head=newnode; else if(head-id)(newnode-id) /插入到第一个结点的情况 newnode-next=head; head=newnode; else /插入到第二个及以后情况 p1=head; while(1) if(!(p1-next) p1-next=newnode; break; else if(p1-next)-idnewnode-id) newnode-next=p1-next; p1-next=newnode; break; p1=p1-next; bool Link:linkDelete(int nid) /删除结点,成功则返回true Node *p; if(head=NULL)/链表为空的情况 return false; if(head-id=nid) /删除的为第一个结点的情况 head=head-next; return true; p=head; while(p-next) /删除的为第二个及以后结点的情况 if(p-next)-id=nid) p-next=(p-next)-next; return true; p=p-next; return false;void Link:linkClear() /清空链表 head=NULL;Node* Link:linkFind(int nid) /查找id值为nid的结点,返回该结点的指针 Node *p=head; /没找到符合条件的结点的话,返回的指针值为NULL while(p) if(p-id=nid) break; else p=p-next; return p;void Link:linkView() /显示链表数据 Node *p=head; coutsetw(6)学号 setw(10)姓名endl; while(p) coutsetw(6)id setw(10)namenext; Node* Link:getHead() return head;student.h#ifndef STUDENT_H_INCLUDED#define STUDENT_H_INCLUDED#include link.h/类Student,用于包装Link类及菜单操作class Studentprivate: Link slink;/Link对象成员 bool k;/记录数据是否被修改public: Student(); void studentClear(); void studentInsert(); void studentDelete(); void studentFind(); void studentView(); void studentLoad(); void studentSave(); void Exit();/退出程序 void showMenu();/显示菜单 void showTip();/显示操作提示 void doMenu(char n);/执行相应菜单项功能;#endif / STUDENT_H_INCLUDEDstudent.cpp#include student.hStudent:Student() Link();/调用成员对象的构造函数 studentLoad();/从文件中读取数据,创建链表 k=false;/设置数据被修改void Student:studentClear() /清空学生记录 slink.linkClear(); cout成功清空学生记录!endl;void Student:studentInsert() /插入学生记录 Node *p=new Node(); coutp-id; coutp-name; if(!slink.linkFind(p-id) /判断学号是否存在 slink.linkInsert(p); k=true; else cout学号为id的学生已存在,插入失败!endl;void Student:studentDelete() /删除学生记录 int i; if(slink.linkIsEmpty()/链表为空的情况 cout没有学生记录!endl; else couti; if(slink.linkDelete(i) cout成功删除学号为i的学生记录!endl; k=true; else cout没有找到学号为i的学生!endl; void Student:studentFind() /查找某学号的学生记录 int n; Node *p; if(slink.linkIsEmpty()/链表为空的情况 cout没有学生记录!endl; else coutn; p=slink.linkFind(n);/获得找到的结点的指针 if(p) /指针值不为NULL时 coutsetw(6)学号 setw(10)姓名endl; coutsetw(6)id setw(10)nameendl; else/指针值为NULL时 cout没有找到学号为n的学生记录!endl; void Student:studentView() /显示所有学生的记录 if(slink.linkIsEmpty() cout没有学生记录!endl; else slink.linkView();void Student:studentLoad() /从文件中读入数据,创建链表 Node *p; int nid; ifstream infile(data.txt); if(!infile) cerrnid) /读取学号,直到读空 p=new Node(); p-id=nid; infilep-name;/读取姓名 slink.linkInsert(p); infile.close(); /关闭文件void Student:studentSave() /将数据保存到文件 Node *p=slink.getHead(); ofstream outfile(data.txt); if(!outfile) cerr错误:数据文件不能打开!n; else while(p) outfileid namenext; k=false; cout保存成功!endl; void Student:Exit() char s=Y; if(k) /判断数据是否修改 couts; if(s=y|s=Y) studentSave(); cout已安全退出,; system(pause); exit(0);void Student:showMenu() cout|-|endl; cout| 学生信息管理系统 |endl; cout|-|endl; cout| 1.清空:清除所有学生数据 |endl; cout| 2.添加:插入一条学生数据 |endl; cout| 3.删除:删除指定学生数据 |endl; cout| 4.查找:查找指定学生数据 |endl; cout| 5.显示:显示所有学生数据 |endl; cout| 6.保存:保存所有学生数据 |endl; cout| 0.退出:安全的退出本系统 |endl; cout|-|endlendl;void Student:showTip() coutendl; cout-操作完成-endl; cout-选择05继续-endl; cout请选择:;void Student:doMenu(char n) switch(n) case 1:
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年高考生物三年高考真题及模拟题分类汇编专题12种群和群落含解析
- 再生障碍性贫血护理教学查房
- 家庭教育书分享
- 中医艾灸护理程序图解
- 国画动物美术课件
- 肿瘤科春季健康宣教内容
- 幼儿园睿思维培训
- 绿化工程造价培训
- 酒障病人的护理
- 2025年音乐产业音乐版权运营与音乐科技创新融合发展的技术创新报告
- 2025版国家开放大学法律事务专科《宪法学》期末考试总题库
- 【MOOC】融合新闻:通往未来新闻之路-暨南大学 中国大学慕课MOOC答案
- 电信总经理谈服务
- JGJT46-2024《施工现场临时用电安全技术标准》条文解读
- 防雷应急演练方案
- 半结构化面试题100题
- 第三章更好统筹发展和安全的途径和方法-国家安全教育大学生读本教案
- 房屋及相关设施零星维修工程施工方案
- 部编版四年级语文下册 期末词语成语专项复习【含答案】
- 2025年危险化学品经营单位安全管理人员上岗证考试题库(含答案)
- 2吨超纯水技术方案
评论
0/150
提交评论