职工管理系统(文件保存)
2017-02-06 16:09
274 查看
今天,做了一个通讯录的文件保存,然后拿了这个职工管理系统再熟悉一下,感觉和通讯录差不多,唯一有点不同的就是c++和Linux c对文件操作的不同了。感觉文件操作掌握的还行了,除了C语言自带的文件操作(还没有练习)。
#ifndef _CONTROL_H_
#define _CONTROL_H_
#include <iostream>
#include <string>
#include <fstream>
#include<windows.h>
using namespace std;
typedef struct node
{
string num; //职工号
string name; //名字
int age; //年龄
string x; //性别 f为女 m为男
string yobi; //邮编
string bum; //部门
int salary; //工资
struct node *next;
}Node;
typedef struct node * PNode;
class Control
{
public:
void jiemian(); //界面显示
void zhuce(); //注册职工
void xiugai(); //修改职工信息
void shanchu(); //删除职工信息
void chaxun(); //查询职工信息
void paiming(); //根据薪资排名
void pint(); //打印所有信息
};
#endif
#ifndef _CONTROL_H_
#define _CONTROL_H_
#include <iostream>
#include <string>
#include <fstream>
#include<windows.h>
using namespace std;
typedef struct node
{
string num; //职工号
string name; //名字
int age; //年龄
string x; //性别 f为女 m为男
string yobi; //邮编
string bum; //部门
int salary; //工资
struct node *next;
}Node;
typedef struct node * PNode;
class Control
{
public:
void jiemian(); //界面显示
void zhuce(); //注册职工
void xiugai(); //修改职工信息
void shanchu(); //删除职工信息
void chaxun(); //查询职工信息
void paiming(); //根据薪资排名
void pint(); //打印所有信息
};
#endif
#include "control.h" void Control::jiemian() { system("cls"); cout<<"\n\n\n"; cout<<"\t\t\t**************************************\n"; cout<<"\t\t\t* 欢迎来到职工管理系统 *\n"; cout<<"\t\t\t* 1 注册新职工 *\n"; cout<<"\t\t\t* 2 修改职工信息 *\n"; cout<<"\t\t\t* 3 删除职工信息 *\n"; cout<<"\t\t\t* 4 查询职工信息 *\n"; cout<<"\t\t\t* 5 薪资排名顺序 *\n"; cout<<"\t\t\t* 6 浏览所有信息 *\n"; cout<<"\t\t\t**************************************\n"; cout<<"\n\n\t\t请输入您的选择:"; } void Control::zhuce() { PNode p = new Node; system("cls"); cout<<"\n\n\n"; cout<<"\t\t\t请输入职工号:"; cin>>p->num; cout<<"\n\t\t\t请输入名字:"; cin>>p->name; cout<<"\n\t\t\t请输入年龄:"; cin>>p->age; cout<<"\n\t\t\t请输入性别:"; cin>>p->x; cout<<"\n\t\t\t请输入邮编:"; cin>>p-&g 4000 t;yobi; cout<<"\n\t\t\t请输入部门:"; cin>>p->bum; cout<<"\n\t\t\t请输入工资:"; cin>>p->salary; ofstream out; out.open("职工档案.txt", ios::out | ios::app); if(!out) { cerr<<"open error!"<<endl; return; } out.write((char*)p, sizeof(Node)); out.close(); } void Control::xiugai() { string str1; int flag = 0; system("cls"); cout<<"\n\n\n"; cout<<"\t\t\t请输入要修改人的职工号:"; cin>>str1; ifstream in; in.open("职工档案.txt", ios::in | ios::_Nocreate); if(!in) { cerr<<"open error!"<<endl; return; } PNode h = new Node; PNode p = new Node; if(in.read((char*) p, sizeof(Node))) { h->next = p; while(1) { PNode t = new Node; if (in.read((char*) t, sizeof(Node))) { p->next = t; p = p->next; continue; } else { p->next = h; break; } } } else { cout<<"\n\n\n\n\n\n\t\t\t\t系统中暂时无人!"<<endl; in.close(); return; } in.close(); PNode temp = h->next; while(temp != h) { if(temp->num == str1) { flag = 1; cout<<"\n\t\t\t请输入修改后的名字:"; cin>>temp->name; cout<<"\n\t\t\t请输入修改后的年龄:"; cin>>temp->age; cout<<"\n\t\t\t请输入修改后的性别:"; cin>>temp->x; cout<<"\n\t\t\t请输入修改后的邮编:"; cin>>temp->yobi; cout<<"\n\t\t\t请输入修改后的部门:"; cin>>temp->bum; cout<<"\n\t\t\t请输入修改后的薪资:"; cin>>temp->salary; break; } temp = temp->next; } if (flag) { Sleep(2); system("cls"); cout<<"\n\n\n\n\n\n\t\t\t\t修改成功!"<<endl; } else { Sleep(2); system("cls"); cout<<"\n\n\n\n\n\n\t\t\t\t查无此人!"<<endl; return; } remove("职工档案.txt"); ofstream out; out.open("职工档案.txt", ios::out | ios::app); if(!out) { cerr<<"open error"<<endl; return; } temp = h->next; while (temp != h) { out.write((char*)temp, sizeof(Node)); temp = temp->next; } out.close(); } void Control::shanchu() { system("cls"); string str1; int flag = 0; cout<<"\n\n\n"; cout<<"\t\t\t请输入要删除人的职工号:"; cin>>str1; ifstream in; in.open("职工档案.txt", ios::in | ios::_Nocreate); if(!in) { cerr<<"open error!"<<endl; return; } PNode h = new Node; PNode p = new Node; if(in.read((char*) p, sizeof(Node))) { h->next = p; while(1) { PNode t = new Node; if (in.read((char*) t, sizeof(Node))) { p->next = t; p = p->next; continue; } else { p->next = h; break; } } } else { cout<<"\n\n\n\n\n\n\t\t\t\t系统中暂时无人!"<<endl; in.close(); return; } in.close(); PNode temp = h; if(temp->next->next == h) //一个结点的表 { if(temp->next->num == str1) { PNode tmp = temp->next; temp->next = h; delete tmp; remove("职工档案.txt"); ofstream outfile; outfile.open("职工档案.txt", ios::out); outfile.close(); system("cls"); cout<<"\n\n\n\n\n\n\t\t\t\t删除成功!"<<endl; return; } else { system("cls"); cout<<"\n\n\n\n\n\n\t\t\t\t查无此人!"<<endl; return; } } while (temp->next != h) { if (temp->next->num == str1) { flag = 1; PNode p = temp->next; temp->next = p->next; free(p); break; } temp = temp->next; } if(flag) { system("cls"); cout<<"\n\n\n\n\n\n\t\t\t\t删除成功!"<<endl; } else { system("cls"); cout<<"\n\n\n\n\n\n\t\t\t\t查无此人!"<<endl; return; } remove("职工档案.txt"); ofstream out; out.open("职工档案.txt", ios::out | ios::app); if(!out) { cerr<<"open error"<<endl; return; } temp = h->next; while (temp != h) { out.write((char*)temp, sizeof(Node)); temp = temp->next; } out.close(); } void Control::chaxun() { system("cls"); string str1, str2; int flag = 0; cout<<"\n\n\n"; cout<<"\t\t\t请输入要查询的职工号:"; cin>>str1; cout<<"\n\n\t\t\t请输入要查询的名字:"; cin>>str2; ifstream in; in.open("职工档案.txt", ios::in | ios::_Nocreate); if(!in) { cerr<<"open error!"<<endl; return; } PNode h = new Node; PNode p = new Node; if(in.read((char*) p, sizeof(Node))) { h->next = p; while(1) { PNode t = new Node; if (in.read((char*) t, sizeof(Node))) { p->next = t; p = p->next; continue; } else { p->next = h; break; } } } else { cout<<"\n\n\n\n\n\n\t\t\t\t系统中暂时无人!"<<endl; in.close(); return; } in.close(); PNode temp = h->next; while (temp != h) { if(temp->num == str1 && temp->name == str2) { flag = 1; cout<<"\n\n年龄:"<<temp->age<<" 性别:"<<temp->x<<" 邮编:"<<temp->yobi<<" 部门:" <<temp->bum<<" 薪资:"<<temp->salary<<endl; break; } temp = temp->next; } if (flag == 0) { Sleep(2); system("cls"); cout<<"\n\n\n\n\n\n\t\t\t\t查无此人!"<<endl; } } void Control::paiming() { ifstream in; in.open("职工档案.txt", ios::in | ios::_Nocreate); if(!in) { cerr<<"open error!"<<endl; return; } PNode h = new Node; PNode p = new Node; if(in.read((char*) p, sizeof(Node))) { h->next = p; while(1) { PNode t = new Node; if (in.read((char*) t, sizeof(Node))) { p->next = t; p = p->next; continue; } else { p->next = h; break; } } } else { cout<<"\n\n\n\n\n\n\t\t\t\t系统中暂时无人!"<<endl; in.close(); return; } in.close(); PNode temp, max, n, m; int i = 0; n = h; m = max = h->next; while (n->next != h) //大循环,控制循环次数// { temp = h->next; //temp为下面找最大值的前节点所用,赋初值// for (m = n->next; m != h; m = m->next) //小循环,依次找出当前最大值// { if (max->salary > m->salary) { max = m; } } while(temp->next != max) { temp = temp->next; } temp->next = max->next; max->next = h->next; h->next = max; if(i == 0) { n = max; } max = n->next; i++; } remove("职工档案.txt"); ofstream out; out.open("职工档案.txt", ios::out | ios::app); if(!out) { cerr<<"open error"<<endl; return; } temp = h->next; while (temp != h) { out.write((char*)temp, sizeof(Node)); temp = temp->next; } out.close(); pint(); } void Control::pint() { system("cls"); cout<<"\n\n\n"; ifstream in; in.open("职工档案.txt", ios::in | ios::_Nocreate); if(!in) { cerr<<"open error!"<<endl; return; } PNode h = new Node; PNode p = new Node; if(in.read((char*) p, sizeof(Node))) { h->next = p; while(1) { PNode t = new Node; if (in.read((char*) t, sizeof(Node))) { p->next = t; p = p->next; continue; } else { p->next = h; break; } } } else { cout<<"\n\n\n\n\n\n\t\t\t\t系统中暂时无人!"<<endl; in.close(); return; } PNode temp = h->next; while (temp != h) { cout<<"职工号:"<<temp->num<<" 名字:"<<temp->name<<" 年龄:"<<temp->age<<" 性别:"<<temp->x <<" 邮编:"<<temp->yobi<<" 部门:"<<temp->bum<<" 薪资:"<<temp->salary<<endl; temp = temp->next; } in.close(); }
#include "control.h" int main() { Control con; char ecf; //选项 char sel[10]; while(1) { con.jiemian(); cin>>ecf; switch (ecf) { case '1': //注册新职工 { con.zhuce(); break; } case '2': //修改职工信息 { con.xiugai(); cout<<"\n\n\t\t输入任意键返回:"; cin>>sel; break; } case '3': //删除职工信息 { con.shanchu(); cout<<"\n\n\t\t输入任意键返回:"; cin>>sel; break; } case '4': //查询职工信息 { con.chaxun(); cout<<"\n\n\t\t输入任意键返回:"; cin>>sel; break; } case '5': //薪资排名顺序 { con.paiming(); cout<<"\n\n\t\t输入任意键返回:"; cin>>sel; break; } case '6': //浏览所有信息 { con.pint(); cout<<"\n\n\t\t输入任意键返回:"; cin>>sel; break; } default: { system("cls"); cout<<"\n\n\n\n\n请输入1--6!"<<endl; cout<<"\n\n\t\t输入任意键返回:"; cin>>sel; break; } } } return 0; }
相关文章推荐
- [零基础学JAVA]Java SE实战开发-37.MIS信息管理系统实战开发[文件保存](1) 推荐
- Python备份文件、文件版本的学生管理系统如何实现(将数据保存在txt文件中)
- [零基础学JAVA]Java SE实战开发-37.MIS信息管理系统实战开发[文件保存](2) 推荐
- 学生管理系统----文件和数据库(oracle)两种保存数据方式
- 管理windows系统中保存的文件服务器账号密码
- 【Linux 入门笔记】文件系统挂载管理
- vs2005视频教程 之 文件管理系统(一)视频教程[视频]
- [Linux]八,文件系统管理
- 职工管理系统 ——静态数组实现
- linux 文件系统的管理 (硬盘)
- linux 学习之九、Linux 磁盘与文件系统管理(1)
- 学生信息管理系统V0.2(使用文件存储数据)【MVC模式、DAO模式、Factory模式】
- Linux 文件系统管理之一
- Linux的磁盘与文件管理系统(1)
- AIX文件系统基本之逻辑元管理概念
- 文件管理系统(JQuery插件+Ajax)
- Android内核与标准Linux内核在文件系统、进程间通信机制、内存管理等方面存在不同
- Linux 文件系统管理之二
- 文件系统的管理方法和xfs文件系统备份恢复