學生選修課程系統設計c語言
㈠ c語言課程設計學籍管理系統
這個是我曾經做的,上面功課和你的不一樣,把漢字改下就行了,還有那個人數,人數和排名最後一名數字一樣,你運行一下就清楚了
#include<stdio.h>
#include<malloc.h>
#define M "%-6s%-6d%-6d%-6d%-6d%-6d%-7d%-6d\n"
#define H p->name,p->num,p->grade.Escore,p->grade.Mscore,p->grade.Cscore,p->grade.Pscore,p->grade.Allscore,p->grade.Allrank
typedef struct score{
int Escore;
int Mscore;
int Cscore;
int Pscore;
int Allscore;
int Allrank;
}Sco;
typedef struct student{
char name [20];
int num;
struct score grade;
struct student *next;
}*stu;
struct student *Create(struct student *head)
{
int i,n;
printf("請輸入學生個數;");
scanf("%d",&n);
printf("請輸入信息和成績\n");
printf("姓名,學號,英語,高數,C語言,體育:");
printf("\n");
stu p,q;
p=q=(stu)malloc(sizeof(student));
head=p;
for(i=0;i<n;i++)
{
p->next=q;
p=q;
scanf("%s%d%d%d%d%d",q->name,&q->num,&q->grade.Escore,&q->grade.Mscore,&q->grade.Cscore,&q->grade.Pscore);
q->grade.Allscore=q->grade.Escore+q->grade.Mscore+q->grade.Cscore+q->grade.Pscore;
q=(stu)malloc(sizeof(student));
}
p->next=NULL;
return head;
}
struct student *Change(struct student *head)
{
int n,i,k;
stu p;
p=head;
printf("請輸入要修改的學號:");
scanf("%d",&i);
printf("1.英語 2.高數 3.C語言 4.體育\n");
printf("請輸入要修改的成績:");
scanf("%d",&n);
while(p)
{
if(i==p->num)
switch(n)
{
case 1:
printf("請輸入英語分數:");
scanf("%d",&k);
p->grade.Escore=k;
break;
case 2:
printf("請輸入高數分數:");
scanf("%d",&k);
p->grade.Mscore=k;
break;
case 3:
printf("請輸入C語言分數:");
scanf("%d",&k);
p->grade.Cscore=k;
break;
case 4:
printf("請輸入體育分數:");
scanf("%d",&k);
p->grade.Pscore=k;
break;
}
if(i==p->num) break;
if(p->next)
p=p->next;
}
p->grade.Allscore=p->grade.Escore+p->grade.Mscore+p->grade.Cscore+p->grade.Pscore;
return head;
}
struct student *Insert(struct student *head)
{
stu p,q;
p=q=(stu)malloc(sizeof(student));
p=head;
printf("請輸入姓名和學號:\n");
scanf("%s%d",q->name,&q->num);
printf("請輸入英語,高數,C語言,體育成績:\n");
scanf("%d%d%d%d",&q->grade.Escore,&q->grade.Mscore,&q->grade.Cscore,&q->grade.Pscore);
q->grade.Allscore=q->grade.Escore+q->grade.Mscore+q->grade.Cscore+q->grade.Pscore;
while(p->next)
{
p=p->next;
}
p->next=q;
p=p->next;
p->next=NULL;
return head;
}
struct student *Delet(struct student *head)
{
stu p,q,m;
int n;
printf("請輸入要刪除的學號:");
scanf("%d",&n);
p=head;
if(n==p->num)
{
q=p;
head=p->next;
free(p);
}
else
{
q=p->next;
while(q)
if(q->next==NULL&&n==q->num)
{
m=q;
free(q);
p->next=NULL;
q=NULL;
}
else if(q->next!=NULL&&n==q->num)
{
p->next=q->next;
free(q);
q=NULL;
}
else
{
if(q->next!=NULL)
{
p=q;
q=q->next;
}
}
}
return head;
}
void Look(struct student *head)
{
stu p;
int n,i,k;
p=head;
printf("1.按學號查找 2.按分數查找\n");
printf("請輸入查找的類別:");
scanf("%d",&n);
if(n==1)
{
printf("請輸入要查找的學號:");
scanf("%d",&i);
while(p)
{
if(i==p->num)
{
printf("姓名 學號 英語 高數 C語言 體育 總成績 排名\n");
printf(M,H);
}
if(i==p->num) break;
if(p->next)
p=p->next;
}
}
if(n==2)
{
printf("1.英語 2.高數 3.C語言 4.體育 5.總分\n");
printf("請輸入要查找的課程:");
scanf("%d",&i);
switch(i)
{
case 1:
printf("請輸入要查找的英語最低分數:");
scanf("%d",&k);
printf("姓名 學號 英語 高數 C語言 體育 總成績 排名\n");
while(p)
{
if(k<=p->grade.Escore)
printf(M,H);
p=p->next;
}
break;
case 2:
printf("請輸入要查找的高數最低分數:");
scanf("%d",&k);
printf("姓名 學號 英語 高數 C語言 體育 總成績 排名\n");
while(p)
{
if(k<=p->grade.Mscore)
printf(M,H);
p=p->next;
}
break;
case 3:
printf("請輸入要查找C語言語最低分數:");
scanf("%d",&k);
printf("姓名 學號 英語 高數 C語言 體育 總成績 排名\n");
while(p)
{
if(k<=p->grade.Cscore)
printf(M,H);
p=p->next;
}
break;
case 4:
printf("請輸入要查找的體育最低分數:");
scanf("%d",&k);
printf("姓名 學號 英語 高數 C語言 體育 總成績 排名\n");
while(p)
{
if(k<=p->grade.Pscore)
printf(M,H);
p=p->next;
}
break;
case 5:
printf("請輸入要查找的總分最低分數:");
scanf("%d",&k);
printf("姓名 學號 英語 高數 C語言 體育 總成績 排名\n");
while(p)
{
if(k<=p->grade.Allscore)
printf(M,H);
p=p->next;
}
break;
}
}
}
struct student *Rank(struct student *head,struct student *p,int j)
{
int i;
stu q;
i=p->grade.Allscore;
q=head;
while(q)
{
if(q->grade.Allscore>i)
j++;
if(!q->next)break;
q=q->next;
}
p->grade.Allrank=j;
while(p)
{
if(!p->next)break;
{
p=p->next;
Rank(head,p,1);
}
}
return head;
}
void Rankshow(struct student *head,int j)
{
int i;
stu p,q;
q=head;
p=head;
i=j;
printf("姓名 學號 英語 高數 C語言 體育 總成績 排名\n");
while(q)
{
while(p)
if(i==p->grade.Allrank)
{
printf(M,H);
p=p->next;
}
else
p=p->next;
p=head;
i++;
if(!q->next)break;
q=q->next;
}
}
void show(struct student *head)
{
stu p;
printf("姓名 學號 英語 高數 C語言 體育 總成績 排名");
printf("\n");
p=head;
while(p)
{
printf(M,H);
p=p->next;
}
}
void main()
{
int n;
struct student *head,*p;
stu L;
printf("綜合素質測評系統\n");
printf("1.數據錄入\n");
printf("2.數據修改\n");
printf("3.插入操作\n");
printf("4.刪除操作\n");
printf("5.查找操作\n");
printf("6.排序操作\n");
printf("7.數據顯示\n");
printf("0.退出系統\n");
printf("請輸入操作:");
scanf("%d",&n);
while(n!=0)
{
switch(n)
{
case 0:
break;
case 1:
L=Create(head);
Rank(L,L,1);
printf("請輸入操作:");
break;
case 2:
Change(L);
Rank(L,L,1);
printf("請輸入操作:");
break;
case 3:
L=Insert(L);
Rank(L,L,1);
printf("請輸入操作:");
break;
case 4:
L=Delet(L);
Rank(L,L,1);
printf("請輸入操作:");
break;
case 5:
Look(L);
printf("請輸入操作:");
break;
case 6:
Rank(L,L,1);
Rankshow(L,1);
printf("請輸入操作:");
break;
case 7:
show(L);
printf("請輸入操作:");
break;
}
scanf("%d",&n);
}
}