学生管理系统

来源:互联网 发布:深圳网站建设方维网络 编辑:程序博客网 时间:2024/06/15 15:59

题目:设计一个学生管理系统,要求:

1)可以输入学生的姓名,学号,语文和数学成绩

2)通过学生的姓名查找该生的其他信息

3)各科成绩排序

4)修改功能

5)显示全部

6)退出功能


#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int i = 0;
struct student 
{
int ID;
char name[10];
int math;
int china;
};
typedef struct student STU;


void show()
{
system("clear");
printf("**************************************\n\n");
printf("*****WELCOME TO TEACER SYSTERM********\n\n");
printf("**************************************\n\n");
sleep(2);
system("clear");
}


void PrintInfo()
{
printf("***************************************\n\n");
printf("***1.InsertInfo           2.SearchInfo**\n");
printf("***3.SortInfo             4.ChangeInfo**\n");
printf("***5.ShowInfo             6.Quit**********\n");
printf("***************************************\n\n");
printf("please input your choice:\n");
}


int InsertInfo(STU *s[])
{
// int i = 0;


printf("Please input Information:\n");
while(1)
{
s[i] = (STU *)malloc(sizeof(STU));
if(NULL == s[i])
{
return;
}
scanf("%s", s[i]->name);
if(strcmp(s[i]->name, "end") == 0)break;
scanf("%d%d%d",&s[i]->ID, &s[i]->math, &s[i]->china);
i++;
}
return i;
}


void SearchInfo(STU *s[])
{
int i = 0;
char target[10] = {0};


printf("Please input name you will find :\n");
scanf("%s",target);


while(s[i] != NULL)
{
if(strcmp(s[i]->name, target) == 0)
{
printf("********************\n");
printf("name :%s\n",s[i]->name);
printf("ID :%d\n",s[i]->ID);
printf("math :%d\n",s[i]->math);
printf("china :%d\n",s[i]->china);
printf("*********************\n");
return;
}
i++;
}


printf("*********************\n");
printf("Not Found!!\n");
printf("*********************\n");
}


void SortInfo(STU *s[],int count)
{
int i,j;
int k;
STU *tmp;
STU *tt;


printf("****Input Your Choice****\n\n");
printf("****1.Math        2.China***\n");
scanf("%d",&k);


if(1 == k)
{
for(j = 0; j < count - 1; j++)
for(i = 0; i < count - 1 - j; i++)
if(s[i]->math > s[i + 1]->math)
{
tmp = s[i];
s[i] = s[i + 1];
s[i + 1] = tmp;
}
for(i = 0; i < count; i++)
printf("The math score is:ID%d %d\n",s[i]->ID,s[i]->math);
return;
}

if(2 == k)
{
for(j = 0; j < count - 1; j++)
for(i = 0; i < count - 1 - j; i++)
if(s[i]->china > s[i + 1]->china)
{
tmp = s[i];
s[i] = s[i + 1];
s[i + 1] = tmp;
}


for(i = 0; i < count; i++)
printf("The chinese score is:ID%d %d\n",s[i]->ID,s[i]->china);
return;


}
}


void ChangeInfo(STU **s)
{
char target[10] = {0};
int i = 0;


printf("Please Input The Name You Want Change:\n");
scanf("%s",target);


printf("Input New Infor :\n");


while(s[i] != NULL)
{
if(strcmp(s[i]->name, target) == 0)
{
scanf("%s",s[i]->name);
scanf("%d",&s[i]->ID);
scanf("%d",&s[i]->math);
scanf("%d",&s[i]->china);
printf("Change Success!\n");
return;
}
i++;
}


}


void ShowInfo(STU **s,int count)
{
int i = 0;
for(;i < count; i++)
{
printf("%s\n",s[i]->name);
printf("%d,%d,%d\n",s[i]->ID,s[i]->math,s[i]->china);
}
}


int main()
{
STU *stu[100] = {0};
char choice[10] = {0};
int count = 0;


show();


while (1)
{
PrintInfo();
scanf("%s", choice);


switch (atoi(&choice[0]))
{
case 1:
count = InsertInfo(stu);
break;
case 2:
SearchInfo(stu);
break;
case 3:
SortInfo(stu,count);
break;
case 4:
ChangeInfo(stu);
break;
case 5:
ShowInfo(stu,count);
break;
case 6:
exit(1);
break;
default:
printf("Unknown Input!\n");
break;
}
}


return 0;
}




原创粉丝点击