qq_33537381
2015-12-29 03:39
采纳率: 100%
浏览 2.7k

求帮助改改我我运行的错误 5位学生4门课学生成绩管理系统

#include
#include
#define maxsize 5
struct student {
int num;
char name[30];
int english,computer,math,chinese;
int rank;

};
static float aen,aco,ama,ach;static int maxch,maxma,maxen,maxco,minch,minma,minen,minco,sum[5];
void menu (struct student students []);
void input_student (struct student students []);
void change_student (struct student *p);
void search_student (struct student *p);
void cal (struct student s[]);
void max (struct student s[]);
void min (struct student s[]);
void sort (struct student students[]);
void output_student (struct student students []);

void input_student (struct student students [])
{
int i;char ch;

for (i=0;i<5;i++){
printf("********************************\n");
printf("请输入:\n学号:");
scanf("%d",&students [i].num);
printf("姓名:");
scanf("%s",students [i].name);
printf("英语:");
scanf("%d",&students [i].english);
printf("计算机:");
scanf("%d",&students [i].computer);
printf("语文:");
scanf("%d",&students [i].math);
printf("数学:");
scanf("%d",&students [i].chinese);
printf("是否继续?(Y/N)________________:\n");
scanf("%c",&ch);

if (ch==('N'||'n')) break;}

return;

}

void output_student (struct student students [ ])
{
int i,a,b,j;int sum[5];

printf ("---------------------------------------------------------------------------\n");
printf ("num\t name\t english\t computer\t math\t chinese\t rank\n");
for (i=0;i<5;i++){

printf("%d\t",students [i].num);
printf(" %s\t",students [i].name);
printf(" %d\t",students [i].english);
printf(" %d\t",students [i].computer);
printf(" %d\t",students [i].math);
printf(" %d\t",students [i].chinese);
printf(" %d\t\n",students [i].rank);}

printf("平均分 %.2f\t%.2f\t%.2f\t%.2f\n",aen,aco,ama,ach);
printf("最高分 %d\t%d\t%d\t%d\n",maxen,maxco,maxma,maxch); /*分数的调用*/
printf("最低分 %d\t%d\t%d\t%d\n",minen,minco,minma,minch);
printf ("---------------------------------------------------------------------------");
return ;

}

void search_student (struct student students [ ] )
{

int i,cour,way,j;

char a[20];
printf("choice the way:1.姓名2.课程3.总分名次");
scanf("%d",&way);

switch(way){
case 1:
printf("姓名:");
scanf("%s",&a);
for (i=0;i<5;i++){
if (strcmp(students[i].name,a)==0) { /*逐个比较相等为0 ,不等返回不相等的差值 !strcmp(students[i].name, a)*/
printf(" num:%d",students [i].num);
printf(" english:%d",students [i].english);
printf(" computer:%d",students [i].computer);
printf(" math:%d",students [i].math);
printf("chinese:%d\n",students [i].chinese);}
}

case 2:printf("课程:");
printf("a-英语,b-计算机,c-数学,d-语文:");
scanf("%c",&cour);

if(cour=='a') {
printf(" 英语:");
for (i=0;i<5;i++) printf(" %d",students [i].english);
if(i==4) {
printf("平均分: %f",&aen);
printf(" 最高分:%d",&maxen);
printf("最低分: %d",&minen);}
}

if(cour=='b') {
printf(" 计算机:");
for (i=0;i<5;i++) printf(" %d",students [i].computer);
if(i==4) {
printf("平均分: %f",&aco);
printf(" 最高分:%d",&maxco);
printf("最低分: %d",&minco);}
}

if(cour=='c') {
printf(" 数学:");
for (i=0;i<5;i++) printf(" %d",students [i].math);
if(i==4) {
printf("平均分: %f",&ama);
printf(" 最高分:%d",&maxma);
printf("最低分: %d",&minma);}
}

if(cour=='d') {
printf("语文:");
for (i=0;i<5;i++) printf(" %d",students [i].chinese);
if(i==4) {
printf("平均分: %f",&ach);
printf(" 最高分:%d",&maxch);
printf("最低分: %d",&minch);}
}

case 3:for (j=1;j<6;j++)
for (i=0;i<5;i++)
if(students [i].rank==j) printf(" name:%s",students [i].name);

return;
}

}

void sort (struct student students[]){
int i,j,x;x=1;

for(i=0;i<5;i++)
for(j=1;i<6;i++)

if(sum[i]<sum[i+1])
{x=x+1;
students[i].rank=x;
}
return;
}

void max (struct student students []){
int i;

maxch=students [0].chinese;
maxma=students [0].math;
maxen=students [0].english;
maxco=students [0].computer;

for (i=0;i if (students [i].chinese>students [i+1].chinese){

maxch=students [i+1].chinese;}
if (students [i].math>students [i+1].math){

maxma=students [i+1].math;}
if (students [i].english>students [i+1].english){

maxen=students [i+1].english;}
if (students [i].computer>students [i+1].computer){

maxco=students [i+1].computer;}
}
return;
}

void min (struct student students []){
int i;

minch=students [0].chinese;
minma=students [0].math;
minen=students [0].english;
minco=students [0].computer;
/*各科最低*/
for (i=0;i<5;i++) {

if(students [i].chinese<students [i+1].chinese)
maxch=students [i+1].chinese;
if (students [i].math<students [i+1].math)

maxma=students [i+1].math;
if (students [i].english<students [i+1].english)

maxen=students [i+1].english;
if (students [i].computer<students [i+1].computer)

maxco=students [i+1].computer;}
return;
}

void change_student (struct student *p)
{
int num,course,score,i;
printf("输入学号:");
scanf("%d",&num);
printf("choice the course:1.english2.computer3.math4.chinese:");
scanf("%d",&course);
printf("输入新成绩:");
scanf("%d",&score);

for (i=0;i if(p->num==num)
break;
if(i switch(course)
{
case 1:p->english=score;break;
case 2:p->computer=score;break;
case 3:p->math=score;break;
case 4:p->chinese=score;break;
}
return;

}

int main (void){
struct student students[maxsize];
int c;

while (1){
printf("********************************\n");
printf(" 学生成绩管理系统\n");
printf("********************************\n");
printf(" (1)输入学生成绩\n");
printf(" (2)查询学生成绩\n");
printf(" (3)修改学生成绩\n");
printf(" (4)输出学生成绩\n");
printf(" (5) 退出系统\n");
printf("请选择(1、2、3、4、5)______\n");
scanf("%d",&c);
if (c>5||c<0)
printf("error\n");
else
switch(c)
{
case 1:input_student (students);break;
case 2:search_student (students);break;
case 3:change_student (students);break;
case 4:output_student (students) ;
break;
case 5:break;
}
if (c==5) break;
}

return 0;
}

出现三个问题,第一,input 函数里yes or no 的选择不出现,第二,总分排须有问题,第三,我自定义函数里计算的值无法输出,不知道该怎么调用定义的cal,max,min.

求大神门帮助阿,用的是dev c++写的。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

9条回答 默认 最新

  • John_ToDebug 2015-12-29 05:47
    已采纳

    看看我的代码:
    #if 1
    #include
    #include
    #include
    #define maxsize 5

    struct student {
    int num;
    char name[30];
    int english, computer, math, chinese;
    int rank;
    };
    static float aen, aco, ama, ach; static int maxch, maxma, maxen, maxco, minch, minma, minen, minco, sum[5];
    void menu(struct student students[]);
    //void input_student(struct student students[]);
    int input_student(struct student students[]);
    void change_student(struct student p);
    void search_student(struct student *p);
    void cal(struct student s[]);
    void max_(struct student s[]);
    void min_(struct student s[]);
    void sort(struct student students[]);
    void output_student(struct student students[]);
    void mnue();
    int input_student(struct student students[])
    {
    int i; char ch;
    for (i = 0; i<5; i++){
    printf("
    *******************************\n");
    printf("请输入:\n学号:");
    scanf("%d", &students[i].num);
    printf("姓名:");
    scanf("%s", students[i].name);
    printf("英语:");
    scanf("%d", &students[i].english);
    printf("计算机:");
    scanf("%d", &students[i].computer);
    printf("语文:");
    scanf("%d", &students[i].math);
    printf("数学:");
    scanf("%d", &students[i].chinese);
    printf("rank:");
    scanf("%d", &students[i].rank);
    printf("是否继续?(Y/N)________________:\n");
    fflush(stdin);
    scanf("%c", &ch);
    //if (ch == ('N' || 'n'))
    if (ch == 'N' || ch == 'n')
    break;
    //if (ch == ('Y' || 'y'))
    if (ch == 'Y' || ch == 'y')
    break;
    }
    return i+1;
    }
    void output_student(struct student students[], int n)
    {
    int i, a, b, j; int sum[5];
    printf("---------------------------------------------------------------------------\n");
    printf("num\tname\tenglish\tcomputer\tmath\tchinese\trank\n");
    //此处必须得改变接口,因为数组名退化为指针,所以以下语句不能用。
    //int aq = sizeof(students) / sizeof(students[0]);
    for (i = 0; i printf(" %d\t", students[i].num);
    printf(" %s\t", students[i].name);
    printf(" %d\t", students[i].english);
    printf(" %d\t\t", students[i].computer);
    printf(" %d\t", students[i].math);
    printf(" %d\t", students[i].chinese);
    printf(" %d\t\n", students[i].rank);
    }
    printf("平均分 %.2f\t%.2f\t%.2f\t%.2f\n", aen, aco, ama, ach);
    printf("最高分 %d\t%d\t%d\t%d\n", maxen, maxco, maxma, maxch); /*分数的调用*/
    printf("最低分 %d\t%d\t%d\t%d\n", minen, minco, minma, minch);
    printf("---------------------------------------------------------------------------");
    //此处不要加return, 加了return函数立即返回,并且你有没有要用返回值。并且记得清空缓存。
    fflush(stdin);
    getchar();
    //return;
    }
    void search_student(struct student students[])
    {
    int i, cour, way, j;
    char a[20];
    printf("choice the way:1.姓名2.课程3.总分名次");
    scanf("%d", &way);
    switch (way){
    case 1:
    printf("姓名:");
    scanf("%s", &a);
    for (i = 0; i if (strcmp(students[i].name, a) == 0) { /*逐个比较相等为0 ,不等返回不相等的差值 !strcmp(students[i].name, a)*/
    printf(" num:%d", students[i].num);
    printf(" english:%d", students[i].english);
    printf(" computer:%d", students[i].computer);
    printf(" math:%d", students[i].math);
    printf("chinese:%d\n", students[i].chinese);
    }
    }
    case 2:printf("课程:");
    printf("a-英语,b-计算机,c-数学,d-语文:");
    scanf("%c", &cour);
    if (cour == 'a') {
    printf(" 英语:");
    for (i = 0; i if (i == 4) {
    //此处的输出有问题,怎么能给整型变量加&符呢?这样的话你输出的是地址。
    //printf("平均分: %f", &aen);
    printf(" 最高分:%d", &maxen);
    printf("最低分: %d", &minen);
    }
    }
    if (cour == 'b') {
    printf(" 计算机:");
    for (i = 0; i if (i == 4) {
    printf("平均分: %f", &aco);
    printf(" 最高分:%d", &maxco);
    printf("最低分: %d", &minco);
    }
    }
    if (cour == 'c') {
    printf(" 数学:");
    for (i = 0; i if (i == 4) {
    printf("平均分: %f", &ama);
    printf(" 最高分:%d", &maxma);
    printf("最低分: %d", &minma);
    }
    }
    if (cour == 'd') {
    printf("语文:");
    for (i = 0; i if (i == 4) {
    printf("平均分: %f", &ach);
    printf(" 最高分:%d", &maxch);
    printf("最低分: %d", &minch);
    }
    }
    case 3:for (j = 1; j for (i = 0; i if (students[i].rank == j) printf(" name:%s", students[i].name);
    return;
    }
    }
    void sort(struct student students[]){
    int i, j, x; x = 1;
    for (i = 0; i for (j = 1; i if (sum[i] {
    x = x + 1;
    students[i].rank = x;
    }
    return;
    }
    void max_(struct student students[])
    {
    int i;
    maxch = students[0].chinese;
    maxma = students[0].math;
    maxen = students[0].english;
    maxco = students[0].computer;
    for (i = 0; i if (students[i].chinese>students[i + 1].chinese)
    {
    maxch = students[i + 1].chinese;
    }
    if (students[i].math>students[i + 1].math)
    {
    maxma = students[i + 1].math;
    }
    if (students[i].english>students[i + 1].english)
    {
    maxen = students[i + 1].english;
    }
    if (students[i].computer>students[i + 1].computer)
    {
    maxco = students[i + 1].computer;
    }
    }

    void min_(struct student students[]){
    int i;
    minch = students[0].chinese;
    minma = students[0].math;
    minen = students[0].english;
    minco = students[0].computer;
    /*各科最低*/
    for (i = 0; i if (students[i].chinese maxch = students[i + 1].chinese;
    if (students[i].math maxma = students[i + 1].math;
    if (students[i].english maxen = students[i + 1].english;
    if (students[i].computer maxco = students[i + 1].computer;
    }
    return;
    }
    void change_student(struct student *p)
    {
    int num, course, score, i;
    printf("输入学号:");
    scanf("%d", &num);
    printf("choice the course:1.english2.computer3.math4.chinese:");
    scanf("%d", &course);
    printf("输入新成绩:");
    scanf("%d", &score);
    for (i = 0; i if (p->num == num)
    break;
    switch (course)
    {
    case 1:p->english = score; break;
    case 2:p->computer = score; break;
    case 3:p->math = score; break;
    case 4:p->chinese = score; break;
    }
    }

    void mnue()
    {
    printf("********************************\n");
    printf(" 学生成绩管理系统\n");
    printf("********************************\n");
    printf(" (1)输入学生成绩\n");
    printf(" (2)查询学生成绩\n");
    printf(" (3)修改学生成绩\n");
    printf(" (4)输出学生成绩\n");
    printf(" (5) 退出系统\n");
    printf("请选择(1、2、3、4、5)______\n");
    }

    int main(void){
    struct student students[maxsize];
    int c, a;
    while (1){
    system("cls");
    mnue();
    scanf("%d", &c);
    if (c>5 || c<0)
    printf("error\n");
    else
    switch (c)
    {
    case 1:a = input_student(students); break;
    case 2:search_student(students); break;
    case 3:change_student(students); break;
    case 4:output_student(students, a); break;
    case 5:break;
    }
    }
    return 0;
    }
    #endif
    代码逻辑错误很多,但是我改了一部分。

    已采纳该答案
    打赏 评论
  • devmiao 2015-12-29 03:59
    打赏 评论
  • ysuwood 2015-12-29 04:55

    粘贴错误很多,修改一下,把代码放到代码片里。
    看到一处错误,修改如下:

     void input_student (struct student students [])
    {
        int i;char ch;
        for (i=0;i<5;i++){
            printf("********************************\n");
            printf("请输入:\n学号:");
            scanf("%d",&students [i].num);
            printf("姓名:");
            scanf("%s",students [i].name);
            printf("英语:");
            scanf("%d",&students [i].english);
            printf("计算机:");
            scanf("%d",&students [i].computer);
            printf("语文:");
            scanf("%d",&students [i].math);
            printf("数学:");
            scanf("%d",&students [i].chinese);
            printf("是否继续?(Y/N)________________:\n");
            scanf("%c",&ch);
            if (ch=='N' || ch=='n') break;}//修改
        return;
    }
    
    打赏 评论
  • John_ToDebug 2015-12-29 05:49

    ![图片说明](https://img-ask.csdn.net/upload/201512/29/1451368198_988692.png)图片说明

    打赏 评论
  • John_ToDebug 2015-12-29 05:49

    图片说明

    打赏 评论
  • John_ToDebug 2015-12-29 05:50

    图片说明

    打赏 评论
  • John_ToDebug 2015-12-29 06:18

    我把平均分去了,看看截图...
    ![图片说明](https://img-ask.csdn.net/upload/201512/29/1451369915_235008.png)图片说明

    打赏 评论
  • John_ToDebug 2015-12-29 06:19

    图片说明
    #if 1
    #include
    #include
    #include
    #define maxsize 5

    struct student {
    int num;
    char name[30];
    int english, computer, math, chinese;
    int rank;
    };
    static float aen, aco, ama, ach; static int maxch, maxma, maxen, maxco, minch, minma, minen, minco, sum[5];
    void menu(struct student students[]);
    //void input_student(struct student students[]);
    int input_student(struct student students[]);
    void change_student(struct student p);
    void search_student(struct student *p);
    void cal(struct student s[]);
    void max_(struct student s[], int n);
    void min_(struct student s[], int n);
    void sort(struct student students[]);
    void output_student(struct student students[]);
    void mnue();
    int input_student(struct student students[])
    {
    int i; char ch;
    for (i = 0; i<5; i++){
    printf("
    *******************************\n");
    printf("请输入:\n学号:");
    scanf("%d", &students[i].num);
    printf("姓名:");
    scanf("%s", students[i].name);
    printf("英语:");
    scanf("%d", &students[i].english);
    printf("计算机:");
    scanf("%d", &students[i].computer);
    printf("语文:");
    scanf("%d", &students[i].math);
    printf("数学:");
    scanf("%d", &students[i].chinese);
    printf("rank:");
    scanf("%d", &students[i].rank);
    printf("是否继续?(Y/N)________________:\n");
    fflush(stdin);
    scanf("%c", &ch);
    //if (ch == ('N' || 'n'))
    if (ch == 'N' || ch == 'n')
    break;
    //if (ch == ('Y' || 'y'))
    if (ch == 'Y' || ch == 'y')
    break;
    }
    return i+1;
    }
    void output_student(struct student students[], int n)
    {
    int i, a, b, j; int sum[5];
    printf("---------------------------------------------------------------------------\n");
    printf("num\tname\tenglish\tcomputer\tmath\tchinese\trank\n");
    //此处必须得改变接口,因为数组名退化为指针,所以以下语句不能用。
    //int aq = sizeof(students) / sizeof(students[0]);
    for (i = 0; i<n; i++){
    printf(" %d\t", students[i].num);
    printf(" %s\t", students[i].name);
    printf(" %d\t", students[i].english);
    printf(" %d\t\t", students[i].computer);
    printf(" %d\t", students[i].math);
    printf(" %d\t", students[i].chinese);
    printf(" %d\t\n", students[i].rank);
    }

    max_(students, n);
    min_(students, n);
    //此处以下三条语句中的变量输出一定是0, 因为此时你并没有给他们赋值。
    /*printf("平均分 %.2f\t%.2f\t%.2f\t%.2f\n", aen, aco, ama, ach);
    printf("最高分 %d\t%d\t%d\t%d\n", maxen, maxco, maxma, maxch); 
    printf("最低分 %d\t%d\t%d\t%d\n", minen, minco, minma, minch);*/
    printf("---------------------------------------------------------------------------");
    //此处不要加return, 加了return函数立即返回,并且你有没有要用返回值。并且记得清空缓存。
    fflush(stdin);
    getchar();
    //return;
    

    }
    void search_student(struct student students[])
    {
    int i, cour, way, j;
    char a[20];
    printf("choice the way:1.姓名2.课程3.总分名次");
    scanf("%d", &way);
    switch (way){
    case 1:
    printf("姓名:");
    scanf("%s", a);
    for (i = 0; i if (strcmp(students[i].name, a) == 0) { /*逐个比较相等为0 ,不等返回不相等的差值 !strcmp(students[i].name, a)*/
    printf(" num:%d", students[i].num);
    printf(" english:%d", students[i].english);
    printf(" computer:%d", students[i].computer);
    printf(" math:%d", students[i].math);
    printf("chinese:%d\n", students[i].chinese);
    }
    }
    case 2:printf("课程:");
    printf("a-英语,b-计算机,c-数学,d-语文:");
    scanf("%c", &cour);
    if (cour == 'a') {
    printf(" 英语:");
    for (i = 0; i if (i == 4) {
    //此处的输出有问题,怎么能给整型变量加&符呢?这样的话你输出的是地址。
    //printf("平均分: %f", &aen);
    //printf(" 最高分:%d", &maxen);
    //printf("最低分: %d", &minen);
    printf("平均分: %f", aen);
    printf(" 最高分:%d", maxen);
    printf("最低分: %d", minen);
    }
    }
    if (cour == 'b') {
    printf(" 计算机:");
    for (i = 0; i if (i == 4) {
    /*printf("平均分: %f", &aco);
    printf(" 最高分:%d", &maxco);
    printf("最低分: %d", &minco);*/
    printf("平均分: %f", aco);
    printf(" 最高分:%d", maxco);
    printf("最低分: %d", minco);
    }
    }
    if (cour == 'c') {
    printf(" 数学:");
    for (i = 0; i if (i == 4) {
    /*printf("平均分: %f", &ama);
    printf(" 最高分:%d", &maxma);
    printf("最低分: %d", &minma);*/
    printf("平均分: %f", ama);
    printf(" 最高分:%d", maxma);
    printf("最低分: %d", minma);
    }
    }
    if (cour == 'd') {
    printf("语文:");
    for (i = 0; i if (i == 4) {
    /*printf("平均分: %f", &ach);
    printf(" 最高分:%d", &maxch);
    printf("最低分: %d", &minch);*/
    printf("平均分: %f", ach);
    printf(" 最高分:%d", maxch);
    printf("最低分: %d", minch);
    }
    }
    case 3:for (j = 1; j for (i = 0; i if (students[i].rank == j) printf(" name:%s", students[i].name);
    return;
    }
    }
    void sort(struct student students[]){
    int i, j, x; x = 1;
    for (i = 0; i for (j = 1; i if (sum[i] {
    x = x + 1;
    students[i].rank = x;
    }
    return;
    }
    void max_(struct student students[], int n)
    {
    int i;
    maxch = students[0].chinese;
    maxma = students[0].math;
    maxen = students[0].english;
    maxco = students[0].computer;
    for (i = 0; i {
    /* if (students[i].chinese > students[i + 1].chinese)
    {
    maxch = students[i + 1].chinese;
    }
    if (students[i].math > students[i + 1].math)
    {
    maxma = students[i + 1].math;
    }
    if (students[i].english > students[i + 1].english)
    {
    maxen = students[i + 1].english;
    }
    if (students[i].computer > students[i + 1].computer)
    {
    maxco = students[i + 1].computer;
    }*/

        if (maxch <= students[i].chinese)
        {
            maxch = students[i].chinese;
        }
        if (maxma <= students[i].math)
        {
            maxma = students[i].math;
        }
        if (maxen <= students[i].english)
        {
            maxen = students[i].english;
        }
        if (maxco <= students[i].computer)
        {
            maxco = students[i].computer;
        }
    }
        printf("最高分 %d\t%d\t%d\t%d\n", maxen, maxco, maxma, maxch);
    

    }

    void min_(struct student students[], int n){
    int i;
    minch = students[0].chinese;
    minma = students[0].math;
    minen = students[0].english;
    minco = students[0].computer;
    /*各科最低*/
    for (i = 0; i {
    //此处已经改过了...
    if (minch >= students[i].chinese)
    maxch = students[i].chinese;
    if (minma >= students[i].math)
    maxma = students[i].math;
    if (minen >= students[i].english)
    maxen = students[i].english;
    if (minco >= students[i].computer)
    maxco = students[i].computer;
    }
    printf("最低分 %d\t%d\t%d\t%d\n", minen, minco, minma, minch);
    }
    void change_student(struct student *p)
    {
    int num, course, score, i;
    printf("输入学号:");
    scanf("%d", &num);
    printf("choice the course:1.english2.computer3.math4.chinese:");
    scanf("%d", &course);
    printf("输入新成绩:");
    scanf("%d", &score);
    for (i = 0; i if (p->num == num)
    break;
    switch (course)
    {
    case 1:p->english = score; break;
    case 2:p->computer = score; break;
    case 3:p->math = score; break;
    case 4:p->chinese = score; break;
    }
    }

    void mnue()
    {
    printf("********************************\n");
    printf(" 学生成绩管理系统\n");
    printf("********************************\n");
    printf(" (1)输入学生成绩\n");
    printf(" (2)查询学生成绩\n");
    printf(" (3)修改学生成绩\n");
    printf(" (4)输出学生成绩\n");
    printf(" (5) 退出系统\n");
    printf("请选择(1、2、3、4、5)______\n");
    }

    int main(void){
    struct student students[maxsize];
    int c, a;
    while (1){
    system("cls");
    mnue();
    scanf("%d", &c);
    if (c>5 || c<0)
    printf("error\n");
    else
    switch (c)
    {
    case 1:a = input_student(students); break;
    case 2:search_student(students); break;
    case 3:change_student(students); break;
    case 4:output_student(students, a); break;
    case 5:break;
    }
    }
    return 0;
    }
    #endif

    打赏 评论
  • YXTS122 2015-12-31 10:43
     #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #define maxsize 5
    struct student {
    int num;
    char name[30]; 
    int english,computer,math,chinese;
    int rank;
    };
    double aen,aco,ama,ach;int maxch,maxma,maxen,maxco,minch,minma,minen,minco,sum[5],k;
    //void menu (struct student students []);
    void input_student (struct student students []);
    void change_student (struct student *p);
    void search_student (struct student *p);
    void cal (struct student s[]);
    void max (struct student s[]);
    void min (struct student s[]);
    void sort (struct student students[]);
    void output_student (struct student students []);
    
    void input_student (struct student students [])
    {
    int i;
    for (i=0;i<5;i++){
    printf("********************************\n");
    printf("请输入:\n学号:");
    scanf_s("%d",&students [i].num);getchar();
    printf("姓名:");
    scanf_s("%s",students [i].name,30);getchar();
    printf("英语:");
    scanf_s("%d",&students [i].english);getchar();
    printf("计算机:");
    scanf_s("%d",&students [i].computer);getchar();
    printf("数学:");
    scanf_s("%d",&students [i].math);getchar();
    printf("语文:");
    scanf_s("%d",&students [i].chinese);getchar();
    }
    max (students);
    min (students);
    cal (students);
    sort(students);
    }
    
    void output_student (struct student students [ ]) 
    {
    int i;
    printf ("---------------------------------------------------------------------------\n");
    printf ("num\t name\t engl\t comp\t math\t chin\t rank\n");
    for (i=0;i<5;i++){
    printf("%d\t",students [i].num);
    printf(" %s\t",students [i].name);
    printf(" %d\t",students [i].english);
    printf(" %d\t",students [i].computer);
    printf(" %d\t",students [i].math);
    printf(" %d\t",students [i].chinese);
    printf(" %d\t\n",students [i].rank);}
    printf("平均分    \t%.1f\t%.1f\t%.1f\t%.1f\n",aen,aco,ama,ach);
    printf("最高分    \t%d\t%d\t%d\t%d\n",maxen,maxco,maxma,maxch); /*分数的调用*/ 
    printf("最低分    \t%d\t%d\t%d\t%d\n",minen,minco,minma,minch);
    printf ("---------------------------------------------------------------------------");
    }
    
    void search_student (struct student students [ ] ) 
    {
    int i,way,j;
    char a[20],cour;
    printf("choice the way:1.姓名2.课程3.总分名次");
    scanf_s("%d",&way);getchar();
    switch(way){
    case 1:
    printf("姓名:");
    scanf_s("%s",a,20);getchar();
    for (i=0;i<5;i++){
    if (strcmp(students[i].name,a)==0) { /*逐个比较相等为0 ,不等返回不相等的差值 !strcmp(students[i].name, a)*/ 
    printf(" num:%d",students [i].num);
    printf(" english:%d",students [i].english);
    printf(" computer:%d",students [i].computer);
    printf(" math:%d",students [i].math);
    printf("chinese:%d\n",students [i].chinese);}
    }
    
    case 2:printf("课程:");
    printf("a-英语,b-计算机,c-数学,d-语文:");
    scanf_s("%c",&cour);
    if(cour=='a') {
    printf(" 英语:");
    for (i=0;i<5;i++) printf(" %d",students [i].english);
    printf("平均分: %f",aen);
    printf(" 最高分:%d",maxen);
    printf("最低分: %d",minen);
    }
    
    if(cour=='b') {
    printf(" 计算机:");
    for (i=0;i<5;i++) printf(" %d",students [i].computer);
    printf("平均分: %f",aco);
    printf(" 最高分:%d",maxco);
    printf("最低分: %d",minco);
    }
    
    if(cour=='c') {
    printf(" 数学:");
    for (i=0;i<5;i++) printf(" %d",students [i].math);
    printf("平均分: %f",ama);
    printf(" 最高分:%d",maxma);
    printf("最低分: %d",minma);
    }
    
    if(cour=='d') {
    printf("语文:");
    for (i=0;i<5;i++) printf(" %d",students [i].chinese);
    printf("平均分: %f",ach);
    printf(" 最高分:%d",maxch);
    printf("最低分: %d",minch);
    }
    
    case 3:
    for (j=1;j<6;j++)
    for (i=0;i<5;i++)
    if(students [i].rank==j) printf(" name:%s",students [i].name);
    return; 
    }
    }
    
    void sort (struct student students[]){
    int i,j,x,maxsum;x=1;
    for(i=0;i<5;i++)
        sum[i]=students[i].chinese+students[i].math+
        students[i].computer+students[i].english;
    for(i=0;i<5;i++)
        students[i].rank=0;
    for(i=0;i<5;i++)
    {
        if(students[i].rank==0)
        {
            maxsum=sum[i]; k=i;
            for(j=0;j<5;j++)
            {
                if(students[j].rank==0)
                    if(sum[j]>maxsum)
                    {
                        maxsum=sum[j]; k=j;
                    }
            }
            students[k].rank=x;  x++;
        }
    }
    for(i=0;i<5;i++)
        if(students[i].rank==0)
        {
            k=i;  students[k].rank=x;
        }
    }
    
    void max (struct student students []){
    int i;
    maxch=students [0].chinese;
    maxma=students [0].math;
    maxen=students [0].english;
    maxco=students [0].computer;
    for (i=1;i<5;i++) {
    if (students [i].chinese>maxch){
    maxch=students [i].chinese;}
    if (students [i].math>maxma){
    maxma=students [i].math;}
    if (students [i].english>maxen){
    maxen=students [i].english;}
    if (students [i].computer>maxco){
    maxco=students [i].computer;}
    }
    }
    
    void min (struct student students []){
    int i;
    minch=students [0].chinese;
    minma=students [0].math;
    minen=students [0].english;
    minco=students [0].computer;
    /*各科最低*/ 
    for (i=1;i<5;i++) {
    if(students [i].chinese<minch)
    minch=students [i].chinese;
    if (students [i].math<minma)
    minma=students [i].math;
    if (students [i].english<minen)
    minen=students [i].english;
    if (students [i].computer<minco)
    minco=students [i].computer;}
    }
    
    void cal (struct student students[])
    {
        int i;double tach=0,tama=0,taen=0,taco=0;
        for(i=0;i<5;i++)
        {
            tach+=students[i].chinese;
            tama+=students[i].math;
            taen+=students[i].english;
            taco+=students[i].computer;
        }
        ach=tach/5; ama=tama/5; aen=taen/5; aco=taco/5;
    }
    
    void change_student (struct student *p) 
    {
    int num,course,score,i;
    printf("输入学号:");
    scanf_s("%d",&num);
    printf("choice the course:1.english2.computer3.math4.chinese:");
    scanf_s("%d",&course);
    printf("输入新成绩:");
    scanf_s("%d",&score);
    for(i=0;i<5;i++,p++){
    if(p->num==num)
    switch(course)
    {
    case 1:p->english=score;break;
    case 2:p->computer=score;break;
    case 3:p->math=score;break;
    case 4:p->chinese=score;break;
    }
    }
    }
    
    int main (void){
    struct student students[maxsize];
    int c;
    while (1){
    printf("********************************\n");
    printf(" 学生成绩管理系统\n");
    printf("********************************\n");
    printf(" (1)输入学生成绩\n");
    printf(" (2)查询学生成绩\n");
    printf(" (3)修改学生成绩\n");
    printf(" (4)输出学生成绩\n");
    printf(" (5) 退出系统\n");
    printf("请选择(1、2、3、4、5)______\n");
    scanf_s("%d",&c);getchar();
    if (c>5||c<1)
    printf("error\n");
    else 
    switch(c)
    {
    case 1:input_student (students);break;
    case 2:search_student (students);break;
    case 3:change_student (students);break;
    case 4:output_student (students) ;break;
    case 5:break;
    }
    if(c==5)
        break;
    }
    system("pause");
    return 0;
    }
    
    打赏 评论

相关推荐 更多相似问题