九,电话簿管理系统 存储的数据包括:姓名、班级、电话号码和E-mail地址等。程序要求具有如下功能:

2020-06-16 教育 2633阅读
#我曾经份实验报告想要前三功能都需改提示信息行
#include
#define NUM 50
typedef struct _stu //定义结构体类型
{
char no[11]; //号
char name[10]; //姓名
char birthday[11]; //期
char sex[3]; //性别
char nation[10]; //民族
char department[20]; //院系
char major[20]; //专业
char province[20]; //省份
int score; //卷面绩
int add; //加
int total; //总=卷面绩+加
}STU;
int menu();
int enter(STU s[]);
void print(STU s[], int n);
void search(STU s[], int n);
int insert(STU s[], int n);
int del(STU s[], int n);
void save(STU s[], int n);
int load(STU s[]);
void sort(STU s[], int n);
void modify(STU st[], int n);
void printone(STU s);
void back();
void reinput();
void enterone(STU *s);
void copystu(const STU *a, STU *b);
int main(){
STU stu[NUM];
int num=0;
while(1){
switch(menu()){
case 1: num += enter(stu); break;
case 2: search(stu,num); break;
case 3: num += insert(stu,num); break;
case 4: num -= del(stu, num); break;
case 5: save(stu, num); break;
case 6: num=load(stu); break;
case 7: sort(stu, num); break;
case 8: modify(stu, num); break;
case 9: print(stu, num); break;
case 10: return 0;
default: printf(" >>> Unknown Command!!!\n");
}
}
return 0;
}
int menu(){
int in = -1;
printf("\n\n*****************************************************************\n\n"
" 档案库\n\n"
"菜单:\n\n"
" 1.输入记录 2.查找记录 3.插入记录 4.删除记录\n\n"
" 5.保存数据 6.加载数据 7.排序记录 8.修改记录\n\n"
" 9.打印数据 10.退程序\n\n"
"*****************************************************************\n"
"Please input command: ");
scanf("%2d",&in);
while(getchar()!='\n');
return in;
}
int enter(STU s[]){
int n, f, ok=0, i;
printf("输入要添加记录数目: ");
do{
f=scanf("%2d", &n);
if(f==0 || n>=NUM){
if(n>=NUM) printf("能存储%d条记录",NUM);
reinput();
}else ok=1;
}while(!ok);
for(i=0; i printf("始输入第%d位信息\n\n",i+1);
enterone(s+i);
printf("第%d位信息输入完毕\n\n");
}
printf("全部输入完毕\n\n");
return n;
}
void print(STU s[], int n){
int i;
printf("\n所档案\n");
for(i=0; i printf("\n序号 %d :\n",i+1);
printone(s[i]);
printf(">>> 按Enter键显示\n");
getchar();
}
printf("已打印所条目\n");
back();
}
void search(STU s[],int n){
char name[10];
int i,j=0;
printf("输入要查找姓名(目前仅提供姓名检索)\n ");
while(scanf("%9s",name)==0) reinput();
while(getchar()!='\n');
for(i=0;i if(!strcmp(s[i].name, name)){
printone(s[i]);
j++;
}
}
if(!j) printf("未找相关记录\n");
back();
}
int insert(STU s[], int n){
STU in,temp;
int i,j;
char no[11];
if(n>=NUM){
printf("容量足插入新记录\n");
back();
return 0;
}
enterone(&in);
printf("输入完毕\n现输入某记录号新记录插指定记录前:\n");
while(scanf("%10s", no)==0) reinput();
for(i=0;i if(!strcmp(s[i].no, no)){
for(j=n-1;j>=i;j--){
copystu(s+j,s+j+1);
}
copystu(&in,s+i);
printf("新记录已插入指定位置\n");
back();
return 1;
}
}
printf("没找与指定号匹配记录已自新记录添加末尾\n");
copystu(&in,s+n);
back();
return 1;
}
int del(STU s[], int n){
char no[11];
int i,j;
printf("输入要删除记录号:\n");
while(scanf("%10s",&no)==0) reinput();
for(i=0;i if(!strcmp(s[i].no, no)){
for(j=i;j copystu(s+j+1,s+j);
}
printf("记录已删除\n");
back();
return 1;
}
}
printf("没找指定记录\n");
back();
return 0;
}
void save(STU s[], int n){
char nm[50];
FILE* f;
int i;
printf("输入文件路径名称: \n");
while(scanf("%49s",nm)==0) reinput();
if((f=fopen(nm,"a"))==NULL){
if((f=fopen(nm,"w"))==NULL){
printf("文件打或创建失败");
back();
return;
}
}
fprintf(f,"%d\n",n);
for(i=0; i fprintf(f,"%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%d\n%d\n%d\n",
s[i].no, s[i].name, s[i].birthday, s[i].sex, s[i].nation,
s[i].department,s[i].major,s[i].province,s[i].score,s[i].add,s[i].total);
}
fclose(f);
printf("文件已保存: %s\n",nm);
}
int load(STU s[]){
char nm[50];
FILE* f;
int i, n=0;
printf("输入文件路径名称: \n");
while(scanf("%49s",nm)==0) reinput();
if((f=fopen(nm,"r"))==NULL){
printf("文件打失败");
back();
return 0;
}
fscanf(f,"%d",&n);
if(n>NUM) n=NUM;
for(i=0; i fscanf(f,"%s %s %s %s %s %s %s %s %d %d %d",
&s[i].no, &s[i].name, &s[i].birthday, &s[i].sex, &s[i].nation,
&s[i].department,&s[i].major,&s[i].province,&s[i].score,&s[i].add,&s[i].total);
}
fclose(f);
printf("记录加载完毕\n");
back();
return n;
}
void sort(STU s[], int n){
STU temp;
int i, j;
for(i=0; i for(j=0;j if(s[j].total copystu(s+j+1,&temp);
copystu(s+j,s+j+1);
copystu(&temp,s+j);
}
printf("已按总高低进行排序\n");
back();
}
void modify(STU st[], int n){
STU *s=NULL;
char no[11];
int i,j, c;
char item[10][10]={"号","姓名","期","性别","民族","院系",
"专业","省份","卷面绩","加"};
printf("输入要修改记录号:\n");
while(scanf("%10s",&no)==0) reinput();
while(getchar()!='\n');
for(i=0;i if(!strcmp(st[i].no, no)){
s=st+i;
for(j=0;j<10;j++){
printf("修改 %s ?(确定输入’y‘)\n",item[j]);
if((c=getchar())=='y' || c=='Y')
switch(j){
case 0:
while(scanf("%10s",s->no)==0) reinput(); break;
case 1:
while(scanf("%9s",s->name)==0) reinput(); break;
case 2:
while(scanf("%10s",s->birthday)==0) reinput(); break;
case 3:
while(scanf("%2s",s->sex)==0) reinput(); break;
case 4:
while(scanf("%9s",s->nation)==0) reinput(); break;
case 5:
while(scanf("%19s",s->department)==0) reinput(); break;
case 6:
while(scanf("%19s",s->major)==0) reinput(); break;
case 7:
while(scanf("%19s",s->province)==0) reinput(); break;
case 8:
while(scanf("%d",&(s->score))==0 || s->score<0) reinput(); break;
case 9:
while(scanf("%d",&(s->add))==0 ) reinput(); break;
}
while(getchar()!='\n');
}
s->total=s->score+s->add;
printf("修改完\n");
back();
return;
}
}
printf("没找指定记录\n");
back();
}
void printone(STU s){
printf(" 号: %s\n"
" 姓名: %s\n"
" 期: %s\n"
" 性别: %s\n"
" 民族: %s\n"
" 院系: %s\n"
" 专业: %s\n"
" 省份: %s\n"
" 卷面绩: %d\n"
" 加: %d\n"
" 总: %d\n",
s.no, s.name,s.birthday,s.sex,s.nation,
s.department,s.major,s.province,s.score,s.add,s.total);
}
void back(){
printf("\n按Enter键返主菜单\n");
getchar();
}
void reinput(){
printf("输入合重新输入:\n ");
while(getchar()!='\n');
}
void enterone(STU *s){
printf("号:\n ");
while(scanf("%10s",s->no)==0) reinput();
while(getchar()!='\n');
printf("姓名:\n ");
while(scanf("%9s",s->name)==0) reinput();
while(getchar()!='\n');
printf("期(.月.):\n ");
while(scanf("%10s",s->birthday)==0) reinput();
while(getchar()!='\n');
printf("性别:\n ");
while(scanf("%2s",s->sex)==0) reinput();
while(getchar()!='\n');
printf("民族:\n ");
while(scanf("%9s",s->nation)==0) reinput();
while(getchar()!='\n');
printf("院系:\n ");
while(scanf("%19s",s->department)==0) reinput();
while(getchar()!='\n');
printf("专业:\n ");
while(scanf("%19s",s->major)==0) reinput();
while(getchar()!='\n');
printf("省份:\n ");
while(scanf("%19s",s->province)==0) reinput();
while(getchar()!='\n');
printf("卷面绩:\n ");
while(scanf("%d",&(s->score))==0 || s->score<0) reinput();
while(getchar()!='\n');
printf("加:\n ");
while(scanf("%d",&(s->add))==0 ) reinput();
while(getchar()!='\n');
s->total=s->score+s->add;
}
void copystu(const STU *a, STU *b){
strcpy(b->no, a->no);
strcpy(b->name, a->name);
strcpy(b->birthday, a->birthday);
strcpy(b->sex, a->sex);
strcpy(b->nation, a->nation);
strcpy(b->department, a->department);
strcpy(b->major, a->major);
strcpy(b->province, a->province);
b->score=a->score;
b->add=a->add;
b->total=a->total;
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com