c语言编写学生管理系统

昨天我一高中同学让我写一个学生管理系统,说怎么简单怎么来,其实管理系统是每个学编程的人必须会的代码,下面分享给大家。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#define number 50
#define LEN sizeof(struct address)
struct address
{
char name[20];
char num[20];
char cj[20];
struct address *next;
};

struct address *head;
static int n=0;

void  scan(struct address *g)
{
printf("请输入:姓名:");
scanf("%s",g->name);
printf("请输入:学号:");
scanf("%s",g->num);
printf("请输入:成绩:");
scanf("%s",g->cj);
}

int menu_select()
{
int choice;
printf("*********************************************************************\n");
printf("   学生管理系统         \n");
printf("*********************************************************************\n");
printf("   1:学生信息录入              \n");
printf("   2:分段人数              \n");
printf("   3:信息查找          \n");
printf("   4:按成绩排序            \n");
printf("   5:系统退出              \n");
printf("请输入您的选择:");
scanf("%d",&choice);
return choice;
}
void   look(struct address *head)
{
struct address *p;
p=head;
printf("*********************************************************************\n");
printf("姓名\t学号\t成绩\n");
printf("*********************************************************************\n");
if(head!=NULL)
{
while(p!=NULL)
{
printf("%s\t%s\t%s\n",p->name,p->num,p->cj);
p=p->next;
}
}
}


struct address* add()
{
int temp;
struct address *p1,*p2;
p2=p1=(struct address *)malloc(LEN);
head=NULL;
while(1)
{
n=n+1;
printf("第%d个人.\n",n);
if(n==1)  head=p1;
else      p2->next=p1;
scan(p1);
p2=p1;
p1=(struct address *)malloc(LEN);
printf("如果你想退出,请输入1;如果你想继续,请输入2:");
scanf("%d",&temp);
if(temp==1)   break;
}
p2->next=NULL;
look(head);
return head;
}

void  find(struct address *head)
{
struct address *p;
char  good[20];
p=head;
printf("请输入所查找的人的姓名:");
scanf("%s",good);
    if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->name)==0)
{
printf("*********************************************************************\n");
printf("姓名\t学号\t成绩\n");
printf("%s\t%s\t%s\n",p->name,p->num,p->cj);
printf("*********************************************************************\n");
}
p=p->next;
}

}
}

struct  address  *sort()
{
struct  address  *a,*p,*p1,*p2,*p3,*p4;
int f=0,h;
p2=p1=(struct address *)malloc(LEN);
a=(struct address *)malloc(LEN);
p4=p=head;
while(f<n)
{
f=f+1;
if(f==1)  head=p1;
else      p2->next=p1;
p=p4;
h=0;
while(p!=NULL)
{
h=h+1;
p3=p;
p=p->next;
if(h==1)
{*a=*p3;}
if(strcmp(a->cj,p3->cj)>0)
{
*a=*p3;
}
}
p=p4;
while(p!=NULL)
{
p3=p;
p=p->next;
if(strcmp(a->cj,p4->cj)==0)
{
p4=p;
break;
}
if(strcmp(a->cj,p->cj)==0)
{
p3->next=p->next;
break;
}
}
*p1=*a;
p2=p1;
p1=(struct address *)malloc(LEN);
}
p2->next=NULL;
    look(head);
return head;
}

void set_grade(struct address *head)
{
struct address *p;
p=head;
int i,a=0,b=0,c=0,d=0,e=0;
if(head!=NULL)
{
while(p!=NULL)
{
    if(strcmp(p->cj,"90")>=0)
    {
    a++;
    }
    else if(strcmp(p->cj,"80")>=0)
    {
    b++;
    }
    else if(strcmp(p->cj,"70")>=0)
    {
    c++;
    }
    else if(strcmp(p->cj,"60")>=0)
    {
    d++;
    }
    else
    {
    e++;
    }
      p=p->next;
}
   
    
}
printf("a:%d\nb:%d\nc:%d\nd:%d\ne:%d\n",a,b,c,d,e); 


int main()
{
while(1)
{
switch(menu_select())
{
case 1:add();break;//录入 
case 2:set_grade(head);break;//分段 
case 3:find(head);break;//查找 
case 4:sort();break;//排序 
case 5:exit(0);
}
}
return 0;
}

因为他要求的功能比较少,所以只做了这些,如果需要更多功能的,我之前写的管理系统功能更全面可以用做参考

点击打开链接









猜你喜欢

转载自blog.csdn.net/yang03_26/article/details/80983231