#include <stdio.h>
#include <stdlib.h>
int num=0;
struct student
{
char name[10];
int id;
int math;
int china;
};
typedef struct student STU;
void show()
{
system("clear");
printf("************************************\n\n");
printf("*****WELCOME TO TEACHER SYSTEM******\n\n");
printf("************************************\n\n");
sleep(2);
system("clear");
}
void PrintInfo()
{
printf("*************************************\n\n");
printf("**1.InserInfo 2.SearchInfo**\n");
printf("**3.SortInfo 4.ChangeInfo**\n");
printf("**5.ShowInfo 6.quit **\n");
printf("*************************************\n\n");
printf("Please input your choice :\n");
}
void 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++;
num++;
}
}
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 Fount!!\n");
printf("**************\n");
}
void SortInfo(STU *s[])
{
int i,j;
STU *tmp;
printf("*****************************\n");
printf("*****1.math 2.china*\n");
printf("*****************************\n");
int a;
scanf("%d",&a);
if(a==1)
{
for(i=0;i<num;i++)
{
for(j=0;j<num-i-1;j++)
{
if((s[j]->math)<(s[j+1]->math))
{
tmp=s[j];
s[j]=s[j+1];
s[j+1]=tmp;
}
}
}
}
if(a==2)
{
for(i=0;i<num;i++)
{
for(j=0;j<num-i-1;j++)
{
if((s[j]->china)<(s[j]->china))
{
tmp=s[j];
s[j]=s[j+1];
s[j+1]=tmp;
}
}
}
}
}
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[])
{
printf("Show all information:\n");
int i=0;
for(i=0;i<num;i++)
{
printf("%10s%4d%4d%4d\n",s[i]->name,s[i]->id,s[i]->math,s[i]->china);
}
}
int main()
{
STU *stu[100] = {0};
char choice[10] = {0};
show();
while (1)
{
PrintInfo();
scanf("%s", choice);
switch (atoi(&choice[0]))
{
case 1:
InsertInfo(stu);
break;
case 2:
SearchInfo(stu);
break;
case 3:
SortInfo(stu);
break;
case 4:
ChangeInfo(stu);
break;
case 5:
ShowInfo(stu);
break;
case 6:
exit(1);
break;
default:
printf("Unkown Input!\n");
break;
}
}
return 0;
}
#include <stdlib.h>
int num=0;
struct student
{
char name[10];
int id;
int math;
int china;
};
typedef struct student STU;
void show()
{
system("clear");
printf("************************************\n\n");
printf("*****WELCOME TO TEACHER SYSTEM******\n\n");
printf("************************************\n\n");
sleep(2);
system("clear");
}
void PrintInfo()
{
printf("*************************************\n\n");
printf("**1.InserInfo 2.SearchInfo**\n");
printf("**3.SortInfo 4.ChangeInfo**\n");
printf("**5.ShowInfo 6.quit **\n");
printf("*************************************\n\n");
printf("Please input your choice :\n");
}
void 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++;
num++;
}
}
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 Fount!!\n");
printf("**************\n");
}
void SortInfo(STU *s[])
{
int i,j;
STU *tmp;
printf("*****************************\n");
printf("*****1.math 2.china*\n");
printf("*****************************\n");
int a;
scanf("%d",&a);
if(a==1)
{
for(i=0;i<num;i++)
{
for(j=0;j<num-i-1;j++)
{
if((s[j]->math)<(s[j+1]->math))
{
tmp=s[j];
s[j]=s[j+1];
s[j+1]=tmp;
}
}
}
}
if(a==2)
{
for(i=0;i<num;i++)
{
for(j=0;j<num-i-1;j++)
{
if((s[j]->china)<(s[j]->china))
{
tmp=s[j];
s[j]=s[j+1];
s[j+1]=tmp;
}
}
}
}
}
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[])
{
printf("Show all information:\n");
int i=0;
for(i=0;i<num;i++)
{
printf("%10s%4d%4d%4d\n",s[i]->name,s[i]->id,s[i]->math,s[i]->china);
}
}
int main()
{
STU *stu[100] = {0};
char choice[10] = {0};
show();
while (1)
{
PrintInfo();
scanf("%s", choice);
switch (atoi(&choice[0]))
{
case 1:
InsertInfo(stu);
break;
case 2:
SearchInfo(stu);
break;
case 3:
SortInfo(stu);
break;
case 4:
ChangeInfo(stu);
break;
case 5:
ShowInfo(stu);
break;
case 6:
exit(1);
break;
default:
printf("Unkown Input!\n");
break;
}
}
return 0;
}