




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 八年级物理上册 1.6《乐音和噪声》说课稿 北京课改版
- 2024-2025学年新教材高中语文 第二单元 6.2 文氏外孙入村收麦说课稿(3)部编版必修上册
- 2024-2025学年高中物理 第四章 机械能和能源 第7节 功率说课稿2 粤教版必修2
- 人教版历史与社会八年级下册第八单元第二课洋务运动与近代民族工业的发展第一课时洋务运动说课稿设计
- 2023三年级英语下册 Unit 2 Are you Lingling第1课时说课稿 湘少版
- 中国联通红河自治州2025秋招笔试行测题库及答案网络优化与维护类
- 中国广电中山市2025秋招笔试行测题库及答案财务审计类
- 第7课《散文诗二首-荷叶·母亲》说课稿 统编版语文七年级上册
- 海南安全员培训地点课件
- 1北京的春节 教学设计-语文六年级下册统编版
- 经济学研究生组会文献汇报
- 智能化凝点试验系统多源数据融合的异构接口标准化难题及解决方案
- 防滑跌安全培训课件
- 2025年山东省青岛市中考英语试卷附答案
- 2025职业病诊断化学中毒试题及答案
- 驾照体检表完整版本
- 磁保持继电器基础知识课件
- 安全生产区域管理办法范本
- 设备保管协议
- 中石油职称英语通用教材
- 焊接质量手册
评论
0/150
提交评论