




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include #include #include #include #include #include class CSalary private:char szName20; /姓名double dlSalary; /工资public:CSalary(); /默认构造CSalary(char *name,double salary); / 构造函数void SetSalary(char *name,double salary); /置工资与姓名double GetSal(); /返回工资int Compare(const CSalary &other); /比较姓名,供查找用bool Find(char *name); /寻找名字void Show(ostream &os = cout); ;class CNode /定义节点类private:CSalary *pData;/用于指向数据类的指针CNode *pNext; /指向链表的指针public:CNode()pData = NULL; pNext = NULL; /节点构造函数CNode(const CNode &node)pData = node.pData; pNext = node.pNext; /用于拷贝的构造函数void InputData(CSalary *pSal)pData = pSal; /输入数据void ShowNode(ostream &os = cout)pData-Show(os); /显示CSalary *GetData()return pData;friend class CList; /定义 链表类的友元类;class CList /定义链表类protected:CNode *pHead; /链表头结点指针int num;public:CList()pHead = NULL;num = 0; /链表构造函数CList()DeleteList(); /链表的析构函数void AddNode(CNode *pnode); /在首部添加结点CNode *DeleteNode(CNode *pnode); /删除一个指定的结点,返回该结点的指针CNode *LookUp(CSalary &other); /查找一个指定的数据,返回该数据所在结点的链表中的指针void ShowList(ostream &os = cout); /打印整个链表void DeleteList(); /删除整个链表CNode *GetListHead(); /返回链表的首结点CNode *GetListNextNode(CNode *pnode); /返回链表的指定结点的下一个结点void Insert(CNode *pnode); /按工资顺序插入节点CSalary *Exist(char *name); /该员工信息;static char str256;/* CSalary的函数 */CSalary:CSalary() /默认构造函数strcpy (szName,0); dlSalary = 0.0;CSalary:CSalary(char *name,double salary) /构造函数strcpy (szName,name);dlSalary = salary;void CSalary:SetSalary(char *name,double salary) / 置姓名与工资的函数strcpy (szName,name);dlSalary = salary;bool CSalary:Find(char *name) /用于查找是否有此人函数if (strcmp (szName,name) = 0)return true;elsereturn false;double CSalary:GetSal() /返回工资的函数return dlSalary;void CSalary:Show(ostream &os) /输出工资信息os szName t other.dlSalary ? 1 : -1;elsereturn strcmp (szName,other.szName);/* 链表的函数 */ void CList:AddNode(CNode *pnode) /增加节点CNode *temp = pHead;pnode-pNext = temp;pHead = pnode;num +;CNode *CList:DeleteNode(CNode *pnode) /删除节点CNode *temp = pHead;if (temp = pnode)pHead = pHead-pNext;delete temp-pData;delete temp;num -;return pnode;while (temp != NULL)if (temp-pNext = pnode)delete temp-pNext-pData;temp-pNext = pnode-pNext;delete pnode;num -;return pnode;temp = temp-pNext;return NULL;CNode *CList:LookUp(CSalary &other) /查找一个指定的数据,返回该数据所在结点的链表中的指针CNode *temp = pHead;while (temp != NULL)if (temp-pData-Compare(other) = 0)return temp;temp = temp-pNext;return NULL;void CList:ShowList(ostream &os) / 显示整个链表CNode *temp = pHead;while (temp != NULL)temp-pData-Show(os);os pNext;void CList:DeleteList() /删除链表CNode *temp = pHead;while (temp != NULL)pHead = pHead-pNext;delete temp-pData;delete temp;temp = pHead;pHead = NULL;CNode *CList:GetListHead() /返回链表首节点 return pHead;CNode *CList:GetListNextNode(CNode *pnode)return pnode-pNext;void CList:Insert(CNode *pnode) /按工资顺序插入节点CNode *temp = pHead;if (pHead = NULL)AddNode(pnode);return;if (pHead-pData-Compare(*(pnode-pData) 0)AddNode(pnode);return;while (temp-pNext != NULL)if (temp-pNext-pData-Compare(*(pnode-pData) 0)pnode-pNext = temp-pNext;temp-pNext = pnode;num +;return;temp = temp-pNext;temp-pNext = pnode;pnode-pNext = NULL;num +;CNode *MakeList(char *name,double salary) /创建出一个链表CNode *p = new CNode;CSalary *pp = new CSalary;pp-SetSalary(name,salary);p-InputData(pp);return p;CSalary *CList:Exist(char *name) /链表,该员工信息CNode *temp = pHead;while (temp != NULL)if (temp-pData-Find(name)return temp-pData;temp = temp-pNext;return NULL;/* 主函数 */int main()CList head;CNode *temp;CSalary *one;fstream fin;fstream fout;char file1256,file2256;char name24;double salary;char str256;cout 文件读入,请选择(Y/y) endl;cin.getline(str,256);if (strcmp (str,Y) & strcmp (str,y) /判断输入的选择是否有错return 0;if (!(strcmp (str,Y) & strcmp (str,y) /读入文件内信息cout 输入文件名:;cin.getline(file1,256);fin.open(file1,ios:in|ios:nocreate|ios:binary);if (!fin) /判断文件存在性cout 没有该文件。 name salary;if (head.Exist(name) != NULL)continue;temp = MakeList(name,salary);head.Insert(temp);cout 操作成功。 endl;fin.close(); system(pause); /暂停while (!(strcmp (str,Y) & strcmp (str,y) /菜单选择bool flag = true;int i; system(cls); /清屏cout 1.添加 endl;cout 2.显示 endl;cout 3.查询 endl;cout 4.修改 endl;cout 5.删除 endl;cout 0.退出 i; if(!cin.good() /判断输入问题,如字母等 char str1100; cin.clear(); cin.getline(str1,100); cout 输入错误,请重新输入 endl; system(pause); continue; if(i5) /判断输入非规定数字 char str1100; cin.clear(); cin.getline(str1,100); cout 输入错误,请重新输入 endl; system(pause); continue; char buffer124; /用于清除读取缓冲区内容switch (i)case 1: cin.getline(buffer1,24);cout 请输入要添加的人的姓名(输0为结束):;cin.getline(name,24);if (strcmp (name,0) = 0)break;if (head.Exist(name) != NULL)cout name 已存在,再次输入无效。 endl; system(pause); continue;cout salary;temp = MakeList(name,salary);head.Insert(temp);cout 已添加完毕。 endl;system(pause); break; case 2: head.ShowList();system(pause);break;case 3:cin.getline(buffer1,24);cout 输入你要查询的姓名:;cin.getline(name,24);one = head.Exist(name);if (one = NULL)cout 无此人信息。 ShowNode();cout endl;system (pause);break;case 4: cin.getline(buffer1,24);cout 输入你要修改的姓名:;cin.getline(name,24);one = head.Exist(name);if (one = NULL)cout 无此人信息。 endl;elsecout salary;while(!cin.good() /判断 char buffer80; cout错误,重新输入 salary; cin.getline(buffer1,24); cout 确定要修改吗?(Y/y) endl;cin.getline(buffer1,24);if (strcmp (buffer1,Y) & strcmp (buffer1,y) break; temp = head.LookUp(*one);head.DeleteNode(temp);temp = MakeList(name,salary);head.Insert(temp);cout 信息已经修改 endl;system(pause); break;case 5: cin.getline(buffer1,24);cout 输入你要删除的姓名:;cin.getline(name,24);one = head.Exist(name);if (one = NULL)cout 无此人信息。 endl;elsecout 确定要删除吗?(Y/y) endl;cin.getline(str,256);if (strcmp (str,Y) & strcmp (str,y) break; temp = head.LookUp(*one);head.DeleteNode(temp);cout 信息已经删除 endl;system(pause);break;case 0:flag = false;break;def
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 森林碳汇评估方法-第1篇-洞察与解读
- 本土文化适配企业价值观-洞察与解读
- 2025年事业单位招聘考试综合类职业能力倾向测验真题模拟试卷:语文写作与阅读
- 2025年事业单位招聘考试综合类职业能力倾向测验真题模拟试卷(渔业)
- 2025年度随州市招募选派三支一扶高校毕业生考前自测高频考点模拟试题及答案详解(易错题)
- 2025年上海市事业单位招聘考试综合类专业知识试卷及答案
- 2025年甘肃省张掖市市直医疗卫生单位招聘专业技术人员模拟试卷及答案详解(夺冠)
- 机器人替代与效率关系-洞察与解读
- 动态封装力学分析-洞察与解读
- 河南中招备考试卷及答案
- 康复第三期品管圈甘特
- 医院运营管理工作汇报
- 病理检查报告审核制度
- 水土保持方案投标文件技术部分
- 《数据库系统概论》全套课件(南京农业大学)
- 建行秋招历年考试试题及答案2024
- 2024秋季新教材人教版体育与健康一年级上册课件:1我们爱运动
- 大型展会突发事件应急预案
- 中考英语1600核心词汇
- 广东省茂名市2023-2024学年高一上学期数学期中试卷(含答案)
- 英国海德公园
评论
0/150
提交评论