需求分析
该系统所应包含的信息有以下一些:
人员的基本信息:
编号、姓名、年龄、性别、职称等。
实现功能如下:
各种基本数据的录入。
各种基本数据的修改。即:允许对已经录入的数据重新进行编辑、修改。
例如修改信息栏中张三的基本信息
各种基本数据的删除。例如将张三的信息从信息栏中删除
基于各种数据的查询。
基于各种数据的统计。
数据导出:将信息栏中信息导出到指定文件。
数据导入:从指定文件导入信息到信息栏中。
系统环境:
采用C++语言实现,开发环境为Microsoft Visual Studio 2010,可以运行在操作系统windows10。
数据结构设计:
界面显示:
代码如下:
#include "stdafx.h"
#include "teacher.h"
#include "tea.h"
#include "test.h"
#include "po.h"
//教师管理界面
void tea1(tea TEA)
{
int b,v=Tea3;
char c;
do{
cout<<"教师管理界面"<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"1.添加 ";
cout<<"2.查询 ";
cout<<"3.显示 ";
cout<<"4.编辑 ";
cout<<"5.删除 ";
cout<<"6.统计 ";
cout<<"7.保存 ";
cout<<"8.读取 ";
cout<<"0.退出 "<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"请选择:";cin>>b;
switch(b)
{
case 1:TEA.Add(v);system("pause");break;
case 2:TEA.Search();system("pause");break;
case 3:TEA.Show();system("pause");break;
case 4:TEA.Edit();system("pause");break;
case 5:TEA.Delete(v);system("pause");break;
case 6:cout<<"共有教师人数:"<<v<<endl;system("pause");break;
case 7:TEA.Save();system("pause");break;
case 8:TEA.Read(v);system("pause");break;
default:cout<<"\n 错误!"<<endl;system("pause");break;
case 0:break;
}
cin.clear();
c=getchar();
system("cls");
}while(b!=0);
}
//实验员管理界面
void test1(test TES)
{
int b,v=Testop;
char c;
do{
cout<<"实验员管理界面"<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"1.添加 ";
cout<<"2.查询 ";
cout<<"3.显示 ";
cout<<"4.编辑 ";
cout<<"5.删除 ";
cout<<"6.统计 ";
cout<<"7.保存 ";
cout<<"8.读取 ";
cout<<"0.退出 "<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"请选择:";cin>>b;
switch(b)
{
case 1:TES.Add(v);system("pause");break;
case 2:TES.Search();system("pause");break;
case 3:TES.Show();system("pause");break;
case 4:TES.Edit();system("pause");break;
case 5:TES.Delete(v);system("pause");break;
case 6:cout<<"共有实验员人数:"<<v<<endl;system("pause");break;
case 7:TES.Save();system("pause");break;
case 8:TES.Read(v);system("pause");break;
default:cout<<"\n错误!"<<endl;system("pause");break;
case 0:break;
}
cout<<"按回车键返回"<<endl;
cin.clear();
c=getchar();
system("cls");
}while(b!=0);
}
//行政人员管理界面
void po1(po PO)
{
int b,v=Policersop;
char c;
do{
cout<<"行政人员管理界面"<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"1.添加 ";
cout<<"2.查询 ";
cout<<"3.显示 ";
cout<<"4.编辑 ";
cout<<"5.删除 ";
cout<<"6.统计 ";
cout<<"7.保存 ";
cout<<"8.读取 ";
cout<<"0.退出 "<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"请选择:";cin>>b;
switch(b)
{
case 1:PO.Add(v);system("pause");break;
case 2:PO.Search();system("pause");break;
case 3:PO.Show();system("pause");break;
case 4:PO.Edit();system("pause");break;
case 5:PO.Delete(v);system("pause");break;
case 6:cout<<"共有行政员人数:"<<v<<endl;system("pause");break;
case 7:PO.Save();system("pause");break;
case 8:PO.Read(v);system("pause");break;
default:cout<<"\n 错误!"<<endl;system("pause");break;
case 0:break;
}
cin.clear();
c=getchar();
system("cls");
}while(b!=0);
}
//主函数
int main()
{ tea tea2;
test tes2;
po po2;
int a;
char c;
while(1)
{
system("cls");
cout<<endl;
cout<<" ****欢迎使用高校人员信息管理系统**** "<<endl;
cout<<" \n\n\n"<<endl;
cout<<" 1.教师管理 "<<endl;
cout<<" 2.实验员管理 "<<endl;
cout<<" 3.行政员管理 "<<endl;
cout<<" 0.退出 "<<endl;
cout<<"\n\n\n"<<endl;
cout<<"请选择:";cin>>a;
switch(a)
{
case 1:system("cls");tea1(tea2);break;
case 2:system("cls");test1(tes2);break;
case 3:system("cls");po1(po2);break;
case 0:exit(0);break;
default:cout<<"\n 错误!"<<endl;
system("pause");
c=getchar();
cin.clear();
break;
}
}
return 0;
}
以下是类:
persion.h
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
static int Tea3;
static int Testop;
static int Policersop;
#define z 666
class person
{
public:
int num;
string name;
string sex;
int age;
};
tester.h
#include "person.h"
class tester :
virtual public person
{
public:
string testroom;
string post;
void Input()
{
cout<<"请再次输入编号以确定:";cin>>num;
cout<<"请输入姓名:";cin>>name;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入该实验员所在实验室:";cin>>testroom;
cout<<"请输入该实验员的职务:";cin>>post;
}
void Output()
{
cout<<"编号: "<<num<<" "<<"姓名: "<<name<<" "<<"性别: "<<sex<<" "<<"年龄: "<<age<<
" "<<"所在实验室: "<<testroom<<" "<<"职务: "<<post<<endl;
}
};
policer.h
#include "person.h"
class policer :
virtual public person
{
public:
string polices;
string post1;
void Input()
{
cout<<"请再次输入编号以确定:";cin>>num;
cout<<"请输入姓名:";cin>>name;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入政治面貌:";cin>>polices;
cout<<"请输入职称:";cin>>post1;
}
void Output()
{
cout<<"编号: "<<num<<" "<<"姓名: "<<name<<" "<<"性别: "<<sex<<" "<<"年龄: "<<age<<
" "<<"政治面貌: "<<polices<<" "<<"职称: "<<post1<<endl;
}
};
teacher.h
#include "person.h"
class teacher :
virtual public person
{
public:
string dept;
string special;
string title;
void Input()
{
cout<<"请再次输入编号以确定:";cin>>num;
cout<<"请输入姓名:";cin>>name;
cout<<"请输入性别:";cin>>sex;
cout<<"请输入年龄:";cin>>age;
cout<<"请输入该教师所在系别:";cin>>dept;
cout<<"请输入该教师专业:";cin>>special;
cout<<"请输入该教师的职称:";cin>>title;
}
void Output()
{
cout<<"编号: "<<num<<" "<<"姓名: "<<name<<" "<<"性别: "<<sex<<" "<<"年龄: "<<age<<
" "<<"所在系: "<<dept<<" "<<"专业: "<<special<<" "<<"职称: "<<title<<endl;
}
};
方法类:
po.h
#include "policer.h"
class po
{
public:
policer Po[z];
int Add(int &w);
int Search();
void Show();
void Edit();
int Delete(int &w);
void Save();
int Read(int &w);
};
po.cpp
#include "StdAfx.h"
#include "po.h"
int po::Add(int &w)
{
policer t;
int i,nu;
if(Policersop==z)
{cout<<"人数已满"<<endl;
return 0;
}
cout<<"请输入编号:";cin>>nu;
for(i=0;i<Policersop;i++)
{
if(nu==Po[i].num)
{cout<<"已有编号,请重新输入"<<endl;
return 0;
}
}
t.Input();
Po[Policersop]=t;
Policersop++;
w=Policersop;
cout<<"添加成功!"<<endl;
return 1;
}
int po::Search()
{
int j,n;
cout<<"请输入编号:";cin>>n;
for(j=0;j<Policersop;j++)
{
if(n==Po[j].num) break;
}
if(j==Policersop)
cout<<"没有此人!"<<endl;
else
Po[j].Output();
return 1;
}
void po::Show()
{
int i;
if(Policersop==0)
{cout<<"记录为空!"<<endl; return;}
for(i=0;i<Policersop;i++)
Po[i].Output();
}
void po::Edit()
{
policer t1;
int j,n;
cout<<"请输入要编辑的人的编号:";cin>>n;
for(j=0;j<Policersop;j++)
{
if(n==Po[j].num) break;
}
if(j==Policersop)
{cout<<"没有此人!"<<endl;return;};
cout<<"输入修改后的信息,编号不能改:"<<endl;
t1.Input();
Po[j]=t1;
cout<<"编辑成功!"<<endl;
}
int po::Delete(int &w)
{
int j,n;
cout<<"请输入要删除的人的编号:";cin>>n;
for(j=0;j<Policersop;j++)
{
if(n==Po[j].num) break;
}
if(j==Policersop)
{cout<<"没有此人!"<<endl;return 0;};
for(j;j<Policersop;j++)
{
Po[j]=Po[j+1];
}
Policersop--;
w=Policersop;
cout<<"删除成功!"<<endl;
return 1;
}
void po::Save()
{
int i;
ofstream outfile,outfile1;
outfile1.open("Policersop.dat",ios::out);
outfile1<<Policersop;
outfile.open("Policers_data.dat",ios::out);
if(!outfile)
{cerr<<"没有此文件!"<<endl; return; }
for(i=0;i<Policersop;i++)
{
outfile<<Po[i].num<<endl;
outfile<<Po[i].name<<endl;
outfile<<Po[i].sex<<endl;
outfile<<Po[i].age<<endl;
outfile<<Po[i].polices<<endl;
outfile<<Po[i].post1<<endl;
}
outfile.close();
cout<<"保存成功!"<<endl;
}
int po::Read(int &w)
{
w=0;
int i;
ifstream infile,infile1;
infile1.open("Policersop.dat",ios::in);
infile1>>Policersop;
w=Policersop;
infile.open("Policers_data.dat",ios::in);
if(!infile)
{cerr<<"没有此文件!"<<endl; return 1; }
for(i=0;i<Policersop;i++)
{ infile>>Po[i].num;
infile>>Po[i].name;
infile>>Po[i].sex;
infile>>Po[i].age;
infile>>Po[i].polices;
infile>>Po[i].post1;}
infile.close();
cout<<"读取成功!"<<endl;
return 0;
}
tea.h
#include "teacher.h"
class tea
{
public:
teacher Tea[z];
int Add(int &w);
int Search();
void Show();
void Edit();
int Delete(int &w);
void Save();
int Read(int &w);
tea(void);
~tea(void);
};
tea.cpp
#include "StdAfx.h"
#include "tea.h"
int tea::Add(int &w)
{
teacher t;
int i,nu;
if(Tea3==z)
{cout<<"人数已满"<<endl;
return 0;
}
cout<<"请输入编号:";cin>>nu;
for(i=0;i<Tea3;i++)
{
if(nu==Tea[i].num)
{cout<<"已有编号,请重新输入"<<endl;
return 0;
}
}
t.Input();Tea[Tea3]=t;Tea3++;
w=Tea3;
cout<<"添加成功!"<<endl;
return 1;
}
int tea::Search()
{
int j,n;
cout<<"请输入编号:";cin>>n;
for(j=0;j<Tea3;j++)
{
if(n==Tea[j].num) break;
}
if(j==Tea3)
cout<<"没有此人!"<<endl;
else
Tea[j].Output();
return 1;
}
void tea::Show()
{
int i;
if(Tea3==0)
{cout<<"记录为空!"<<endl; return;}
for(i=0;i<Tea3;i++)
Tea[i].Output();
}
void tea::Edit()
{
teacher t1;
int j,n;
cout<<"请输入要编辑的人的编号:";cin>>n;
for(j=0;j<Tea3;j++)
{
if(n==Tea[j].num) break;
}
if(j==Tea3)
{cout<<"没有此人!"<<endl;return;};
cout<<"输入修改后的信息,编号不能改:"<<endl;
t1.Input();
Tea[j]=t1;
cout<<"编辑成功!"<<endl;
}
int tea::Delete(int &w)
{
int j,n;
cout<<"请输入要删除的人的编号:";cin>>n;
for(j=0;j<Tea3;j++)
{
if(n==Tea[j].num) break;
}
if(j==Tea3)
{cout<<"没有此人!"<<endl;return 0;};
for(j;j<Tea3;j++)
{
Tea[j]=Tea[j+1];
}
Tea3--;
w=Tea3;
cout<<"删除成功!"<<endl;
return 1;
}
void tea::Save()
{
int i;
ofstream outfile,outfile1;
outfile1.open("Tea3.dat",ios::out);
outfile1<<Tea3;
outfile.open("Tea_data.dat",ios::out);
if(!outfile)
{cerr<<"没有此文件!"<<endl; return; }
for(i=0;i<Tea3;i++)
{
outfile<<Tea[i].num<<endl;
outfile<<Tea[i].name<<endl;
outfile<<Tea[i].sex<<endl;
outfile<<Tea[i].age<<endl;
outfile<<Tea[i].dept<<endl;
outfile<<Tea[i].special<<endl;
outfile<<Tea[i].title<<endl;
}
outfile.close();
cout<<"保存成功!"<<endl;
}
int tea::Read(int &w)
{
w=0;
int i;
ifstream infile,infile1;
infile1.open("Tea3.dat",ios::in);
infile1>>Tea3;
w=Tea3;
infile.open("Tea_data.dat",ios::in);
if(!infile)
{cerr<<"没有此文件!"<<endl; return 0; }
for(i=0;i<Tea3;i++)
{ infile>>Tea[i].num;
infile>>Tea[i].name;
infile>>Tea[i].sex;
infile>>Tea[i].age;
infile>>Tea[i].dept;
infile>>Tea[i].special;
infile>>Tea[i].title;
}
infile.close();
cout<<"读取成功!"<<endl;
return 0;
}
tea::tea(void)
{
}
tea::~tea(void)
{
}
test.h
#include "tester.h"
class test
{
public:
tester Test[z];
int Add(int &w);
int Search();
void Show();
void Edit();
int Delete(int &w);
void Save();
int Read(int &w);
};
test.cpp
#include "StdAfx.h"
#include "test.h"
int test::Add(int &w)
{
tester t;
int i,nu;
if(Testop==z)
{cout<<"人数已满"<<endl;
return 0;
}
cout<<"请输入编号:";cin>>nu;
for(i=0;i<Testop;i++)
{
if(nu==Test[i].num)
{cout<<"已有编号,请重新输入"<<endl;
return 0;
}
}
t.Input();
Test[Testop]=t;
Testop++;
w=Testop;
cout<<"添加成功!"<<endl;
return 1;
}
int test::Search()
{
int j,n;
cout<<"请输入编号:";cin>>n;
for(j=0;j<Testop;j++)
{
if(n==Test[j].num) break;
}
if(j==Testop)
cout<<"没有此人!"<<endl;
else
Test[j].Output();
return 1;
}
void test::Show()
{
int i;
if(Testop==0)
{cout<<"记录为空!"<<endl; return;}
for(i=0;i<Testop;i++)
Test[i].Output();
}
void test::Edit()
{
tester t1;
int j,n;
cout<<"请输入要编辑的人的编号:";cin>>n;
for(j=0;j<Testop;j++)
{
if(n==Test[j].num) break;
}
if(j==Testop)
{cout<<"没有此人!"<<endl;return;};
cout<<"输入修改后的信息,编号不能改:"<<endl;
t1.Input();
Test[j]=t1;
cout<<"编辑成功!"<<endl;
}
int test::Delete(int &w)
{
int j,n;
cout<<"请输入要删除的人的编号:";cin>>n;
for(j=0;j<Testop;j++)
{
if(n==Test[j].num) break;
}
if(j==Testop)
{cout<<"没有此人!"<<endl;return 0;};
for(j;j<Testop;j++)
{
Test[j]=Test[j+1];
}
Testop--;
w=Testop;
cout<<"删除成功!"<<endl;
return 1;
}
void test::Save()
{
int i;
ofstream outfile,outfile1;
outfile1.open("Test.dat",ios::out);
outfile1<<Testop;
outfile.open("Test_data.dat",ios::out);
if(!outfile)
{cerr<<"没有此文件!"<<endl; return; }
for(i=0;i<Testop;i++)
{
outfile<<Test[i].num<<endl;
outfile<<Test[i].name<<endl;
outfile<<Test[i].sex<<endl;
outfile<<Test[i].age<<endl;
outfile<<Test[i].testroom<<endl;
outfile<<Test[i].post<<endl;
}
outfile.close();
cout<<"保存成功!"<<endl;
}
int test::Read(int &w)
{
int i;
ifstream infile,infile1;
infile1.open("Test.dat",ios::in);
infile1>>Testop;
w=Testop;
infile.open("Test_data.dat",ios::in);
if(!infile)
{cerr<<"没有此文件!"<<endl; return 1; }
for(i=0;i<Testop;i++)
{ infile>>Test[i].num;
infile>>Test[i].name;
infile>>Test[i].sex;
infile>>Test[i].age;
infile>>Test[i].testroom;
infile>>Test[i].post;
}
infile.close();
cout<<"读取成功!"<<endl;
return 0;
}
下载链接
仅供学习参考,文件下载链接C++实现高校人员信息管理系统