You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
2.9 KiB

#include<stdio.h>
#define maxsize 100
struct student{
int num;
char name;
int math,chin,eng;
int average;
};
int count = 0;
void new_students(struct student students[])
{
int i, n;
if (count == maxsize){
printf("the number isfull");
return;
}
printf("the number is n");
scanf("%d", &n);
for (i = 0; i < n; i++){
printf("the student's num");
scanf("%d", &students[i].num);
printf("the student's name");
scanf("%s",&students[i].name);
printf("the student's math");
scanf("%d", &students[i].math);
printf("the student's chin");
scanf("%d", &students[i].chin);
printf("the student's eng");
scanf("%d", &students[i].eng);
count++;
}
}
void out_input(struct student students[])
{
int i;
if (count == 0){
printf("count of students is 0");
return;
}
printf("num\t name\t math\t chin\t eng\t average\n");
for (i = 0; i < count; i++){
printf("%d\t", students[i].num);
printf("%s\t", students[i].name);
printf("%d\t", students[i].math);
printf("%d\t", students[i].chin);
printf("%d\t", students[i].eng);
printf("%d\t\n", students[i].average);
}
getchar();
}
void average(struct student students[])
{
int i;
for (i = 0; i < count; i++)
{
students[i].average = (students[i].eng + students[i].math + students[i].chin) / 3;
}
}
void sort(struct student s[])
{
struct student temp;
int i, j;
for (i = 0; i < count; i++)
{
for (j = 0; j < i - j - 1; j++)
if (s[j].average>s[j + 1].average){
temp = s[j];
s[j] = s[j + 1];
s[j + 1] = temp;
}
}
}
void modify(struct student *p)
{
int num, course, score, i;
printf("input the new student");
scanf("%d", &num);
printf("chioce the course :1math 2.chin,3.eng");
scanf("%d", &course);
printf("input the new score");
scanf("%d", &score);
for (i = 0; i < count; i++, p++)
{
if (p->num == num)
break;
if (i<count)
switch (course)
{
case 1:p->math = score;
break;
case 2:p->chin = score;
break;
case 3:p->eng = score;
break;
}
}
}
void search_student(struct student students[], int num)
{
int i, flag = 0;
if (count == 0){
printf("zhe xue sheng shu mu is0");
return;
}
for (i = 0; i < count;i++)
if (students[i].num == num)
{
flag = 1;
break;
}
if (flag)
{
printf("num:%d", students[i].num);
printf("name:%s", students[i].name);
printf("math:%d", students[i].math);
printf("chin:%d", students[i].chin);
printf("eng:%d", students[i].eng);
printf("average:%d", students[i].average);
}
else
printf("no found");
}
void new_students(struct student students[]);
void out_input(struct student students[]);
void search_student(struct student students[], int num);
void modify(struct student *p);
void average(struct student students[]);
void sort(struct student s[]);
int main()
{
struct student students[maxsize];
new_students(students);
average(students);
out_input(students);
sort(students);
out_input(students);
modify(students);
out_input(students);
return 0;
}