| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3249 人关注过本帖
标题:C++ 职工信息管理系统(代源码)
只看楼主 加入收藏
gdzhan
Rank: 2
等 级:论坛游民
帖 子:90
专家分:14
注 册:2007-4-15
结帖率:66.67%
收藏
 问题点数:0 回复次数:8 
C++ 职工信息管理系统(代源码)
新手,,,,刚看完C++ PRIMER PLUS,,,对文件处理不太会,,还有个删除功能实现不了,
请看过的师傅帮偶提个好点的算法,,谢谢了,, 还有我这用的是不是面向对像的编程阿,^_^
菜鸟没办法了



// Employee.h

#ifndef _EMPLOYEE_H
#define _EMPLOYEE_H

#include <cstring>

/////////////////////////////////////////////////////////////////
//emp命名空间包含员工类定义
namespace emp
{
class Employee
{
private:
enum {MAXEMP = 20};

char empname[MAXEMP]; //员工姓名
char empnumber[MAXEMP]; //员工编号
char empdepart[MAXEMP]; //所属部门
char empgrade[MAXEMP]; //员工级别
long empold; //员工年龄

Employee(const Employee &em) {} //不允许员工之间赋值
Employee& operator= (const Employee &em) {}

public: //对外接口
Employee();

void Input_Employee(); //录入数据
void View_Employee(); //显示数据
//获取员工信息
char* getempname();
char* getempnumber();
char* getempdepart();
char* getempgrade();
long getempold();
};
}

#endif
-----------------------------------------------------------------
// Employee.cpp

#include <iostream>
#include <cstring>
#include "Employee.h"

///////////////////////////////////////////////////
// 员工类接口实现
namespace emp
{
using std::cout;
using std::endl;
using std::cin;
using std::ios_base;

//////////////////////////////////////////////////
// 初始化员工元素
Employee::Employee()
{
empname[0] = '\0';
empnumber[0] = '\0';
empdepart[0] = '\0';
empgrade[0] = '\0';
empold = 0L;
}

/////////////////////////////////////////////////
// 输入员工信息
void Employee::Input_Employee()
{
cout << "员工姓名: ";
cin.getline (empname, MAXEMP - 1);
cout << "员工编号: ";
cin.getline (empnumber, MAXEMP - 1);
cout << "员工所属部门: ";
cin.getline (empdepart, MAXEMP - 1);
cout << "员工级别: ";
cin.getline (empgrade, MAXEMP - 1);
cout << "员工年龄: ";
if (cin >> empold)
{
while (cin.get() != '\n')
continue;
return;
}
else
{
cin.clear();
while (cin.get() != '\n')
continue;
return;
}
}

/////////////////////////////////////////////////
// 显示员工信息

void Employee::View_Employee()
{
cout << "员工姓名: " << getempname() << endl;
cout << "员工编号: " << getempnumber() << endl;
cout << "员工所属部门: " << getempdepart() << endl;
cout << "员工级别: " << getempgrade() << endl;
cout << "员工年龄: " << getempold() << endl;
}

//////////////////////////////////////////////////
// 获取员工元素
char* Employee::getempname()
{
return empname;
}

char* Employee::getempnumber()
{
return empnumber;
}

char* Employee::getempdepart()
{
return empdepart;
}

char* Employee::getempgrade()
{
return empgrade;
}

long Employee::getempold()
{
return empold;
}
}
搜索更多相关主题的帖子: 信息管理系统 源码 职工 
2007-07-31 19:38
gdzhan
Rank: 2
等 级:论坛游民
帖 子:90
专家分:14
注 册:2007-4-15
收藏
得分:0 
// Database.h -- 员工数据库类定义

#ifndef _DATABASE_H
#define _DATABASE_H

#include <iostream>
#include <fstream>
#include "Employee.h"

/////////////////////////////////////////////////////
// emp包含数据库类
namespace emp
{
class Database
{
private:
static const int maxemployee = 5 ; //数据库最大容纳员工

Employee employee[maxemployee];

public:
Database();

void CreateDatabase(); //建立数据库
void Input_Database(); //录入数据库
void Mod_Database(); //修改数据库
void Sea_Database(); //搜索数据库
void Del_Database(); //删除数据库指定数据
void Show_Database(); //显示数据库所有内容
};
}

#endif
--------------------------------------------------------------------


2007-07-31 19:39
gdzhan
Rank: 2
等 级:论坛游民
帖 子:90
专家分:14
注 册:2007-4-15
收藏
得分:0 
// Database.cpp

#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
#include <windows.h> //Sleep()
#include "Database.h"

int index = 0;

namespace emp
{
using std::cout;
using std::endl;
using std::cin;
using std::cerr;
using std::vector;
using std::ios_base;
using std::ifstream;
using std::fstream;
using std::ofstream;

////////////////////////////////////////////
// 初始化数据库
Database::Database()
{
}

/////////////////////////////////////////////
// 建立员工数据库
void Database::CreateDatabase()
{
system ("cls");
cout << "正在建立员工数据库,这可能要花费几分钟,请稍后";
for (size_t i = 0; i <= 5; i++)
{
Sleep (800);
cout << ".";
}
ofstream outfile;
outfile.open ("c:\\EmployeeDatabase.dat", ios_base::out | ios_base::binary);

if (!outfile.is_open())
{
cerr << "\a建立员工数据库失败,请检察其它故障!" << endl;
cout << "------------------------------------" << endl;
for (size_t i = 1; i <=5; i++)
{
Sleep (800);
cout << "5秒将自动退出! " << "[" << i++ << "]" << "\r";
}
exit(1);
}
cout << endl << "建立员工数据库成功!";
Sleep (800);
outfile.close();
outfile.clear();
system ("cls");
return;
}


////////////////////////////////////////////
// 录入员工数据库
void Database::Input_Database()
{
system ("cls");

fstream iofile;
iofile.open ("c:\\EmployeeDatabase.dat", ios_base::in | ios_base::binary);

if (!iofile.is_open())
{
cerr << "\a链接员工数据库失败,请确认已成功建立数据库!";
cin.get();
system ("cls");
return ;
}
else
{
cout << "正在链接到数据库,请稍后";
for (size_t i = 0; i <= 5; i++)
{
Sleep(800);
cout << ".";
}
cout << endl;
cout << "已成功链接到数据库!" << endl;
iofile.seekg(0);
while (iofile.read ((char *) &employee[index], sizeof (Employee)))
{
index++;
}
iofile.close();
iofile.clear();

if (index >= maxemployee)
{
cout << "数据库记录已满!";
cin.get();
system ("cls");
return ;
}

iofile.open ("c:\\EmployeeDatabase.dat", ios_base::out | ios_base::app
| ios_base::binary);

cout << "--------------------" << endl;
cout << " 员工信息登记表" << endl;
cout << "--------------------" << endl;
while (index < maxemployee)
{
employee[index].Input_Employee();
iofile.write((char *) &employee[index], sizeof (Employee));
cout << "录入下一位(y/n): ";
char ch;
cin.get(ch).get();
if ('y' == ch)
index++;
else
break;
}
iofile.close();
iofile.clear();
system ("cls");
}
}

///////////////////////////////////////////////
// 修改数据库内容
void Database::Mod_Database()
{
system ("cls");

fstream iofile;
iofile.open ("c:\\EmployeeDatabase.dat", ios_base::in
| ios_base::out | ios_base::binary);

if (!iofile.is_open())
{
cerr << "链接员工数据库失败,请确认已成功建立数据库!";
cin.get();
system ("cls");
return ;
}
else
{
cout << "正在链接数据库,请稍后";
for (size_t i = 0; i < 5; i++)
{
Sleep(800);
cout << ".";
}
cout << endl;
cout << "已成功链接到数据库!" << endl;
cout << "请输入需要修改的员工姓名: ";
char name[20];
cin.getline(name, 19);
int index = 0; //在数据库中定位文件位置
iofile.seekg(0);
while (iofile.read ((char *) &employee[index], sizeof (Employee)))
{
if (!strcmp (name, employee[index].getempname()))
{
iofile.close();
iofile.clear();

iofile.open ("c:\\EmployeeDatabase.dat", ios_base::out | ios_base::in
| ios_base::binary);

iofile.seekp (index * sizeof (Employee), ios_base::beg);
cout << "请重新输入数据!" << endl;
employee[index].Input_Employee();
iofile.write ((char *) &employee[index], sizeof (Employee));
cout << "修改成功! " << endl;
iofile.close();
iofile.clear();
cin.get();
system ("cls");
return ;
}
index++;
}
iofile.close();
iofile.clear();
cout << "在数据库没有搜索到" << name << "的相关信息" << endl;
cin.get();
system ("cls");
return ;
}
}

////////////////////////////////////////////////
// 搜索指定员工的相关信息
void Database::Sea_Database()
{
system ("cls");
ifstream infile;
infile.open ("c:\\EmployeeDatabase.dat", ios_base::in | ios_base::binary);

if (!infile.is_open())
{
cerr << "链接员工数据库失败,请确认已成功建立数据库!";
cin.get();
system ("cls");
return ;
}
else
{
cout << "正在链接员工数据库,请稍后";
for (size_t i = 0; i < 5; i++)
{
Sleep(800);
cout << ".";
}
cout << endl;
cout << "已成功链接到员工数据库!" << endl;
cout << "请输入需要搜索的关建字(姓名有关): ";
char name[20];
cin.getline (name, 19);
name[19] = '\0';
int index = 0;
int fcount = 1;
vector <int> count; //记录搜索到的员工个数
infile.seekg(0);
while (infile.read ((char *) &employee[index], sizeof (Employee)))
{
if (strstr (employee[index].getempname(), name))
{
count.push_back(index); //保存搜索到的下标
cout << "当前搜索到 " << "[ " << fcount++ << " ]"
<< " 条与" << name << "的相关信息!" << "\r";
index++;
Sleep(500); //休眠一会
continue;
}
index++;
}
infile.close();
infile.clear();
if (fcount == 1)
{
cout << "没有搜索到与" << name << "的相关信息!" << endl;
cin.get();
system ("cls");
return ;
}
else
{
cout << endl << "----------------------------------" << endl;
for (vector<int>::iterator p = count.begin(); p != count.end(); p++)
{
employee[*p].View_Employee();
}
cin.get();
system ("cls");
return ;
}
}
}

///////////////////////////////////////////////////////
// 删除数据库指定的员工信息
void Database::Del_Database()
{
system ("cls");
fstream iofile;
iofile.open ("c:\\EmployeeDatabase.dat", ios_base::in | ios_base::out
| ios_base::binary);

if (!iofile.is_open())
{
cerr << "不能链接到员工数据库,请确认已成功建立!";
cin.get();
system ("cls");
return ;
}
else
{
cout << "正在链接员工数据库,请稍后";
for (size_t i = 0; i < 5; i++)
{
Sleep (800);
cout << ".";
}
cout << endl <<"已成功链接到员工数据库!" << endl;
iofile.seekg(0);
cout << "请输入要删除的员工姓名:";
char name[20];
cin.getline (name, 19);
int index = 0;
while (iofile.read ((char *) &employee[index], sizeof (Employee)))
{
if (!strcmp (name, employee[index].getempname()))
{
while (iofile)
{
iofile.seekg((index + 1) * sizeof (Employee));
if (!(iofile.read ((char *) &employee[index + 1], sizeof (Employee))))
{
iofile.close();
iofile.clear();
system ("cls");
return ;
}
iofile.seekp(index * sizeof (Employee));
iofile.write ((char *) &employee[index + 1], sizeof (Employee));
index++;
}
iofile.close();
iofile.clear();
system ("cls");
return ;
}
index++;
}
iofile.close();
iofile.clear();
cout << "数据库中没有搜索到" << name << "的相关信息!" << endl;
system ("cls");
return ;
}
}

//////////////////////////////////////////////////////
// 显示数所有数据库信息
void Database::Show_Database()
{
system ("cls");

ifstream infile;
infile.open ("c:\\EmployeeDatabase.dat", ios_base::in | ios_base::binary);

if (!infile.is_open())
{
cerr << "不能链接到员工数据库,请确认已成功建立!";
cin.get();
system ("cls");
return ;
}
else
{
cout << "正在链接数据库,请稍后";
for (size_t i = 0; i < 5; i++)
{
Sleep(800);
cout << ".";
}
cout << endl;
cout << "已成功链接到员工数据库!" << endl;
infile.seekg(0);
int index = 0;
cout << "------------------------------" << endl;
cout << " 以下是数据库搜索到的所有信息!" << endl;
cout << "------------------------------" << endl;
while (infile.read ((char *) &employee[index], sizeof (Employee)))
{
employee[index].View_Employee();
index++;
if (!(index % 3))
{
cout << "---------------------------" << endl;
system ("pause");
continue;
}
}
if (!index)
{
cout << "数据库没有文件,可能已损坏或不存在!";
infile.close();
infile.clear();
cin.get();
system ("cls");
return ;
}
}
infile.close();
infile.clear();
cin.get();
system ("cls");
return ;
}
}

2007-07-31 19:39
gdzhan
Rank: 2
等 级:论坛游民
帖 子:90
专家分:14
注 册:2007-4-15
收藏
得分:0 
// UserDatabase.h

#ifndef _USERDATABASE_H
#define _USERDATABASE_H

int System_UI();
void System_Menu();

#endif
-----------------------------------
// UserDatabase.cpp

#include <iostream>
#include "Database.h"

using namespace std;
using namespace emp;

//////////////////////////////////////////////////
// 提供用户操作界面
int System_UI()
{
cout << endl << endl << endl;
cout << " 职工信息管理系统v1.0 Bate 1测试版 " << endl;
cout << "========================================= " << endl;
cout << " 本系统不支持中文录入 " << endl;
cout << " 可以使用英文,拼音或助 " << endl;
cout << " 记词方法录入 !" << endl;
cout << endl << endl;
cout << " 1. 建立员工数据库 ( 请小心使用! ) " << endl;
cout << " 2. 员工个人信息登记" << endl;
cout << " 3. 修改单个员工信息" << endl;
cout << " 4. 搜索单个员工信息" << endl;
cout << " 5. 删除单个员工信息" << endl;
cout << " 6. 浏览所有数据库信息" << endl;
cout << " 7. 使用本系统帮助" << endl;
cout << " 8. 退出系统" << endl;
cout << "________________________----------------------" << endl;
cout << " 请正确选择: ";
int input;
while (cin >> input)
{
while (cin.get() != '\n')
continue;
return input;
}
cin.clear();
while (cin.get() != '\n')
continue;
return -1;
}

////////////////////////////////////////////////////////////////////
// 用户操作菜单
void System_Menu()
{
int in;
Database employee_obj;

while ((in = System_UI()) != 8)
{
switch (in)
{
case 1:
employee_obj.CreateDatabase();
break;
case 2:
employee_obj.Input_Database();
break;
case 3:
employee_obj.Mod_Database();
break;
case 4:
employee_obj.Sea_Database();
break;
case 5:
employee_obj.Del_Database();
break;
case 6:
employee_obj.Show_Database();
break;
case 7:
break;
default:
cout << "没有此选项!" << endl;
break;
}
}
}
--------------------------------------------------------------------
// TestEmployeeDatabase.cpp

#include <windows.h> //Sleep()
#include <iostream>
#include "UserDatabase.h"

using std::cout;
using std::endl;

int main()
{
System_Menu(); //用户界面

cout << "谢谢使用本系统"<< endl;
for (size_t i = 1; i <= 5; i++)
{
Sleep (800); //休眠
cout << "5秒钟将自动退出 "<< "[ " << i << " ]" << "\r";
}

return 0;
}




2007-07-31 19:40
gdzhan
Rank: 2
等 级:论坛游民
帖 子:90
专家分:14
注 册:2007-4-15
收藏
得分:0 

还是打个包吧,,太长了,,\

j7lDKkiN.rar (128.99 KB) C++ 职工信息管理系统(代源码)



2007-07-31 19:48
wingyip
Rank: 1
等 级:新手上路
威 望:2
帖 子:119
专家分:0
注 册:2007-7-16
收藏
得分:0 
哇 有沒有題目啊?

2007-08-02 09:37
hllj123
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-8-2
收藏
得分:0 
早点贴不就没那么辛苦了嘛....
2007-08-02 14:20
可是
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-10-27
收藏
得分:0 
谢谢了。。。有的参考的了。。。
2010-10-27 10:44
无情云
Rank: 1
等 级:新手上路
帖 子:22
专家分:7
注 册:2010-9-25
收藏
得分:0 
真的很好哦,我参考学习下,呵呵....
2010-10-28 13:32
快速回复:C++ 职工信息管理系统(代源码)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022884 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved