急!!!这个程序当运行(4)查找时显示不出信息。希望有人帮帮忙...
#include "iostream"#include "string"
#define N 10000
using namespace std;
struct teacher
{
char name[10];//教师姓名
double num;//教师编号
char gender[10];//教师性别
char position[20];//教师职称
int age;//教师年龄
int gage;//工龄
double salary;//各职称教师的薪水
double jiangjin;//教师的年奖金
char tele[20];//教师联系方式1电话号码
char email[20];//教师联系方式2QQ
char add[15];// 教师住址
};
teacher tea[N];
char user[]="xbjqcf";//用户名
char password[]="09080121719";//密码
//数据初始化
void cin1()
{
strcpy(tea[0].name,0);
tea[0].num=0;
strcpy(tea[0].gender,0);
strcpy(tea[0].position,0);
tea[0].age=0;
tea[0].gage=0;
tea[0].salary=0;
tea[0].jiangjin=0;
strcpy(tea[0].tele,0);
strcpy(tea[0].email,0);
strcpy(tea[0].add,0);
}
void jiemian()
{
cout<<" ** *** ** "<<endl;
cout<<" ** *** *** *** ** "<<endl;
cout<<" *** *** *** *** *** *** *** "<<endl;
cout<<" 欢迎使用高校职工信息管理系统 "<<endl;
cout<<" ** ** "<<endl;
cout<<"** 菜单选项 **"<<endl;
cout<<"*=====================================*"<<endl;
cout<<"* (1)添加职工 *"<<endl;
cout<<"*-------------------------------------*"<<endl;
cout<<"* (2)修改信息 *"<<endl;
cout<<"*-------------------------------------*"<<endl;
cout<<"* (3)删除信息 *"<<endl;
cout<<"*-------------------------------------*"<<endl;
cout<<"* (4)查找职工 *"<<endl;
cout<<"*-------------------------------------*"<<endl;
cout<<"* (5)所有职工 *"<<endl;
cout<<"*-------------------------------------*"<<endl;
cout<<"* (6)保存文件 *"<<endl;
cout<<"*-------------------------------------*"<<endl;
cout<<"* (0)退出程序 *"<<endl;
cout<<"*=====================================*"<<endl;
}
//添加信息
void Add(int n)
{
//接受数据
int i;
if(n<=N)
{
for(i=1;i<=n;i++)
{
cout<<"请输入您的姓名(中间不能有空格): ";
cin>>tea[i].name;
cout<<"请输入您的编号:";
cin>>tea[i].num;
cout<<"请输入您的性别:";
cin>>tea[i].gender;
cout<<"请输入您的职务(只能用英文,且用小写):"<<endl;
cout<<"校长(principal)"<<endl;
cout<<"副校长(Vice President)"<<endl;
cout<<"系主任(xizhuren)"<<endl;
cout<<"辅导员(fudaoyuan)"<<endl;
cin>>tea[i].position;
cout<<"请输入您的年龄:";
cin>>tea[i].age;
cout<<"请输入您的工龄: ";
cin>>tea[i].gage;
cout<<"请输入您的工资: ";
cin>>tea[i].salary;//tea[i].salary=Count_salary();
cout<<"请输入您的奖金: ";
cin>>tea[i].jiangjin;
cout<<"请输入您的号码: ";
cin>>tea[i].tele;
cout<<"请输入您的邮箱号: ";
cin>>tea[i].email;
cout<< "请输入您的地址: ";
cin>>tea[i].add;
cout<<"保存成功!"<<endl;
}
}
}
//显示我们注册的所有职工的全部信息
void Displaytea(int n)
{
int i;
for(i=1;i<=n;i++)
{
cout<<tea[i].name<<endl;
cout<<tea[i].num<<endl;
cout<<tea[i].gender<<endl;
cout<<tea[i].position<<endl;
cout<<tea[i].age<<endl;
cout<<tea[i].gage<<endl;
cout<<tea[i].salary<<endl;
cout<<tea[i].jiangjin<<endl;
cout<<tea[i].tele<<endl;
cout<<tea[i].email<<endl;
cout<<tea[i].add<<endl;
}
}
//查找职工
void search(int n)
{
int i;
double num;
cout<<"请输入您要查找的编号: " ;
cin>>num;
for(i=1;i<=n;i++)
{
if(tea[i].num==num)
{
cout<<"姓名: ";
cout<<tea[i].name<<endl;
cout<<tea[i].num<<endl;
cout<<tea[i].gender<<endl;
cout<<tea[i].position<<endl;
cout<<tea[i].age<<endl;
cout<<tea[i].gage<<endl;
cout<<tea[i].salary<<endl;
cout<<tea[i].jiangjin<<endl;
cout<<tea[i].tele<<endl;
cout<<tea[i].email<<endl;
cout<<tea[i].add<<endl;
}
break;
}
}
//主函数
int main()
{
char user1[15];
char password1[15];
int M=3;//输入次数
cout<<"请输入本程序的用户名:"<<endl;
while(M>0)
{
cin>>user1;
if(!strcmp(user,user1))//若输入与用户名相同
{
cout<<"用户名正确!"<<endl;
M=3;//防止输入密码时flag不为3
break;
}
else
{
cout<<"用户名错误,您还有"<<--M<<"次输入机会!"<<endl;
}
}
if(M<0)
{
cout<<"对不起,您输入三次错误,本程序将自动退出!"<<endl;
return (-1);//中断跳出
}
cout<<"请输入本程序的密码:"<<endl;
while(M>0)
{
cin>>password1;
if(!strcmp(password,password1))//若输入的密码与密码相同
{
cout<<"恭喜您,登陆成功!"<<endl;
break;
}
else
{
cout<<"您输入的密码错误,您还有"<<--M<<"次输入机会!"<<endl;
}
}
if(M)
{
cout<<"谢谢使用本程序----高校职工信息管理系统!"<<endl;
cout<<"本程序由09 计师本2班 许碧君 丘程芳 编写"<<endl;
cout<<endl<<endl<<endl;
}
else
{
cout<<"对不起,您三次输错,本程序将自动退出!"<<endl;
return (-1);//中断跳出
}
while(1)
{
int choice;
jiemian();
cout<<"请输入您要选择的菜单选项(请输入数字):";
cin>>choice;
switch(choice)
{
case 1:
{
int n;
cout<<"请输入您想要添加的职工个数:";
cin>>n;
Add(n);//注册职工
break;
}
case 5:
{
int n;
Displaytea(n);//全部显示
break;
}
case 4:
{
int n;
search(n);//查找
break;
}
}
//return 0;
}
}