这出什么错了,请各位高手看看!
#include<iostream>#include<windows.h>
#include<cstdlib>
#include<conio.h>
#include<string>
using namespace std;
typedef struct people
{
char id[10];
int number;//人员号
char name[10];//人员姓名
char sex[10];//girl为女,boy为男
char birthday[12];
char telephone[13];
char address[40];
} people;
void chakan(struct people p[]); /*查看所有人员的信息*/
void chaxun(struct people p[]); /*查询单个人员的信息*/
void shanchu(struct people p[]); /*删除某个人员的信息*/
void tianjia(struct people p[]); /*添加一个人员的信息*/
void main()
{
struct people p[100];
int choice;
do{
system("cloor 2e");
system("cls");
cout<<"\n\t\t\通 讯 录 管 理 系 统";
cout<<"\n\t\t\t\t\t\t\长安大学";
cout<<"\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
cout<<"\n\t*功能菜单*:\n";
cout<<"\n\t\t------------------------------\n";
cout<<"\t\t2:查询");
cout<<"\n\t\t------------------------------\n";
cout<<"\t\t3:删除");
cout<<"\n\t\t------------------------------\n";
cout<<"\t\t4:添加");
cout<<"\n\t\t------------------------------\n";
cout<<"请选择功能---------------------------\n";
cin>>choice;
switch(choice)
{
case 0: system("color 3e");
system("cls");
cout<<("\n\n\n\n\n\n\n\t\t\t\退出系统\n");
int i;
for (i=5;i>=0;i--)
{
sleep(1000);
system("cls");
system("color 4e");
cout<<("\n\n\n\n\n\n\n\t\t\t\请稍等,还剩下%d退出系统\n\n\n,i");
system("color 6e");
system("cls");
cout<<("\n\n\n\n\n\t*您已成功退出系 统!\n\t@谢谢使用!\n");
exit(0);
break;
case l:
system("color 2f");
system("cls");
cout<<"查看所有人员的信息:\n";
chakan(p);
break;
case 2:
system("color 5e");
system("cls");
cout<<"查询但个人员的信息:\n";
chaxun(p);
break;
case 3:
system("color 8e");
system("cls");
cout<<"删除一个人员\n";
shanchu(p);
getch();
break;
case 4:
system("color 9f");
system("cls");
cout<<"添加一个人员\n";
tianjia(P);
break;
default:
system("color 9e");
system("cls");
cout<<"\n\n\n\t\t\t\请正确选择!\n\n";
system("pause");
}
}while(l);
//查看函数
void chakan(struct people p[])
{
FILE*fp;
int i=0,n=0;
if((fp=fopen("e: \\personInfo.txt","r"))==NULL)
{
cout<<"不能打开文件"<<endl;
exit(0);
}
while(!feof(fp)){
fin>><<fp<<p[i].number<<p[i]<<name<<p[i]<<sex<<p[i]<<birthday<<p[i]
<<telephone<<p[i]<<address);
i++;
}
n=i;
fclose(fp);
for(i=1;i<n;i++)
{
cout<<"输出该人员的信息"<<endl;
cout<<"人员号"<<p[i].number<<endl;
cout<<"姓名:"<<p[i].name<<endl;
cout<<"性别:"<<p[i].sex<<endl;
cout<<"生日:"<<p[i].birthday<<endl;
cout<<"电话:"<<p[i].telephone<<endl;
cout<<"地址:"<<p[i].address<<endl;
cout<<endl;
}
getch();
}
楚盼 15:10:17
//查询函数
void chaxun(struct people p[])
{
FILE*fp;
int i=0,j=0,a,flag=0,n=0;
if((fp=fopen("e: \\personInfo.txt","r"))==NULL)
{
cout<<"不能打开文件"<<endl;
exit(0);
}
while(!feof(fp)){
fin>><<fp<<p[i].number<<p[i]<<name<<p[i]<<sex<<p[i]<<birthday<<p[i]
<<telephone<<p[i]<<address);
i++;
}
n=i;
cout<<"请输入查询人员号:"<<endl;
cin>>a;
for(i=1;i<n;i++)
{
if(a==p[i].number)
cout<<"输出该人员的信息"<<endl;
cout<<"人员号"<<p[i].number<<endl;
cout<<"姓名:"<<p[i].name<<endl;
cout<<"性别:"<<p[i].sex<<endl;
cout<<"生日:"<<p[i].birthday<<endl;
cout<<"电话:"<<p[i].telephone<<endl;
cout<<"地址:"<<p[i].address<<endl;
flag=1;
break;
}
}
if(flag!=1)
cout<<"对不起,无此人员号!"<<endl;
fclose(fp);
getch();
}
/添加函数/
void tianjia(struct people p[])
{
abcd:FILE*fp;
people a,h;
int count=0,m=0;
int i=0,j,b,c=0;
if((fp=fopen("e: \\personInfo.txt","r"))==NULL)
{
cout<<"can not open the file!"<<endl;
fp=fopen("e: \\personInfo.txt","w");
cout<<"请输入人员号:"<<endl;
cin>>a.number;
}
else{
while(!feof(fp)){
fin>><<fp<<p[i].number<<p[i]<<name<<p[i]<<sex<<p[i]<<birthday<<p
[i]<<telephone<<p[i]<<address);
i++;
}//从磁盘读人员信息
fclose(fp);
do{
b=0
c=0;
cout<<"请输入人员号:"<<endl;
cin>>a.number;
count=i;
for(i=0;i<count;i++){
if(a.number==p[i].number){
c=-1;
break;}
}
if(c==-1){
cout<<"人员号重复,请重新输入!"<<endl;
goto abcd;}
else
break;
}while(b);//判断人员号是否重复
}
cout<<"请输入姓名"<<endl;
cin>>a.name;
cout<<"请输入性别"<<endl;
cin>>a.sex;
cout<<"请输入生日"<<endl;
cin>>a.birthday;
cout<<"请输入电话"<<endl;
cin>>a.telephone;
cout<<"请输入地址"<<endl;
cin>>a.address;
p[count]=a;
count++;
for(i=1;i<count;i++){
for(j=0;j<(count-1);j++){
if(p[j].number>p[j+1].number){
h=p[j];
p[j]=p[j+1];
p[j+1]=h;
}
}
}//排序
fp=fopen("e: \\personInfo.txt","w");
for(i=0;i<count;i++)
{
if(i==0)
fout<<p[i].number<<p[i].name<<p[i].sex<<p[i].birthday<<p
[i].telephone<<p[i].address<<endl;
else
fout<<\n<<p[i].number<<p[i].name<<p[i].sex<<p
[i].birthday<<p[i].telephone<<p[i].address<<endl;
}//重新写入磁盘
fclose(fp);
getch();
}
//删除函数
void tianjia(struct people p[])
{
FILE*fp;
int n=0;
if((fp=fopen("e: \\personInfo.txt","r"))==NULL)
{
cout<<"不能打开文件"<<endl;
exit(0);
}
int i=1,a,b=-1;
cout<<""<<endl;
cin>>a;
while(!feof(fp)){
fin>><<fp<<p[i].number<<p[i]<<name<<p[i]<<sex<<p[i]<<birthday<<p[i]
<<telephone<<p[i]<<address);
i++;
}
fclose(fp);
n=i;
if((fp=fopen("e: \\personInfo.txt","r"))==NULL)
{
cout<<"不能打开文件"<<endl;
exit(0);
}
for(i=1;i<count;i++)
{
if(p[i].number==a)
{
b=0;
}
else{
if(i==0)
fout<<p[i].number<<p[i].name<<p[i].sex<<p[i].birthday<<p
[i].telephone<<p[i].address<<endl;
else
fout<<\n<<p[i].number<<p[i].name<<p[i].sex<<p
[i].birthday<<p[i].telephone<<p[i].address<<endl;
}
}
fclose(fp);
if(b!=0)
cout<<"对不起,你要删除的人员号不存在!"<<endl;
else
cout<<"删除成功!"<<endl;
}