帮别人做的作业,代码不长,冗余度高,而且幼稚,不到500行,不符合软件工程要求,面向过程,字符界面,没有注释,需要的拿去
传说中的白痴同学录,插入,删除,修改,查询,排序,保存,读取,模块划分清楚,随便改改就变成别的了。
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
void newm();
void open();
void ins();
typedef struct SS S;
struct SS
{
long number;
char address[50];
char name[20];
long zipCode;
long tel;
char email[50];
S *next;
};
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
void newm();
void open();
void ins();
typedef struct SS S;
struct SS
{
long number;
char address[50];
char name[20];
long zipCode;
long tel;
char email[50];
S *next;
};
int built=0;
S h;
S *p=&h;
S *q;
int check(S *c)
{
S *qo;
for(qo=&h;qo!=c;qo=qo->next)
{
if(qo->number==c->number)
{
system("cls");
printf("Already have the same IDNumber.\n");
return (0);
}
}
return (1);
}
S h;
S *p=&h;
S *q;
int check(S *c)
{
S *qo;
for(qo=&h;qo!=c;qo=qo->next)
{
if(qo->number==c->number)
{
system("cls");
printf("Already have the same IDNumber.\n");
return (0);
}
}
return (1);
}
void show2(S *c)
{
printf("ID Number:%d \n",c->number);
printf("Name:%s \n",c->name);
printf("Address:%s\n",c->address);
printf("ZipCode:%d \n",c->zipCode);
printf("Tel:%d \n",c->tel);
printf("E-mail:%s\n",c->email);
}
void ins()
{
int t;
q =(S *)malloc(sizeof(S));
p->next=q;
printf("Please input IDNumber:");
scanf("%ld",&q->number);
printf("Please input Name:");
scanf("%s",q->name);
printf("Please input Address:");
scanf("%s",q->address);
printf("Please input ZipCode:");
scanf("%ld",&q->zipCode);
printf("Please input Tel:");
scanf("%ld",&q->tel);
printf("Please input E-mail:");
scanf("%s",q->email);
t=check(q);
if(t==0) {free( q);ins();}
{
p=q;
system("cls");
}
}
{
printf("ID Number:%d \n",c->number);
printf("Name:%s \n",c->name);
printf("Address:%s\n",c->address);
printf("ZipCode:%d \n",c->zipCode);
printf("Tel:%d \n",c->tel);
printf("E-mail:%s\n",c->email);
}
void ins()
{
int t;
q =(S *)malloc(sizeof(S));
p->next=q;
printf("Please input IDNumber:");
scanf("%ld",&q->number);
printf("Please input Name:");
scanf("%s",q->name);
printf("Please input Address:");
scanf("%s",q->address);
printf("Please input ZipCode:");
scanf("%ld",&q->zipCode);
printf("Please input Tel:");
scanf("%ld",&q->tel);
printf("Please input E-mail:");
scanf("%s",q->email);
t=check(q);
if(t==0) {free( q);ins();}
{
p=q;
system("cls");
}
}
void newm()
{
char abs;
int t;
int n;
p=&h;
for(;;)
{
q = (S *)malloc(sizeof(S));
p->next=q;
printf("Please input IDNumber:");
scanf("%ld",&q->number);
printf("Please input Name:");
scanf("%s",q->name);
printf("Please input Address:");
scanf("%s",q->address);
printf("Please input ZipCode:");
scanf("%ld",&q->zipCode);
printf("Please input Tel:");
scanf("%ld",&q->tel);
printf("Please input E-mail:");
scanf("%s",q->email);
t=check(q);
if(t==0)
{
free((void *) q);
continue;
}
else
{
p=q;
for(n=0;n!=1;)
{
built=1;
system("cls");
printf("Continue? Y/N");
scanf("%c",&abs);
switch(abs)
{
case ‘n’:{system("cls"); return;}
case ‘N’:{system("cls"); return;}
case ‘y’:{system("cls"); n=1;}
case ‘Y’:{system("cls"); n=1;}
}
}
}
}
}
void mod()
{
int num;
char a;
int n;
if(p==&h)
{
printf("No record, press any key to return.");
getch();
return;
}
for(q=&h;q!=p;q=q->next)
show2(q->next);
for(;;)
{
printf("Please input IDNumber:");
scanf("%d",&num);
q=&h;
while(q!=p)
{
if(q->next->number==num)
{
printf("a");
scanf("%s",q->next->name);
printf("b");
scanf("%s",q->next->address);
printf("c");
scanf("%d",&q->next->zipCode);
printf("d");
scanf("%d",&q->next->tel);
printf("e");
scanf("%s",q->next->email);
return;
}
q=q->next;
}
for(n=0;n!=1;)
{
system("cls");
printf("The student is not exist. y:continue n:back to main menu");
scanf("%c",&a);
switch(a)
{
case ‘n’:{system("cls"); return;}
case ‘N’:{system("cls"); return;}
case ‘y’:{system("cls"); n=1;}
case ‘Y’:{system("cls"); n=1;}
}
}
}
}
void del()
{
int num;
char a;
int n;
if(p==&h)
{
printf("No record, press any key to return.");
getch();
return;
}
{
char abs;
int t;
int n;
p=&h;
for(;;)
{
q = (S *)malloc(sizeof(S));
p->next=q;
printf("Please input IDNumber:");
scanf("%ld",&q->number);
printf("Please input Name:");
scanf("%s",q->name);
printf("Please input Address:");
scanf("%s",q->address);
printf("Please input ZipCode:");
scanf("%ld",&q->zipCode);
printf("Please input Tel:");
scanf("%ld",&q->tel);
printf("Please input E-mail:");
scanf("%s",q->email);
t=check(q);
if(t==0)
{
free((void *) q);
continue;
}
else
{
p=q;
for(n=0;n!=1;)
{
built=1;
system("cls");
printf("Continue? Y/N");
scanf("%c",&abs);
switch(abs)
{
case ‘n’:{system("cls"); return;}
case ‘N’:{system("cls"); return;}
case ‘y’:{system("cls"); n=1;}
case ‘Y’:{system("cls"); n=1;}
}
}
}
}
}
void mod()
{
int num;
char a;
int n;
if(p==&h)
{
printf("No record, press any key to return.");
getch();
return;
}
for(q=&h;q!=p;q=q->next)
show2(q->next);
for(;;)
{
printf("Please input IDNumber:");
scanf("%d",&num);
q=&h;
while(q!=p)
{
if(q->next->number==num)
{
printf("a");
scanf("%s",q->next->name);
printf("b");
scanf("%s",q->next->address);
printf("c");
scanf("%d",&q->next->zipCode);
printf("d");
scanf("%d",&q->next->tel);
printf("e");
scanf("%s",q->next->email);
return;
}
q=q->next;
}
for(n=0;n!=1;)
{
system("cls");
printf("The student is not exist. y:continue n:back to main menu");
scanf("%c",&a);
switch(a)
{
case ‘n’:{system("cls"); return;}
case ‘N’:{system("cls"); return;}
case ‘y’:{system("cls"); n=1;}
case ‘Y’:{system("cls"); n=1;}
}
}
}
}
void del()
{
int num;
char a;
int n;
if(p==&h)
{
printf("No record, press any key to return.");
getch();
return;
}
for(q=&h;q!=p;q=q->next)
show2(q->next);
for(;;)
{
printf("Please input IDNumber:");
scanf("%d",&num);
q=&h;
while(q!=p)
{
if(q->next->number==num)
{
printf("Do you want to delete this student? y: yes n: no");
scanf("%c",&a);
if(a==’y')
{
if(q->next==p) p=q;
q->next=q->next->next;
return;
}
else return;
}
q=q->next;
}
for(n=0;n!=1;)
{
system("cls");
printf("The student is not exist. y:continue n:back to main menu");
scanf("%c",&a);
switch(a)
{
case ‘n’:{system("cls"); return;}
case ‘N’:{system("cls"); return;}
case ‘y’:{system("cls"); n=1;}
case ‘Y’:{system("cls"); n=1;}
}
}
}
}
void sort()
{
S *s;
int tag;
long min=-1;
long minp=100000000;
if(p==&h)
{
printf("No record, press any key to return.");
getch();
return;
}
system("cls");
for(;;)
{
tag=0;
for(q=&h;q!=p;)
{
if(q->next->number>min&&q->next->number<minp)
{
minp=q->next->number;
s=q->next;
tag=1;
}
q=q->next;
}
if(tag==1)
{
show2(s);
min=minp;
minp=100000000;
continue;
}
break;
}
getch();
}
void ByNumber()
{
int num;
int n;
char a;
if(p==&h)
{
printf("No record, press any key to return.");
getch();
return;
}
for(;;)
{
printf("Please input IDNumber:");
scanf("%d",&num);
q=&h;
while(q!=p)
{
if(q->next->number==num)
{
show2(q->next);
getch();
return;
}
q=q->next;
}
for(n=0;n!=1;)
{
system("cls");
printf("The student is not exist. y:continue n:back to main menu");
scanf("%c",&a);
switch(a)
{
case ‘n’:{system("cls"); return;}
case ‘N’:{system("cls"); return;}
case ‘y’:{system("cls"); n=1;}
case ‘Y’:{system("cls"); n=1;}
}
}
}
}
void ByName()
{
char name[20];
char a;
int n;
if(p==&h)
{
printf("No record, press any key to return.");
getch();
return;
}
for(;;)
{
printf("Please input name:");
scanf("%s",name);
q=&h;
while(q!=p)
{
if(!strcmp(q->next->name,name))
{
show2(q->next);
getch();
return;
}
q=q->next;
}
for(n=0;n!=1;)
{
system("cls");
printf("The student is not exist. y:continue n:back to main menu");
scanf("%c",&a);
switch(a)
{
case ‘n’:{system("cls"); return;}
case ‘N’:{system("cls"); return;}
case ‘y’:{system("cls"); n=1;}
case ‘Y’:{system("cls"); n=1;}
}
}
}
}
show2(q->next);
for(;;)
{
printf("Please input IDNumber:");
scanf("%d",&num);
q=&h;
while(q!=p)
{
if(q->next->number==num)
{
printf("Do you want to delete this student? y: yes n: no");
scanf("%c",&a);
if(a==’y')
{
if(q->next==p) p=q;
q->next=q->next->next;
return;
}
else return;
}
q=q->next;
}
for(n=0;n!=1;)
{
system("cls");
printf("The student is not exist. y:continue n:back to main menu");
scanf("%c",&a);
switch(a)
{
case ‘n’:{system("cls"); return;}
case ‘N’:{system("cls"); return;}
case ‘y’:{system("cls"); n=1;}
case ‘Y’:{system("cls"); n=1;}
}
}
}
}
void sort()
{
S *s;
int tag;
long min=-1;
long minp=100000000;
if(p==&h)
{
printf("No record, press any key to return.");
getch();
return;
}
system("cls");
for(;;)
{
tag=0;
for(q=&h;q!=p;)
{
if(q->next->number>min&&q->next->number<minp)
{
minp=q->next->number;
s=q->next;
tag=1;
}
q=q->next;
}
if(tag==1)
{
show2(s);
min=minp;
minp=100000000;
continue;
}
break;
}
getch();
}
void ByNumber()
{
int num;
int n;
char a;
if(p==&h)
{
printf("No record, press any key to return.");
getch();
return;
}
for(;;)
{
printf("Please input IDNumber:");
scanf("%d",&num);
q=&h;
while(q!=p)
{
if(q->next->number==num)
{
show2(q->next);
getch();
return;
}
q=q->next;
}
for(n=0;n!=1;)
{
system("cls");
printf("The student is not exist. y:continue n:back to main menu");
scanf("%c",&a);
switch(a)
{
case ‘n’:{system("cls"); return;}
case ‘N’:{system("cls"); return;}
case ‘y’:{system("cls"); n=1;}
case ‘Y’:{system("cls"); n=1;}
}
}
}
}
void ByName()
{
char name[20];
char a;
int n;
if(p==&h)
{
printf("No record, press any key to return.");
getch();
return;
}
for(;;)
{
printf("Please input name:");
scanf("%s",name);
q=&h;
while(q!=p)
{
if(!strcmp(q->next->name,name))
{
show2(q->next);
getch();
return;
}
q=q->next;
}
for(n=0;n!=1;)
{
system("cls");
printf("The student is not exist. y:continue n:back to main menu");
scanf("%c",&a);
switch(a)
{
case ‘n’:{system("cls"); return;}
case ‘N’:{system("cls"); return;}
case ‘y’:{system("cls"); n=1;}
case ‘Y’:{system("cls"); n=1;}
}
}
}
}
void qu()
{
char input;
for(;;)
{
system("cls");
printf("|———————————————| \n");
printf("| Query | \n");
printf("|———————————————| \n");
printf("| 0—-By IDNumber | \n");
printf("| 1—-By Name | \n");
printf("| 2—-Return | \n");
printf("|———————————————| \n");
input=getch();
switch(input)
{
case ’0′: system("cls"); ByNumber();break;
case ’1′: system("cls"); ByName();break;
case ’2′: return;
}
}
}
{
char input;
for(;;)
{
system("cls");
printf("|———————————————| \n");
printf("| Query | \n");
printf("|———————————————| \n");
printf("| 0—-By IDNumber | \n");
printf("| 1—-By Name | \n");
printf("| 2—-Return | \n");
printf("|———————————————| \n");
input=getch();
switch(input)
{
case ’0′: system("cls"); ByNumber();break;
case ’1′: system("cls"); ByName();break;
case ’2′: return;
}
}
}
void save()
{
char *filename;
FILE *fp;
filename=malloc(20*sizeof(char));
if(p==&h)
{
printf("No record, press any key to return.");
getch();
return;
}
q=&h;
printf("Please input the filename:");
scanf("%s",filename);
fp=fopen(filename,"w");
for(q=&h;q!=p;)
{
fwrite(q->next,sizeof(S),1,fp);
q=q->next;
}
fclose(fp);
}
void load()
{
char *filename;
FILE *fp;
filename=malloc(20*sizeof(char));
q=&h;
printf("Please input the filename:");
scanf("%s",filename);
if((fp=fopen(filename,"r"))==NULL)
{
printf("error");
getch();
return;
}
for(p=&h;;)
{
fgetc(fp);
if (feof(fp)) break;
fseek(fp,-1L,1);
q=(S *)malloc(sizeof(S));
fread(q,sizeof(S),1,fp);
p->next=q;
p=q;
}
built=1;
fclose(fp);
}
void open()
{ char start;
for(;;)
{
system("cls");
printf("|———————————————|\n");
printf("| MAIN MENU |\n");
printf("|—- ——- ——————————–|\n");
printf("| A—-New |\n");
printf("| B—-Insert |\n");
printf("| C—-Modify |\n");
printf("| D—-Delete |\n");
printf("| E—-Sort |\n");
printf("| F—-Query |\n");
printf("| S—-Save |\n");
printf("| L—-Load |\n");
printf("| Q—-Quit |\n");
printf("|———————————————|\n");
start=getch();
if(built==1)
{
switch(start)
{
case ‘a’: system("cls"); newm();break;
case ‘A’: system("cls"); newm();break;
case ‘b’: system("cls"); ins();break;
case ‘B’: system("cls"); ins();break;
case ‘c’: system("cls"); mod();break;
case ‘C’: system("cls"); mod();break;
case ‘d’: system("cls"); del();break;
case ‘D’: system("cls"); del();break;
case ‘e’: system("cls"); sort();break;
case ‘E’: system("cls"); sort();break;
case ‘f’: system("cls"); qu();break;
case ‘F’: system("cls"); qu();break;
case ‘s’: system("cls"); save();break;
case ‘S’: system("cls"); save();break;
case ‘l’: system("cls"); load();break;
case ‘L’: system("cls"); load();break;
case ‘q’: exit(0);
case ‘Q’: exit(0);
}
}
else{
switch(start)
{
case ‘a’: system("cls"); newm();break;
case ‘A’: system("cls"); newm();break;
case ‘l’: system("cls"); load();break;
case ‘L’: system("cls"); load();break;
default: system("cls");printf("Please New or Load first");start=getch();
}
}
}
}
{
char *filename;
FILE *fp;
filename=malloc(20*sizeof(char));
if(p==&h)
{
printf("No record, press any key to return.");
getch();
return;
}
q=&h;
printf("Please input the filename:");
scanf("%s",filename);
fp=fopen(filename,"w");
for(q=&h;q!=p;)
{
fwrite(q->next,sizeof(S),1,fp);
q=q->next;
}
fclose(fp);
}
void load()
{
char *filename;
FILE *fp;
filename=malloc(20*sizeof(char));
q=&h;
printf("Please input the filename:");
scanf("%s",filename);
if((fp=fopen(filename,"r"))==NULL)
{
printf("error");
getch();
return;
}
for(p=&h;;)
{
fgetc(fp);
if (feof(fp)) break;
fseek(fp,-1L,1);
q=(S *)malloc(sizeof(S));
fread(q,sizeof(S),1,fp);
p->next=q;
p=q;
}
built=1;
fclose(fp);
}
void open()
{ char start;
for(;;)
{
system("cls");
printf("|———————————————|\n");
printf("| MAIN MENU |\n");
printf("|—- ——- ——————————–|\n");
printf("| A—-New |\n");
printf("| B—-Insert |\n");
printf("| C—-Modify |\n");
printf("| D—-Delete |\n");
printf("| E—-Sort |\n");
printf("| F—-Query |\n");
printf("| S—-Save |\n");
printf("| L—-Load |\n");
printf("| Q—-Quit |\n");
printf("|———————————————|\n");
start=getch();
if(built==1)
{
switch(start)
{
case ‘a’: system("cls"); newm();break;
case ‘A’: system("cls"); newm();break;
case ‘b’: system("cls"); ins();break;
case ‘B’: system("cls"); ins();break;
case ‘c’: system("cls"); mod();break;
case ‘C’: system("cls"); mod();break;
case ‘d’: system("cls"); del();break;
case ‘D’: system("cls"); del();break;
case ‘e’: system("cls"); sort();break;
case ‘E’: system("cls"); sort();break;
case ‘f’: system("cls"); qu();break;
case ‘F’: system("cls"); qu();break;
case ‘s’: system("cls"); save();break;
case ‘S’: system("cls"); save();break;
case ‘l’: system("cls"); load();break;
case ‘L’: system("cls"); load();break;
case ‘q’: exit(0);
case ‘Q’: exit(0);
}
}
else{
switch(start)
{
case ‘a’: system("cls"); newm();break;
case ‘A’: system("cls"); newm();break;
case ‘l’: system("cls"); load();break;
case ‘L’: system("cls"); load();break;
default: system("cls");printf("Please New or Load first");start=getch();
}
}
}
}
void main()
{
open();
}
{
open();
}
老弟,很勤奋嘛!
这还叫不长啊