求救啊!!跪求高手帮忙看下代码啊
#include<iostream> #include<string>
#include<fstream>
using namespace std;
const N=20; //部门最大数值
string Dname[N];
long Dnum[N];
string Djob[N];
string Dupname[N];
class department
{public:
string departmentname;
long departmentnum;
string departmentjob;
string departmentupname;
static long departmentMaxNum;
void Dadd();
void Dchange();
void Ddelete();
void Dshow();
void Dshownum(long number);
static int MaxNum();
};
class DBOperate
{
public:
string departmentname;
long departmentnum;
string departmentjob;
string departmentupname;
static long departmentMaxNum;
void WriteIn(int iflag);
void ReadOut();
void RefreshMaxNum(int iflag); //i=1 or -1 or 0
};
long department::departmentMaxNum = 1000; //部门编号由1000起
int department::MaxNum() //返回系统已经存储的人数
{
int MN = 0;
ifstream myf;
myf.open("departmentMaxNum.txt");
myf>>MN;
cout<<MN<<endl;
myf.close();
return MN;
}
void department::Dadd()
{cout<<"请输入部门名称: ";
cin>>department::departmentname;
cout<<"请输入部门职能: ";
cin>>department::departmentjob;
cout<<"请输入部门的上级部门: ";
cin>>department::departmentupname;
DBOperate dbo;
dbo.ReadOut();
int MaxNum = department::MaxNum();
Dnum[MaxNum]=department::departmentnum;
Dname[MaxNum]=department::departmentname;
Djob[MaxNum]=department::departmentjob;
Dupname[MaxNum]=department::departmentupname;
dbo.WriteIn(1);
cout<<" 添加新成员成功!"<<endl;
return;
}
void department::Dshow()
{ int i;
long number;
for(i=0;i<department::MaxNum();i++)
{
number = Dnum[i];
Dshownum(number);
} }
void department::Dshownum(long number) //按员工编号输出函数
{
int i;
for(i=0;i<department::MaxNum();i++)
{
if(Dnum[i] == number)
{cout<<"**********************************"<<endl;
cout<<"部门编号 >"<<Dnum[i]<<endl;
cout<<"部门名 >"<<Dname[i]<<endl;
cout<<"部门职能 >"<<Djob[i]<<endl;
cout<<"部门的上级部门 >"<<Dupname<<endl;
cout<<"**********************************"<<endl;
}
else continue;
}
}
void department::Dchange()
{int cNum = 1000;
DBOperate dbo;
dbo.ReadOut();
void department::Dshownum(long number);
cout<<"请输入您要修改的部门编号: >";
cin>>cNum;
int MN;
MN=department::MaxNum();
for(int i=0;i<MN;i++) //遍历数据文件,查找要修改的部门数据
{
if(Dnum[i] == cNum)
{
department::Dshownum(cNum);
cout<<"请输入该员工的新信息: "<<endl;
cout<<"新部门名: "; //录入部门新的数据,部门编号保持不变
cin>>department::departmentname;
Dname[i] = department::departmentname;
cout<<"请输入新的部门职能: ";
cin>>department::departmentjob;
Djob[i] = department::departmentjob;
cout<<"请输入新的部门的上级部门: ";
cin>>department::departmentupname;
Dupname[i] = department::departmentupname;
break;
}
}
dbo.WriteIn(0);
}
void department::Ddelete()
{{ char tmp;
int cNum = 1000;
DBOperate dbo;
dbo.ReadOut();
void department::Dshownum(long number);
cout<<"请输入您要删除的部门编号>: ";
cin>>cNum;
int MN;
MN = department::MaxNum();
for(int i=0;i<MN;i++) //遍历数据文件,查找要删除的部门
{
if(Dnum[i] == cNum)
department::Dshownum(cNum);
}
cout<<"确认要删除该部门信息?(Y为确认 N为放弃): ";
cin>>tmp;
if(tmp=='Y')
{
if(i==MN-1)
dbo.WriteIn(-1);
else
{
for(int j=i;j<MN-1;j++)
{ Dnum[j] = Dnum[j+1]; }
dbo.WriteIn(-1);
}
cout<<" 删除操作成功 ! "<<endl;
} }
void DBOperate::WriteIn(int iflag) //数据操作函数 写入
{DBOperate::RefreshMaxNum(iflag);
ofstream myf("department.txt");
department e;
int MN;
MN = e.MaxNum();
for(int i=0;i<MN;i++)
{
myf<<Dnum[i]<<'\n'<<Dname[i]<<'\n'<<Djob[i]<<'\n'<<Dupname[i]<<'\n';
}
myf.close();
}
void DBOperate::ReadOut() //数据操作函数 读出
{ifstream myf("department.txt");
department e;
int MN;
MN = e.MaxNum();
for(int i=0 ;i<MN;i++)
{
myf>>DBOperate::departmentnum>>DBOperate::departmentname>>DBOperate::departmentjob>>DBOperate::departmentupname;
Dnum[i] = DBOperate::departmentnum;
Dname[i] = DBOperate::departmentname;
Djob[i] = DBOperate::departmentjob;
Dupname[i] = DBOperate::departmentupname;
}
myf.close();
}
void DBOperate::RefreshMaxNum(int iflag) //更新系统中员工计数文件的函数
{
int MaxNum = 0;
ifstream myif("departmentMaxNum.txt");
myif>>MaxNum;
myif.close();
MaxNum = MaxNum+iflag;
ofstream myof("departmentMaxNum.txt");
myof<<MaxNum;
myof.close();
}
int main() //主函数
{
system("color 05f");
int select=0;
while(select!=8)
{
cout<<" ╭————————————《主菜单》———————————╮"<<endl;
cout<<" ∣ 请选择功能 ∣"<<endl;
cout<<" ├————————————————————————————┤"<<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<<" ——————————————————————————————"<<endl;
cout<<" 请选择您要服务的类别: " ;
cin>>select;
switch(select)
{
case 1:
{int select1 = 0;
while(select1!=5)
{
cout<<" ╭————————————《部门菜单》———————————╮"<<endl;
cout<<" ∣ 请选择功能 ∣"<<endl;
cout<<" ├————————————————————————————┤"<<endl;
cout<<" ∣ 1.新建并输入部门数据 ∣"<<endl;
cout<<" ∣ 2.修改指定部门数据 ∣"<<endl;
cout<<" ∣ 3.删除指定部门的数据 ∣"<<endl;
cout<<" ∣ 4.查询指定部门数据 ∣"<<endl;
cout<<" ∣ 5.退出 ∣"<<endl;
cout<<" ╰————————————————————————————╯"<<endl;
cout<<" ——————————————————————————————"<<endl;
cout<<" 请选择您要服务的类别: " ;
cin>>select1;
department e;
DBOperate dbo;
switch(select1)
{
case 1:
e.Dadd(); break;
case 2:
dbo.ReadOut();
e.Dchange(); break;
case 3:
e.Ddelete(); break;
case 4:
e.Dshow(); break;
case 5: break;
default:
cout<<"命令错误!"<<endl;
}
if(select == 5)
break;
}
exit(1);
return 0;
}}; break;
case 2: break;
case 3: break;
case 4: break;
case 5: break;
case 6:break;
case 7:break;
default:
cout<<"命令错误!"<<endl;
}
if(select == 8)
break;
} }
----------------------------------------------------------------------------------
怎么总说我RefreshMaxNum ReadOut WriteIn三个函数有问题啊