出现2个问题,费尽都不能解决。。。
这是代码,大家复制在VC6.0里调试一下,只有2个错误,好像很简单,但是却解决不了。#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
struct XX//通讯录信息
{
char id[100];//id记录
char name[18];//姓名
char senbenn[4];//性别
char dennwa[12];//电话
char address[20];//地址
char email[40];//E-mail
};
void printf1(struct XX xx)//通讯录信息键入
{
cout<<"\n现在开始输入新的信息!\n";
cout<<"\n输入ID:";
cin>>xx.id;
cout<<"输入姓名:";
cin>>xx.name;
cout<<"输入性别:";
cin>>xx.senbenn;
cout<<"输入电话:";
cin>>xx.dennwa;
cout<<"输入地址:";
cin>>xx.address;
cout<<"输入E-mail:";
cin>>xx.email;
}
int caidan()
{
system("cls");
int a;
cout<<"--------------------------------------------------------------------------------\n";
cout<<" 1.计算平均值\n"<<" 2.猜数字\n"<<" 3.通讯录\n"<<" 4.偏差值(未完成)\n"<<" 5.学生成绩管理系统(未完成)\n";
cout<<" 6.进制转换(未完成)\n"<<" 7.今日星期几(未完成)\n"<<" 8.最大公约(未完成)\n"<<" 9.最小公倍(未完成)\n"<<"10.XX(未完成)\n";
cout<<"11.(未完成)\n"<<"12.计算器(未完成)\n"<<"13.最大公约(未完成)\n"<<"14.最小公倍(未完成)\n"<<"15.未完成"<<"16.退出";
cout<<"\n\n--------------------------------------------------------------------------------";
cout<<"\n选择:";
cin>>a;
return a;
}
void pj()//求平均值函数
{
int a,i;
float c,b,aver;
c=0;
cout<<"要计算几个数?"<<"计算:";
cin>>a;
for(i=1;i<=a;i++)
{
cout<<"输入第"<<i<<"个数:";
cin>>b;
c+=b;
}
aver=c/a;
cout<<aver;
}
void csz()//猜数字
{
int a;
cout<<"输入一个数:";
cin>>a;
if(a>48)
{
cout<<"太大了!再试试!"<<"\n";
csz();
}
else if(a<48)
{
cout<<"太小了!再试试!"<<"\n";
csz();
}
else
{
cout<<"正解!"<<"\n\n";
caidan();
}
}
void txlxscd()//通讯录显示菜单
{
void ll();
void tj();
int a;
system("cls");
cout<<"\t\t\t\t\t通讯录\n\t\t1.浏览 2.添加 3.查找 4.修改 5.删除 6.返回"<<"\n选择:";
cin>>a;
switch(a)
{
case 1:system("cls");void ll();break;
case 2:system("cls");void tj();break;
case 3:system("cls");void cz();break;
case 4:system("cls");void xg();break;
case 5:system("cls");void sc();break;
case 6:system("cls");void main();break;
default:cout<<"非法输入,程序将返回主菜单!"<<endl;system("pause");void main();break;
}
}
void tj()//通讯录添加
{
FILE *fp;
int a;
struct XX xx;
if((fp=fopen("xinxi.txt","ab"))==NULL)
{
cout<<"打开文件错误,请确认根目录下的xinxi.txt文件存在或无异常."<<"\n现在将返回主菜单."<<endl;
system("Pause");
void main();
}
cout<<"\n输入ID:";
cin>>xx.id;
cout<<"输入姓名:";
cin>>xx.name;
cout<<"输入性别:";
cin>>xx.senbenn;
cout<<"输入电话:";
cin>>xx.dennwa;
cout<<"输入地址:";
cin>>xx.address;
cout<<"输入E-mail:";
cin>>xx.email;
fwrite(&xx,sizeof(xx),1,fp);
fclose(fp);
cout<<"文件信息已写入,下一步?"<<"\n\n\t1.继续添加\t2.返回通讯录菜单\t3.返回主菜单\t4.退出";
cout<<"选择:";
cin>>a;
switch(a)
{
case 1:void tj();break;
case 2:int tslxscd();break;
case 3:void main();break;
case 4:exit(0);break;
default:cout<<"非法操作,程序将放回主菜单!";void main();break;
}
}
void ll()//通讯录浏览
{
struct XX xx;
FILE *fp;
int i;
if((fp=fopen("xinxi.txt","rb"))==NULL)
{
cout<<"打开文件错误,请确认根目录下的xinxi.txt文件存在或无异常."<<"\n现在将返回主菜单."<<endl;
system("Pause");
void main();
}
while(fread(&xx,sizeof(xx),1,fp)==1)
{
cout<<"ID :"<< xx.id;
cout<<"姓名 :"<< xx.name;
cout<<"性别 :"<< xx.senbenn;
cout<<"电话 :"<< xx.dennwa;
cout<<"地址 :"<< xx.address;
cout<<"E-Mail:"<< xx.email;
}fclose(fp);
cout<<"信息已显示.下一步?"<<"\n\n\t1.返回通讯录菜单\t2.返回主菜单\t3.退出";
cout<<"选择:";
cin>>i;
switch(i)
{
case 1:int tslxscd();break;
case 2:void main();break;
case 3:exit(0);break;
default:cout<<"非法操作,程序将放回主菜单!";main();break;
}
}
void cx()//通讯录查询
{
struct XX xx;
FILE *fp;
int a;
char tj[20];
int total=0;
char f;
if((fp=fopen("xinxi.txt","rb"))==NULL)
{
cout<<"打开文件错误,请确认根目录下的xinxi.txt文件存在或无异常."<<"\n现在将返回主菜单."<<endl;
system("Pause");
void main();
}
rewind(fp);
cout<<"选择查询条件:____(1.按ID查询 -- 2.按姓名查询)";
cout<<"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
cin>>a;
if(a==1)
{
cout<<"输入要查询的ID:";
cin>>tj;
total=0;
while(fread(&xx,sizeof(xx),1,fp)==1)
if(strcmp(tj,xx.id)==0)
{
total++;
if(total==1)
{
cout<<"ID :"<< xx.id;
cout<<"姓名 :"<< xx.name;
cout<<"性别 :"<< xx.senbenn;
cout<<"电话 :"<< xx.dennwa;
cout<<"地址 :"<< xx.address;
cout<<"E-Mail:"<< xx.email;
}
}
}
if(a==2)
{
cout<<"输入要查询的姓名:";
cin>>tj;
total=0;
while(fread(&xx,sizeof(xx),1,fp)==1)
if(strcmp(tj,xx.id)==0)
{
total++;
if(total==1)
{
cout<<"ID :"<< xx.id;
cout<<"姓名 :"<< xx.name;
cout<<"性别 :"<< xx.senbenn;
cout<<"电话 :"<< xx.dennwa;
cout<<"地址 :"<< xx.address;
cout<<"E-Mail:"<< xx.email;
}
}
}
else
{
cout<<"请输入1和2!";
system("cls");
void cx();
}
void xg()//通讯录修改
{
struct XX xx;
FILE *fp1,*fp2;
char tj[20];
int a;
int i=0;
if((fp1=fopen("xinxi.txt","rb"))==NULL)
{
cout<<"打开文件错误,请确认根目录下的xinxi.txt文件存在或无异常."<<"\n现在将返回主菜单."<<endl;
system("Pause");
void main();
}
if((fp2=fopen("temp.txt","wb"))==NULL)
{
cout<<"打开文件错误,请确认根目录下的xinxi.txt文件存在或无异常."<<"\n现在将返回主菜单."<<endl;
system("Pause");
void main();
}
cout<<"输入你想修改人的姓名:";
cin>>tj;
while(fread(&xx,sizeof(xx),1,fp)==1)
{
if(strcmp(tj,xx.name)==0)
{
cout<<"ID :"<< xx.id;
cout<<"姓名 :"<< xx.name;
cout<<"性别 :"<< xx.senbenn;
cout<<"电话 :"<< xx.dennwa;
cout<<"地址 :"<< xx.address;
cout<<"E-Mail:"<< xx.email;
cou<<"确认修改此人信息?"<<"\n1.确认 2.重新输入姓名"<<"\n选择:";
cin>>a;
}
if(a==1)
{
cout<<"\n现在开始输入新的信息!\n";
cout<<"\n输入ID:";
cin>>xx.id;
cout<<"输入姓名:";
cin>>xx.name;
cout<<"输入性别:";
cin>>xx.senbenn;
cout<<"输入电话:";
cin>>xx.dennwa;
cout<<"输入地址:";
cin>>xx.address;
cout<<"输入E-mail:";
cin>>xx.email;
i=1;
}
}
fwrite(&xx,sizeof(xx),1,fp2);
fclose(fp1);
fclose(fp2);
if(i==1)
{
remove("xinxi.txt");
rename("temp.txt","xinxi.txt");
}
if(a==2)
{
return;
}
else
{
cout<<"请输入1和2进行选择!现在将返回主界面!";
int tslxscd();
}
}
void sc()//通讯录删除
{
struct XX xx;
FILE *fp;
char tj[20];
int i;
if((fp=fopen("xinxi.txt","rb"))==NULL)
{
cout<<"打开文件错误,请确认根目录下的xinxi.txt文件存在或无异常."<<"\n现在将返回主菜单."<<endl;
system("Pause");
void main();
}
if((fp=fopen("temp.txt","wb"))==NULL)
{
cout<<"打开文件错误,请确认根目录下的xinxi.txt文件存在或无异常."<<"\n现在将返回主菜单."<<endl;
system("Pause");
void main();
}
cout<<"输入姓名:";
cin>>tj;
i=0;
while(fread(&xx,sizeof(xx),1,fp)==1)
{
if(strcmp(tj,xx.name)==0)
{
void printf1(struct XX xx);
i=1;
}
else
fwrite(&xx,sizeof(xx),1,fp2);
}
fclose(fp1);
fclose(fp2);
if(i==1)
{
remove("xinxi.txt");
rename("temp.txt","xinxi.txt");
}
else
{
cout<<"未知错误,不能删除记录!";
}
}
}
void main()
{
cout<<"\t\t\t\t\t程序锦!"<<"\n"<<"\n";
switch(caidan())
{
case 1:system("cls");pj();break;
case 2:system("cls");csz();break;
case 3:system("cls");txlxscd();break;
case 4:system("cls");cout<<"未完成";break;
case 5:system("cls");cout<<"未完成";break;
case 6:system("cls");cout<<"未完成";break;
case 7:system("cls");cout<<"未完成";break;
case 8:system("cls");cout<<"未完成";break;
case 9:system("cls");cout<<"未完成";break;
case 10:system("cls");cout<<"未完成";break;
case 11:system("cls");cout<<"未完成";break;
case 12:system("cls");cout<<"未完成";break;
case 13:system("cls");cout<<"未完成";break;
case 14:system("cls");cout<<"未完成";break;
case 15:system("cls");cout<<"未完成";break;
case 16:exit(1);break;
default:cout<<"错误!";main();break;
}
}