1、问题描述
某高校有四类员工:教师、实验员、行政人员,教师兼行政人员;共有的信息包括:编号、姓名、性别、年龄等。其中,教师还包含的信息有:所在系部、专业、职称;实验员还包含的信息由:所在实验室、职务;行政人员还包含的信息有:政治面貌、职称等。
2、功能要求
(1)添加功能:程序能够任意添加上述四类人员的记录,可提供选择界面供用户选择所要添加的人员类别,要求员工的编号要唯一,如果添加了重复编号的记录时,则提示数据添加重复并取消添加。
(2)查询功能:可根据编号信息对已添加的记录进行查询,如果未找到,给出相应的提示信息,如果找到,则显示相应的记录信息。
(3)显示功能:可显示当前系统中所有记录,每条记录占据一行。
(4)编辑功能:可根据查询结果对相应的记录进行修改,修改时注意编号的唯一性。
(5)删除功能:主要实现对已添加的人员记录进行删除。如果当前系统中没有相应的人员记录,则提示“记录为空!”并返回操作;否则,输入要删除的人员的编号或姓名,根据所输入的信息删除该人员记录,如果没有找到该人员信息,则提示相应的记录不存。
(6)统计功能:能根据多种参数进行人员的统计。能统计四类人员数及人员总数。
(7) 保存功能:可将当前系统中各类人员记录存入文件中,存入方式任意。
(8)读取功能:可将保存在文件中的人员信息读入到当前系统中,供用户进行使用。
//main.cpp
#include "teacher.h"
#include "tea.h"
#include "test.h"
#include "po.h"
#include "tea_po.h"
//教师管理界面
void tea1(tea TEA)
{
int b,v=TeaTop;
do{
cout<<"教师管理界面"<<endl;
cout<<"==========================================================="<<endl;
cout<<"|| ||"<<endl;
cout<<"|| 1.添加 2.查询 3.显示 ||"<<endl;
cout<<"|| ||"<<endl;
cout<<"|| 4.编辑 5.删除 6.统计 ||"<<endl;
cout<<"|| ||"<<endl;
cout<<"|| 7.保存 8.读取 0.退出 ||"<<endl;
cout<<"|| ||"<<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;//退出
}
system("cls");
}while(b!=0);
}
//实验员管理界面
void test1(test TES)
{
int b,v=Testop;
do{
cout<<"实验员管理界面"<<endl;
cout<<"==========================================================="<<endl;
cout<<"|| ||"<<endl;
cout<<"|| 1.添加 2.查询 3.显示 ||"<<endl;
cout<<"|| ||"<<endl;
cout<<"|| 4.编辑 5.删除 6.统计 ||"<<endl;
cout<<"|| ||"<<endl;
cout<<"|| 7.保存 8.读取 0.退出 ||"<<endl;
cout<<"|| ||"<<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;
system("cls");
}while(b!=0);
}
//行政人员管理界面
void po1(po PO)
{
int b,v=PolicerTop;
do{
cout<<"行政人员管理界面"<<endl;
cout<<"==========================================================="<<endl;
cout<<"|| ||"<<endl;
cout<<"|| 1.添加 2.查询 3.显示 ||"<<endl;
cout<<"|| ||"<<endl;
cout<<"|| 4.编辑 5.删除 6.统计 ||"<<endl;
cout<<"|| ||"<<endl;
cout<<"|| 7.保存 8.读取 0.退出 ||"<<endl;
cout<<"|| ||"<<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;
}
system("cls");
}while(b!=0);
}
//教师兼行政人员管理界面
void tea_po1(tea_po TEA_PO)
{
int b,v=Tea_PolicerTop;
do{
cout<<"教师兼行政人员管理界面"<<endl;
cout<<"==========================================================="<<endl;
cout<<"|| ||"<<endl;
cout<<"|| 1.添加 2.查询 3.显示 ||"<<endl;
cout<<"|| ||"<<endl;
cout<<"|| 4.编辑 5.删除 6.统计 ||"<<endl;
cout<<"|| ||"<<endl;
cout<<"|| 7.保存 8.读取 0.退出 ||"<<endl;
cout<<"|| ||"<<endl;
cout<<"==========================================================="<<endl;
cout<<"请选择:";
cin>>b;
switch(b)
{
case 1:TEA_PO.Add(v);system("pause");break;
case 2:TEA_PO.Search();system("pause");break;
case 3:TEA_PO.Show();system("pause");break;
case 4:TEA_PO.Edit();system("pause");break;
case 5:TEA_PO.Delete(v);system("pause");break;
case 6:cout<<"共有教师兼行政员人数:"<<v<<endl;system("pause");break;
case 7:TEA_PO.Save();system("pause");break;
case 8:TEA_PO.Read(v);system("pause");break;
default:cout<<"\n 错误!"<<endl;system("pause");break;
case 0:break;
}
system("cls");
}while(b!=0);
}
//密码登录界面
void loading()
{
int stuNum=0;
int lock=0;
int *temp1=&stuNum;//指针取得用户输入的学号密码
int *temp2=&lock;
cout<<" *****************************************"<<endl;
cout<<" ** **"<<endl;
cout<<" ** 欢迎来到高校人员信息管理系统 **"<<endl;
cout<<" ** **"<<endl;
cout<<" *****************************************"<<endl;
cout<<" 请输入学工号:";
cin>>stuNum;
cout<<" 请输入密码:";
cin>>lock;
if(*temp1!=*temp2)
{
cout<<"密码错误!请重新输入"<<endl;
system("pause");
system("cls");
loading();//函数的递归使用,输入密码不正确,就再次使用函数进行登录
}
}
//主函数
int main()
{ tea tea2;
test tes2;
po po2;
tea_po tea_po2;
int choice;
int *choi=&choice;//指针传递
loading();//先登录
system("cls");
while(true)
{
system("cls");
cout<<endl;
cout<<"************欢迎使用高校人员信息管理系统************"<<endl;
cout<<" __________________________________________________"<<endl;
cout<<"| |"<<endl;
cout<<"| |"<<endl;
cout<<"| |"<<endl;
cout<<"| 1.教师管理 |"<<endl;
cout<<"| 2.实验员管理 |"<<endl;
cout<<"| 3.行政员管理 |"<<endl;
cout<<"| 4.教师兼行政员管理 |"<<endl;
cout<<"| 0.退出 |"<<endl;
cout<<"| |"<<endl;
cout<<"| |"<<endl;
cout<<"|__________________________________________________|"<<endl;
cout<<"请选择:";
cin>>choice;
switch(*choi)
{
case 1:system("cls");tea1(tea2);break;
case 2:system("cls");test1(tes2);break;
case 3:system("cls");po1(po2);break;
case 4:system("cls");tea_po1(tea_po2);break;
case 0:system("cls");
cout<<" 欢迎您下次登录!"<<endl;
cout<<" 欢迎您下次登录!"<<endl;
cout<<" 欢迎您下次登录!"<<endl;
loading();
break;
default:cout<<"\n 错误!"<<endl;
system("pause");
break;
}
}
return 0;
}
persion.h
#ifndef PERSION_H_INCLUDED
#define PERSION_H_INCLUDED
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
static int TeaTop;//静态全局变量,教师人员上限
static int Testop;//静态全局变量,实验员上限
static int PolicerTop;//静态全局变量,行政人员上限
static int Tea_PolicerTop;//静态全局变量,教师兼行政人员上限
#define z 1000
class person
{
friend class teacher;//声明友元,教师类访问人员类私有变量
friend class tester;//声明友元,实验人员类访问人员类私有变量
friend class policer;//声明友元,行政人员类访问人员类私有变量
public:
int num;
string name;
string sex;
int age;
};
#endif // PERSION_H_INCLUDED
teacher.h
#ifndef TEACHER_H_INCLUDED
#define TEACHER_H_INCLUDED
#include "persion.h"
class teacher :virtual public person//教师类
{
friend class teacher_policer;//声明友元,教师兼行政人员类访问教师私有变量
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;
}
};
#endif // TEACHER_H_INCLUDED
tea.h
#ifndef TEA_H_INCLUDED
#define TEA_H_INCLUDED
#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);
};
#endif // TEA_H_INCLUDED
tea.cpp
#include "tea.h"
int tea::Add(int &w)//添加
{
teacher t;
int i,nu;
if(TeaTop==z)//教师最大人数达到宏定义的最大值
{
cout<<"人数已满"<<endl;
return 0;
}
cout<<"请输入编号:";
cin>>nu;
for(i=0;i<TeaTop;i++)
{
if(nu==Tea[i].num)
{
cout<<"已有编号,请重新输入"<<endl;
return 0;
}
}
t.Input();
Tea[TeaTop]=t;
TeaTop++;
w=TeaTop;
cout<<"添加成功!"<<endl;
return 1;
}
int tea::Search()//查询
{
int j,n;
cout<<"请输入编号:";
cin>>n;
for(j=0;j<TeaTop;j++)
{
if(n==Tea[j].num)
break;
}
if(j==TeaTop)
cout<<"没有此人!"<<endl;
else
Tea[j].Output();//输出
return 1;
}
void tea::Show()//显示
{
int i;
if(TeaTop==0)
{
cout<<"记录为空!"<<endl;
return;
}
for(i=0;i<TeaTop;i++)
Tea[i].Output();
}
void tea::Edit()//编辑
{
teacher t1;
int j,n;
cout<<"请输入要编辑的人的编号:";
cin>>n;
for(j=0;j<TeaTop;j++)
{
if(n==Tea[j].num)
break;
}
if(j==TeaTop)
{
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<TeaTop;j++)
{
if(n==Tea[j].num)
break;
}
if(j==TeaTop)
{
cout<<"记录为空!"<<endl;
return 0;
}
for(j;j<TeaTop;j++)
{
Tea[j]=Tea[j+1];
}
TeaTop--;
w=TeaTop;//删除后人数减一
cout<<"删除成功!"<<endl;
return 1;
}
void tea::Save()
{
int i;
ofstream outfile,outfile1;
outfile1.open("TeaTop.dat",ios::out);
outfile1<<TeaTop;
outfile.open("Tea_data.dat",ios::out);
if(!outfile)
{
cerr<<"没有此文件!"<<endl;
return;
}
for(i=0;i<TeaTop;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("TeaTop.dat",ios::in);
infile1>>TeaTop;
w=TeaTop;
infile.open("Tea_data.dat",ios::in);
if(!infile)
{
cerr<<"没有此文件!"<<endl;
return 0;
}
for(i=0;i<TeaTop;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)
{
}
tester.h
#ifndef TESTER_H_INCLUDED
#define TESTER_H_INCLUDED
#include "persion.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;
}
};
#endif // TESTER_H_INCLUDED
test.h
#ifndef TEST_H_INCLUDED
#define TEST_H_INCLUDED
#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);
};
#endif // TEST_H_INCLUDED
test.cpp
#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;
}
policer.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;
}
po.h
#ifndef PO_H_INCLUDED
#define PO_H_INCLUDED
#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);
};
#endif // PO_H_INCLUDED
po.cpp
#include "po.h"
int po::Add(int &w)
{
policer t;
int i,nu;
if(PolicerTop==z)
{
cout<<"人数已满"<<endl;
return 0;
}
cout<<"请输入编号:";
cin>>nu;
for(i=0;i<PolicerTop;i++)
{
if(nu==Po[i].num)
{
cout<<"已有编号,请重新输入"<<endl;
return 0;
}
}
t.Input();
Po[PolicerTop]=t;
PolicerTop++;
w=PolicerTop;
cout<<"添加成功!"<<endl;
return 1;
}
int po::Search()
{
int j,n;
cout<<"请输入编号:";
cin>>n;
for(j=0;j<PolicerTop;j++)
{
if(n==Po[j].num)
break;
}
if(j==PolicerTop)
cout<<"没有此人!"<<endl;
else
Po[j].Output();
return 1;
}
void po::Show()
{
int i;
if(PolicerTop==0)
{
cout<<"记录为空!"<<endl;
return;}
for(i=0;i<PolicerTop;i++)
Po[i].Output();
}
void po::Edit()
{
policer t1;
int j,n;
cout<<"请输入要编辑的人的编号:";cin>>n;
for(j=0;j<PolicerTop;j++)
{
if(n==Po[j].num)
break;
}
if(j==PolicerTop)
{
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<PolicerTop;j++)
{
if(n==Po[j].num)
break;
}
if(j==PolicerTop)
{
cout<<"记录为空!"<<endl;
return 0;
}
for(j;j<PolicerTop;j++)
{
Po[j]=Po[j+1];
}
PolicerTop--;
w=PolicerTop;
cout<<"删除成功!"<<endl;
return 1;
}
void po::Save()
{
int i;
ofstream outfile,outfile1;
outfile1.open("PolicerTop.dat",ios::out);
outfile1<<PolicerTop;
outfile.open("Policers_data.dat",ios::out);
if(!outfile)
{
cerr<<"没有此文件!"<<endl;
return;
}
for(i=0;i<PolicerTop;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].title1<<endl;
}
outfile.close();
cout<<"保存成功!"<<endl;
}
int po::Read(int &w)
{
w=0;
int i;
ifstream infile,infile1;
infile1.open("PolicerTop.dat",ios::in);
infile1>>PolicerTop;
w=PolicerTop;
infile.open("Policers_data.dat",ios::in);
if(!infile)
{
cerr<<"没有此文件!"<<endl;
return 1;
}
for(i=0;i<PolicerTop;i++)
{
infile>>Po[i].num;
infile>>Po[i].name;
infile>>Po[i].sex;
infile>>Po[i].age;
infile>>Po[i].polices;
infile>>Po[i].title1;
}
infile.close();
cout<<"读取成功!"<<endl;
return 0;
}
tea_po.h
#ifndef TEA_PO_H_INCLUDED
#define TEA_PO_H_INCLUDED
#include "teacher_policer.h"
class tea_po//方法类
{
public:
teacher_policer Tea_Po[z];
int Add(int &w);
int Search();
void Show();
void Edit();
int Delete(int &w);
void Save();
int Read(int &w);
};
#endif // TEA_PO_H_INCLUDED
teacher_policer.h
#ifndef TEA_PO_H_INCLUDED
#define TEA_PO_H_INCLUDED
#include "teacher_policer.h"
class tea_po//方法类
{
public:
teacher_policer Tea_Po[z];
int Add(int &w);
int Search();
void Show();
void Edit();
int Delete(int &w);
void Save();
int Read(int &w);
};
#endif // TEA_PO_H_INCLUDED
tea_po.cpp
#include "tea_po.h"
int tea_po::Add(int &w)
{
teacher_policer t;
int i,nu;
if(Tea_PolicerTop==z)
{
cout<<"人数已满"<<endl;
return 0;
}
cout<<"请输入编号:";
cin>>nu;
for(i=0;i<Tea_PolicerTop;i++)
{
if(nu==Tea_Po[i].num)
{
cout<<"已有编号,请重新输入"<<endl;
return 0;
}
}
t.Input();
Tea_Po[Tea_PolicerTop]=t;
Tea_PolicerTop++;
w=Tea_PolicerTop;
cout<<"添加成功!"<<endl;
return 1;
}
int tea_po::Search()
{
int j,n;
cout<<"请输入编号:";
cin>>n;
for(j=0;j<Tea_PolicerTop;j++)
{
if(n==Tea_Po[j].num)
break;
}
if(j==Tea_PolicerTop)
cout<<"没有此人!"<<endl;
else
Tea_Po[j].Output();
return 1;
}
void tea_po::Show()
{
int i;
if(Tea_PolicerTop==0)
{
cout<<"记录为空!"<<endl;
return;
}
for(i=0;i<Tea_PolicerTop;i++)
Tea_Po[i].Output();
}
void tea_po::Edit()
{
teacher_policer t1;
int j,n;
cout<<"请输入要编辑的人的编号:";
cin>>n;
for(j=0;j<Tea_PolicerTop;j++)
{
if(n==Tea_Po[j].num)
break;
}
if(j==Tea_PolicerTop)
{
cout<<"没有此人!"<<endl;
return;
}
cout<<"输入修改后的信息,编号不能改:"<<endl;
t1.Input();
Tea_Po[j]=t1;
cout<<"编辑成功!"<<endl;
}
int tea_po::Delete(int &w)
{
int j,n;
cout<<"请输入要删除的人的编号:";
cin>>n;
for(j=0;j<Tea_PolicerTop;j++)
{
if(n==Tea_Po[j].num)
break;
}
if(j==Tea_PolicerTop)
{
cout<<"记录为空!"<<endl;
return 0;
}
for(j;j<Tea_PolicerTop;j++)
{
Tea_Po[j]=Tea_Po[j+1];
}
Tea_PolicerTop--;
w=Tea_PolicerTop;
cout<<"删除成功!"<<endl;
return 1;
}
void tea_po::Save()
{
int i;
ofstream outfile,outfile1;
outfile1.open("Tea_PolicerTop.dat",ios::out);
outfile1<<Tea_PolicerTop;
outfile.open("Tea_Policers_data.dat",ios::out);
if(!outfile)
{
cerr<<"没有此文件!"<<endl;
return;
}
for(i=0;i<Tea_PolicerTop;i++)
{
outfile<<Tea_Po[i].num<<endl;
outfile<<Tea_Po[i].name<<endl;
outfile<<Tea_Po[i].sex<<endl;
outfile<<Tea_Po[i].age<<endl;
outfile<<Tea_Po[i].polices<<endl;
outfile<<Tea_Po[i].title<<endl;
outfile<<Tea_Po[i].dept<<endl;
outfile<<Tea_Po[i].special<<endl;
}
outfile.close();
cout<<"保存成功!"<<endl;
}
int tea_po::Read(int &w)
{
w=0;
int i;
ifstream infile,infile1;
infile1.open("Tea_PolicerTop.dat",ios::in);
infile1>>Tea_PolicerTop;
w=Tea_PolicerTop;
infile.open("Tea_Policers_data.dat",ios::in);
if(!infile)
{
cerr<<"没有此文件!"<<endl;
return 1;
}
for(i=0;i<Tea_PolicerTop;i++)
{
infile>>Tea_Po[i].num;
infile>>Tea_Po[i].name;
infile>>Tea_Po[i].sex;
infile>>Tea_Po[i].age;
infile>>Tea_Po[i].polices;
infile>>Tea_Po[i].title;
infile>>Tea_Po[i].dept;
infile>>Tea_Po[i].special;
}
infile.close();
cout<<"读取成功!"<<endl;
return 0;
}
代码参考了前辈们的,感谢前辈的示范!希望能帮到大家。
/*一款程序是否具有界面的友好性,就要看运行后各个界面给用户提供的提示以及页面跳转的机制,我在制作登录界面时,我的想法是,登录时输入账号密码,正确就成功进入系统,但是不成功的话,要返回登录界面。
开始时,我想了想,这个功能可以用goto语句,但是goto语句风险大,我便想通过程序控制语句完成,最开始编写的程序是可以回到登录界面,但是是登录界面的叠加,于是进一步改进,利用清屏语句,又使得我的程序密码机制失效,不管怎样输入都不可以进入系统。我又采用了do...while语句,先执行一次,后面操作看条件,可惜还是效果不佳。
我开始分析,我发现这种情况与函数的递归调用很相似,我急忙用判断语句和函数的递归结合,运行起来达到了我的预期效果!
虽然登录页面知识系统的一部分,但是可以说是程序员与用户的沟通桥梁,不经意之间用缺乏实践的递归进入我的代码,是我的最得意,最开心的地方,也是我的一点创意!*/(哈哈哈这是课程设计报告里的话)
谢谢大家看到这里!