本文目錄一覽:
跪求c語言的學生信息管理
#include”stdio.h”
#include”stdlib.h”
#include”string.h”
#define N 3
typedef struct z1
{
char no[11];
char name[15];
int score[N];
float sum;
float average;
int order;
struct z1 *next;
}STUDENT;
STUDENT *init();
STUDENT *create();
STUDENT *del(STUDENT *h);
void print(STUDENT *h);
void search1(STUDENT *h);
void search2(STUDENT *h);
STUDENT *insert(STUDENT *h);
void sort(STUDENT *h);
void save(STUDENT *h);
void tongji(STUDENT *h);
int menu_select();
STUDENT *load();
void inputs(char *prompt,char *s,int count);
STUDENT *load();
main()
{
int i;
STUDENT *head;
head=init();
for(;;)
{
switch(menu_select())
{
case 0:head=init();break;
case 1:head=create();break;
case 2:head=insert(head);break;
case 3:save(head);break;
case 4:print(head);break;
case 5:search1(head);break;
case 6:head=del(head);break;
case 7:sort(head);break;
case 8:tongji(head);break;
case 9:search2(head);break;
case 10:exit(0);
}
}
}
int menu_select()
{
char *menu[]={“************菜單************”,
“0. 初始化鏈表”,
“1. 輸入學生成績”,
“2. 插入學生成績”,
“3. 保存學生記錄”,
“4. 顯示學生記錄”,
“5. 按學號查找學生信息”,
“6. 刪除指定學號的學生信息”,
“7. 按某一門課對學生成績排序”,
“8. 統計某門課程的學生成績”,
“9. 按姓名查找學生信息”,
“10. 退出系統”};
char s[3];
int c,i;
for(i=0;i=11;i++)
printf(” %s\n”,menu[i]);
do
{
printf(“\n請選擇0~10中的某一個選項\n”);
scanf(“%s”,s);
c=atoi(s);
}while(c0||c10);
return c;
}
STUDENT *init()
{
return NULL;
}
STUDENT *create()
{
int i;int s;
STUDENT *h=NULL,*info;
for(;;)
{
info=(STUDENT *)malloc(sizeof(STUDENT));
if(!info)
{
printf(“\n內存不足”);
return NULL;
}
inputs(“輸入學號:”,info-no,11);
if(info-no[0]==’@’)break;
inputs(“輸入姓名:”,info-name,15);
printf(“開始輸入%d門課的成績\n”,N);
s=0;
for(i=0;iN;i++)
{
do{
printf(“第%d門分數:”,i+1);
scanf(“%d”,info-score[i]);
if(info-score[i]100||info-score[i]0)
printf(“輸入成績錯誤,請重新輸入:\n”);
}while(info-score[i]100||info-score[i]0);
s=s+info-score[i];
}
info-sum=s;
info-average=(float)s/N;
info-order=0;
info-next=h;
h=info;
}
return h;
}
void inputs(char *prompt,char *s,int count)
{
char p[255];
do
{
printf(prompt);
scanf(“%s”,p);
if(strlen(p)count)
printf(“\n太長了!\n”);
}while(strlen(p)count);
strcpy(s,p);
}
void print(STUDENT *h)
{
int i=0;
STUDENT *p;
p=h;
printf(“\n\n\n***********************學生***********************\n”);
printf(“|序號|學號 | 姓名 | 語文 | 英語 |數學 | 總分 |平均分 |名次 |\n”);
printf(“|—|——-|——–|—-|—-|—-|——|——|—|\n”);
while(p!=NULL)
{
i++;
printf(“|%3d |%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n”,i,p-no,p-name,p-score[0],p-score[1],p-score[2],p-sum,p-average,p-order);
p=p-next;
}
printf(“***********************end***********************\n”);
}
STUDENT *del(STUDENT *h)
{
STUDENT *p,*q;
char s[11];
printf(“請輸入要刪除的學生的學號\n”);
scanf(“%s”,s);
q=p=h;
while(strcmp(p-no,s)p!=NULL)
{
q=p;
p=p-next;
}
if(p==NULL)
printf(“\n鏈表中沒有學號為%s的學生\n”,s);
else
{
printf(“\n\n\n***********************找到了***********************\n”);
printf(“|學號 | 姓名 | 語文 | 英語 | 數學 | 總分 | 平均分 | 名次 |\n”);
printf(“|———-|———-|—-|—-|—-|——|——|—|\n”);
printf(“|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n”,p-no,p-name,p-score[0],p-score[1],p-score[2],p-sum,p-average,p-order);
printf(“***********************end***********************\n”);
printf(“請按任意鍵刪除\n”);
getchar();
if(p==h)
h=p-next;
else q-next=p-next;
free(p);
printf(“\n已經刪除學號為%s的學生\n”,s);
printf(“不要忘了保存數據\n”);
}
return h;
}
void search1(STUDENT *h)
{
STUDENT *p;
char s[11];
printf(“請輸入你要查找的同學的學號\n”);
scanf(“%s”,s);
p=h;
while(strcmp(p-no,s)p!=NULL)
p=p-next;
if(p==NULL)
printf(“‘n沒有學號為%s的學生\n”,s);
else
{
printf(“\n\n\n***********************找到了***********************\n”);
printf(“|學號 | 姓名 | 語文 | 英語 | 數學 | 總分 | 平均分 | 名次 |\n”);
printf(“|———-|———–|—-|—-|—-|——|——|—|\n”);
printf(“|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n”,p-no,p-name,p-score[0],p-score[1],p-score[2],p-sum,p-average,p-order);
printf(“***********************end***********************\n”);
}
}
void search2(STUDENT *h)
{
STUDENT *p;
char s[11];
printf(“請輸入你要查找的同學的姓名\n”);
scanf(“%s”,s);
p=h;
while(strcmp(p-name,s)p!=NULL)
p=p-next;
if(p==NULL)
printf(“\n沒有姓名為%s的學生\n”,s);
else
{
printf(“\n\n\n***********************找到了***********************\n”);
printf(“|學號 | 姓名 | 語文 | 英語 | 數學 | 總分 | 平均分 | 名次 |\n”);
printf(“|———-|———–|—-|—-|—-|——|——|—|\n”);
printf(“|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n”,p-no,p-name,p-score[0],p-score[1],p-score[2],p-sum,p-average,p-order);
printf(“***********************end***********************\n”);
}
}
STUDENT *insert(STUDENT *h)
{
STUDENT *p,*q,*info;
char s[11];
int s1,i;
printf(“請輸入插入點的學生學號\n”);
scanf(“%s”,s);
printf(“\n請輸入新的學生信息\n”);
info=(STUDENT *)malloc(sizeof(STUDENT));
if(!info)
{
printf(“\n內存不足!”);
return NULL;
}
inputs(“輸入學號:”,info-no,11);
inputs(“輸入姓名:”,info-name,15);
printf(“請輸入%d門課的分數\n”,N);
s1=0;
for(i=0;iN;i++)
{
do{
printf(“分數%d”,i+1);
scanf(“%d”,info-score[i]);
if(info-score[i]100||info-score[i]0)
printf(“輸入數據有誤,請重新輸入\n”);
}while(info-score[i]100||info-score[i]0);
s1=s1+info-score[i];
}
info-sum=s1;
info-average=(float)s1/N;
info-order=0;
info-next=NULL;
p=h;
q=h;
while(strcmp(p-no,s)p!=NULL)
{q=p;p=p-next;}
if(p==NULL)
if(p==h)
h=info;
else q-next=info;
else
if(p==h)
{
info-next=p;
h=info;
}
else
{
info-next=p;
q-next=info;
}
printf(“\n已經插入了%s這個學生\n”,info-name);
printf(“—-不要忘了存檔啊–\n”);
return(h);
}
void save(STUDENT *h)
{
FILE *fp;
STUDENT *p;
char outfile[10];
printf(“請輸入保存文件的文件名,例如 c:\\f1\\te.txt:\n”);
scanf(“%s”,outfile);
if((fp=fopen(outfile,”wb”))==NULL)
{
printf(“不能打開文件\n”);
exit(1);
}
printf(“\n正在保存……\n”);
p=h;
while(p!=NULL)
{
fwrite(p,sizeof(STUDENT),1,fp);
p=p-next;
}
fclose(fp);
printf(“——保存成功!!!——\n”);
}
void sort(STUDENT *h)
{
int i=0,j;
STUDENT *p,*q,*t,*h1;
printf(“請輸入要按哪門課程的編號來排序:(0.語文 1.數學 2.英語)\n”);
scanf(“%d”,j);
h1=h-next;
h-next=NULL;
while(h1!=NULL)
{
t=h1;
h1=h1-next;
p=h;
q=h;
while(t-score[j]p-score[j]p!=NULL)
{
q=p;
p=p-next;
}
if(p==q)
{
t-next=p;
h=t;
}
else
{
t-next=p;
q-next=t;
}
}
p=h;
while(p!=NULL)
{
i++;
p-order=i;
p=p-next;
}
print(h);
printf(“排序成功!!!\n”);
}
void tongji(STUDENT *h)
{
STUDENT *p;
int a,b,i;
printf(“請輸入課程編號\n”);
scanf(“%d”,i);
printf(“請輸入分數段:\n”);
scanf(“%d,%d”,a,b);
p=h;
while(p!=NULL)
{
printf(“\n\n\n***********************找到了***********************\n”);
if(p-score[i]=ap-score[i]=b)
{
printf(“|學號 | 姓名 | 語文 | 英語 | 數學 | 總分 | 平均分 | 名次 |\n”);
printf(“|——–|———|—-|—-|—-|——|——|—|\n”);
printf(“|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n”,p-no,p-name,p-score[0],p-score[1],p-score[2],p-sum,p-average,p-order);
}
p=p-next;
}
printf(“***********************end***********************\n”);
}
用c語言編寫一個學生學籍管理系統
#includeiostream
#includestring
#includefstream
#includeiomanip
using namespace std;
class student
{
protected:
int number;
char name[20];
char sex[6];
char place[20];
char nation[6];
char birth[20];
char party[10];
char id[20];
double score[3];
public:
student *next;
student(){ }
~student(){ }
char* getname(){ return name; }
int getnumber(){ return number;}
double getscore(int i) { return score[3];}
float getg(){ return (score[0]+score[1]+score[2]); }
void input()
{
int e=1;
cout”\t\t\t按提示輸入:”endl;
cout”\t\t輸入編號: “;
cinnumber;
cout”\t\t輸入姓名: “;
cinname;
do
{
cout”\t\t輸入性別: “;
cinsex;
if(strcmp(sex,”男”)==0 || strcmp(sex,”女”)==0)
{
cout”\t\t輸入籍貫: “;
cinplace;
cout”\t\t輸入民族: “;
cinnation;
cout”\t\t輸入生日: “;
cinbirth;
cout”\t\t輸入政治面貌: “;
cinparty;
cout”\t\t輸入身份證號: “;
cinid;
cout”\t\t輸入數學分數: “;
cinscore[0];
cout”\t\t輸入英語分數: “;
cinscore[1];
cout”\t\t輸入計算機分數: “;
cinscore[2];
e=0;
}
else
{
cout”\t\t\t無此類型性別!重新輸入!”endl;
e=1;
}
}while(e);
return ;
}
void input(ifstream is)
{
isnumbernamesexplacenationbirthpartyid
score[0]score[1]score[2];
is.get();
}
void output()
{
cout”學生基本信息如下:”endl;
cout”編號:”number
” 姓名:”name
” 性別:”sex
” 籍貫:”place
” 民族:”nation
” 生日:”birth
” 政治面貌:”partyendl
“身份證號:”id
” 數學:”score[0]
” 英語:”score[1]
” 計算機:”score[2]
” 總分:”getg()endlendl;
}
void output(ofstream os)
{
ossetw(6)number
setw(15)name
setw(6)sex
setw(20)place
setw(6)nation
setw(20)birth
setw(20)party
setw(20)id
setw(6)score[0]
setw(6)score[1]
setw(6)score[2]endl;
}
};
class school
{
public:
school(){ head=new student; head-next=NULL; key=0; }
~school(){ delete head; }
void input();
void mend();
void del();
int find(student **p,int num,char *pn=”^”);
void found();
void show();
void count();
void save();
void begin();
void clear();
char mainmenu();
int getkey(){ return key;}
void setkey(int k){ key=k; }
private:
student *head;
int key;
};
//錄入函數
void school::input()
{
student *p,*p2=NULL;
p=head;
int n;
while(p-next)
p=p-next;
while(n)
{
p2=new student;
p2-input();
p-next=p2;
p2-next=NULL;
p=p-next;
school::setkey(1);
cout”\t\t\t按1繼續,按0返回 : “;
cinn;
}
}
//子查找函數
int school::find(student **p1,int num,char *pn)
{
student *p;
p=head;
while(p-next)
{
(*p1)=p;
if( (p-next)-getnumber()==num||!strcmp( (p-next)-getname(),pn ) )
return 1;
p=p-next;
}
return 0;
}
//查找函數
void school::found()
{
student *p;
int num=-1,n=9;
char name[20]=”^”;
do
{
cout”\t\t1:按編號查找,2:按姓名查找: “;
cinn;
}while(n1||n2);
if(n==1)
{
cout”\t\t\t輸入編號: “;
cinnum;
}
if(n==2)
{
cout”\t\t\t輸入姓名: “;
cinname;
}
if(!find(p,num,name) )
{
cout”\t\t找不到你要查找的內容!”endl;
return;
}
(p-next)-output();
}
//刪除函數
void school::del()
{
student *p,*p2;
int num;
cout”\t\t\t輸入編號: “;
cinnum;
if( !find(p,num,”^”) )
{
cout”\t\t找不到你要刪除的內容!”endl;
return;
}
(p-next)-output();
p2=p-next;
p-next=p2-next;
delete p2;
school::setkey(1);
}
//顯示函數
void school::show()
{
student *p;
p=head;
while(p-next)
{
(p-next)-output();
p=p-next;
}
}
//修改函數
void school::mend()
{
student *p;
int num=-1,n;
char name[20]=”^”;
do
{
cout”\t\t1:按編號修改,2:按姓名修改: “;
cinn;
}while(n1||n2);
if(n==1)
{
cout”\t\t\t輸入編號: “;
cinnum;
}
if(n==2)
{
cout”\t\t\t輸入姓名: “;
cinname;
}
if( !find(p,num,name) )
{
cout”\t\t找不到你要修改的內容!”endl;
return;
}
(p-next)-output();
(p-next)-input();
school::setkey(1);
}
//保存函數
void school::save()
{
student *p;
p=head;
ofstream os(“student.txt”,ios::out);
if (school::getkey()==1)
{
while(p-next)
{
(p-next)-output(os);
p=p-next;
}
}
cout”\t\t\t文件已保存! “endl;
school::setkey(0);
}
//初始化函數
void school::begin()
{
student *p,*p2;
p=head;
clear();
long t;
ifstream is(“student.txt”,ios::in);
if(!is)
{
ofstream os(“student.txt”,ios::out);
os.close();
return ;
}
int num=-1;
while(1)
{
num=-1;
t=is.tellg();
isnum;
is.seekg(t);
if(num0)
{
is.close();
return;
}
p2=new student;
p2-input(is);
p-next=p2;
p2-next=NULL;
p=p-next;
}
}
//清空函數
void school::clear()
{
student *p,*p2;
p=head-next;
while( p )
{
p2=p;
p=p-next;
delete p2;
}
}
//統計函數
void school::count()
{
student *p;
p=head;
int n=0;
double g[3]={0,0,0};
float j[3]={0,0,0};
while(p-next)
{
p=p-next;
n++;
for(int i=0;i3;i++)
{
g[++i]=g[i]+( p-getscore(i) );
(p-getscore(i) )=60? j[i++] : 0 ;
}
}
cout”\t\t\b\b\b\b數學總分:”g[0]” 平均分:”g[0]/n
” 及格率:”j[0]/nendl”\t\t\b\b\b\b英語總分:”g[1]
” 平均分:”g[1]/n” 及格率:”j[1]/nendl
“\t\t\b\b\b\b計算機總分: “g[2]” 平均分: “g[2]/n
” 及格率:”j[2]/nendl;
}
//主選菜單函數
char school::mainmenu()
{
char n[6];
cout”\n\n ☆☆☆☆歡迎進入高校學籍管理系統☆☆☆☆”endlendl
” * * * * * * * * * * * * * * * * * * * * * * * * * * * *”endl
” * * * * * * * * * * * * * * * * * * * * * * * * * * * *”endl
” * * 1: 錄入學生信息 * *”endl
” * * 2: 顯示學生信息 * *”endl
” * * 3: 查找學生信息 * *”endl
” * * 4: 刪除學生信息 * *”endl
” * * 5: 修改學生信息 * *”endl
” * * 6: 統計學生成績 * *”endl
” * * 7: 保存學生信息 * *”endl
” * * 0: 退出系統 * *”endl
” * * * * * * * * * * * * * * * * * * * * * * * * * * * *”endl
” * * * * * * * * * * * * * * * * * * * * * * * * * * * *”endl
” 請選擇:”;
cinn;
return n[0];
}
//主函數
void main()
{
school pp;
int k=1;
char n;
pp.begin();
while(k==1)
{
n=pp.mainmenu();
switch(n)
{
case ‘1’:pp.input(); break;
case ‘2’:pp.show(); break;
case ‘3’:pp.found(); break;
case ‘4’:pp.del(); break;
case ‘5’:pp.mend(); break;
case ‘6’:pp.count(); break;
case ‘7’:pp.save(); break;
case ‘0’:
if(pp.getkey()==1)
{
cout”\t\t\t是否保存? 1 : 保存 0:不保存 : “;
cink;
if(k==1)
pp.save();
}
pp.clear();
k=0;
break;
}
}
}
C語言學生管理系統
#includestdio.h
#includestring.h
#includestdlib.h
#includeconio.h
#define max 20
typedef struct student //學生
{
char sno[max]; // 學號
char sname[max]; //姓名
char sex[max]; //性別
char age[max]; //年齡
char depart[max]; //系
char classs[max]; //班
char grade[max]; //年級
struct student* next;
} student;
student* head;
int LogOn() //登錄模塊,已實現輸入密碼不回顯,如果中途發現輸錯某幾位,可退格鍵重輸
{
char username[max],password[max];
printf(“\n請輸入用戶名:”);
scanf(“%s”,username);
printf(“\n請輸入密碼(最多15位):”);
//開始以不回顯且支持退格方式獲取輸入密碼
int i=0;
while((i=0)(password[i++]=getch())!=13)//條件i=0是用於限制退格的範圍
{
if(password[i-1]==’\b’)//對退格鍵的處理
{
printf(“%c%c%c”,’\b’,’\0′,’\b’);
i=i-2;
}
else
printf(“*”);
}
password[–i]=’\0′;
//已獲取密碼。驗證用戶身份
if(!strcmp(username,”zhang”)!strcmp(password,”8147086″))
{
printf(“\n登錄成功!”);
return 1;
}
else
return 0;
}
void regist()
{
char ch;
student *s,*ptr; //s用來建新結點,ptr用來暫存頭結點
do
{
s=(student*)malloc(sizeof(student)); // 新建一個學生結點
printf(“\n開始註冊…”); //開始註冊
printf(“\n請輸入該學生的學號:”);
scanf(“%s”,s-sno);
printf(“\n請輸入該學生的姓名:”);
scanf(“%s”,s-sname);
printf(“\n請輸入該學生的性別:”);
scanf(“%s”,s-sex);
printf(“\n請輸入該學生的年齡:”);
scanf(“%s”,s-age);
printf(“\n請輸入該學生的系:”);
scanf(“%s”,s-depart);
printf(“\n請輸入該學生所在的班:”);
scanf(“%s”,s-classs);
printf(“\n請輸入該學生所在的年級”);
scanf(“%s”,s-grade);
ptr=head;
head=s;//將新結點插入隊頭
s-next=ptr;
fflush(stdin);
printf(“\n請問是否繼續註冊?(Y/N)”);
scanf(“%c”,ch);
}while(ch==’Y’||ch==’y’);
return;
}
void ElePrint(char str[]) //輸出單個元素
{
if(str==NULL) exit(0);
printf(“%s”,str);
for(unsigned int i=0;i12-strlen(str);i++) printf(” “);//為了對齊輸出,需插入一些空格
return;
}
int LinePrint(student *ptr) //輸出一行
{
if(ptr==NULL) //檢查傳進來的指針
return 0;
printf(“\n”);
ElePrint(ptr-sno);
ElePrint(ptr-sname);
ElePrint(ptr-age);
ElePrint(ptr-sex);
ElePrint(ptr-depart);
ElePrint(ptr-classs);
ElePrint(ptr-grade);
return 1;
}
void print() //輸出全部學生信息
{
student *ptr=head;
printf(“\n學號 姓名 年齡 性別 系 班 年級 “);
while(ptr)
{
LinePrint(ptr);
ptr=ptr-next;
}
printf(“\n”);
return;
}
void search()//查詢模塊
{
int method;//查詢方式
char no[max],name[max],departm[max],clss[max],grades[max]; //用來接收查詢關鍵字
while(1)
{
printf(“\n請選擇查詢方式”);
printf(“\n1.按學號查詢”);
printf(“\n2.按姓名查詢”);
printf(“\n3.按所在系查詢”);
printf(“\n4.按所在班級查詢”);
printf(“\n5.按所在年級查詢”);
printf(“\n6.列印全部學生信息”);
printf(“\n7.返回主菜單\n”);
scanf(“%d”,method);
student *p=head,*temp;
switch(method)
{
case 1:
printf(“\n請輸入要查詢的學號:”);
scanf(“%s”,no);
while(p)
{
if(!strcmp(p-sno,no))
break;
else
{
temp=p;
p=p-next;
}
}
printf(“\n學號 姓名 年齡 性別 系 班 年級 “);
LinePrint(p);
break;
case 2:
printf(“\n請輸入要查詢的姓名:”);
scanf(“%s”,name);
printf(“\n學號 姓名 年齡 性別 系 班 年級 “);
while(p)
{
if(!strcmp(p-sname,name))
LinePrint(p);
p=p-next;
}
break;
case 3:
printf(“\n請輸入學生所在的系:”);
scanf(“%s”,departm);
printf(“\n學號 姓名 年齡 性別 系 班 年級 “);
while(p)
{
if(!strcmp(p-depart,departm))
LinePrint(p);
p=p-next;
}
break;
case 4:
printf(“\n請輸入學生所在的班:”);
scanf(“%s”,clss);
printf(“\n請輸入學生所在的年級:”);
scanf(“%s”,grades);
printf(“\n學號 姓名 年齡 性別 系 班 年級 “);
while(p)
{
if(!strcmp(p-classs,clss)!strcmp(p-grade,grades))
LinePrint(p);
p=p-next;
}
break;
case 5:
printf(“\n請輸入學生所在的年級:”);
scanf(“%s”,grades);
printf(“\n學號 姓名 年齡 性別 系 班 年級 “);
while(p)
{
if(!strcmp(p-grade,grades))
LinePrint(p);
p=p-next;
}
break;
case 6:
print();
break;
case 7:
return;
default:
printf(“很抱歉,暫無此查詢方式!”);
break;
}
}
}
void modify()//修改學生信息
{
char num[max];
student *p=head;
printf(“\n請輸入要修改的學生的學號:”);
scanf(“%s”,num);
while(p)
{
if(!strcmp(p-sno,num))
break;
else
p=p-next;
}
if(p==NULL)
{
printf(“\n錯誤:沒有此學生的信息!\n”);
return;
}
LinePrint(p);
printf(“\n請輸入要修改的該學生的信息:”);
printf(“\n1.姓名”);
printf(“\n2.性別”);
printf(“\n3.年齡”);
printf(“\n4.所在的系”);
printf(“\n5.所在的班”);
printf(“\n6.所在的年級”);
char name1[max],sex1[max],age1[max],depart1[max],class1[max],grade1[max];
int select;
fflush(stdin);
scanf(“%d”,select);
printf(“\n請輸入新的信息:”);
switch(select)
{
case 1:
scanf(“%s”,name1);
strcpy(p-sname,name1);
break;
case 2:
scanf(“%s”,sex1);
strcpy(p-sex,sex1);
break;
case 3:
scanf(“%s”,age1);
strcpy(p-age,age1);
break;
case 4:
scanf(“%s”,depart1);
strcpy(p-depart,depart1);
break;
case 5:
scanf(“%s”,class1);
strcpy(p-classs,class1);
break;
case 6:
scanf(“%s”,grade1);
strcpy(p-grade,grade1);
break;
default:
printf(“\nError!”);
break;
}
LinePrint(p);
return;
}
void del()// 刪除某學生的信息
{
student *p=head,*temp=head,*s;
char num1[max];
printf(“\n請輸入要刪除的學生的學號:”);
scanf(“%s”,num1);
while(p)//查找該學生所在的結點
{
if(!strcmp(p-sno,num1))
break;
else
{
temp=p;
p=p-next;
}
}//while
if(!p)
{
printf(“\n不存在此學生的信息.”);
return;
}
LinePrint(p);//輸出該學生的信息
printf(“\n請問真的要刪除該學生的信息嗎?(Y/N)”);
char ch;
fflush(stdin);
scanf(“%c”,ch);
if(ch==’Y’||ch==’y’)
{
s=p-next;
temp-next=s;
free(p);
printf(“\n已經刪除該學生的信息.”);
}
return;
}
void sort() //排序模塊。將學生記錄按學號從小到大排列。用起泡排序演算法實現
{
student *ptr,*s=head,*p;
int count=0,count1;
while(s)//統計鏈表結點個數
{
count++;
s=s-next;
}
for(int i=1;icount;i++)
{
ptr=head;
p=NULL;
count1=count-i; //用來控制每輪起泡排序的終點,即每次把學號最小的結點移到倒數第i個結點
while(ptrptr-next(count1–))
{
if(strcmp(ptr-sno,ptr-next-sno)0)
{
s=ptr-next;
ptr-next=s-next;
if(p==NULL) //ptr處於隊頭時
head=s;
else
p-next=s;
s-next=ptr;
p=s;
}
else
{
ptr=ptr-next;
if(p==NULL) //ptr處於隊頭時
p=head;
else
p=p-next;
}
}
}
return;
}
void quit()
{
char ch;
printf(“\n真的要退出?(Y/N)”);
fflush(stdin);
scanf(“%c”,ch);
if(ch==’Y’||ch==’y’)
exit(0);
return;
}
int main()
{
int option;
printf(“\nCopyright@2005 KongXinCai All rights reserved.”);
printf(“\n歡迎使用學生信息管理系統!\n”);
//登錄模塊
int icheck=0;
while(icheck3)
{
if(LogOn()==0)
icheck++;
else
break;
}
if(icheck==3)
{
printf(“\n連續登錄三次不成功,退出!”);
exit(0);
}
//系統界面
while(1)
{
printf(“\n\n請選擇需要的服務:”);
printf(“\n1.註冊”);
printf(“\n2.查詢”);
printf(“\n3.修改”);
printf(“\n4.刪除”);
printf(“\n5.排序”);
printf(“\n7.求平均”);
printf(“\n6.退出\n”);
scanf(“%d”,option);
switch(option)
{
case 1:
regist();
break;
case 2:
search();
break;
case 3:
modify();
break;
case 4:
del();
break;
case 5:
sort();
break;
case 6:
quit();
break;
}
}
return 0;
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/247309.html