软吐司_ 2022-05-22 13:20 采纳率: 0%
浏览 59
已结题

如何录入学生信息,搜索学生名,修改成绩,列出成绩表,升序降序排列

#include "stdio.h"
#define NC 100
struct studentRed { //定义学生记录,即对应表格的一行
char studName[20]; //姓名对应第一列的Student Name
char studID[20]; //学号对应第二列的Student ID 用20个字符编码,可用字母做学号
float compProgram; // score for Computer programming 用浮点数可输入小数分数
float physEducat; //score for Computer programming
float commResech; //score for Communication and Research
float averageScore; //average score
}*p,students[NC]={
{"John","zy001",84,86,78,0},
{"Xiaoming","zy002",77,82,90,0},
{"Xiaohua","zy003",79,82,85,0},
{"Jianguo","zy004",84,86,78,0},
{"Xiaodong","zy005",60,55,40,0},
};

void insertAvgScore(struct studentRed *stu,int length){
for (int i = 0; i <length ;++i) {
stu[i].averageScore=(stu[i].compProgram+stu[i].physEducat+stu[i].commResech)/3;
}
}
void printStudentInfo(struct studentRed *stu,int length){
printf("Name\t\tID\t\tComputer\tPhysical\tCommunication\tAverages\n");
for(int i=0;i<length;i++){
printf("%-12s%s",stu[i].studName,stu[i].studID,stu[i].compProgram,stu[i].physEducat,stu[i].commResech,stu[i].averageScore);
}

}

int main(){
insertAvgScore(students,5);
printStudentInfo(students,5);
return 0;
}

  • 写回答

2条回答 默认 最新

  • fuill 2022-05-22 14:03
    关注
    获得5.00元问题酬金

    img


    这是输入一个的

    #include "stdio.h"
    #define NC 100
    struct studentRed   //定义学生记录,即对应表格的一行
    {
        char studName[20]; //姓名对应第一列的Student Name
        char studID[20]; //学号对应第二列的Student ID 用20个字符编码,可用字母做学号
        float compProgram; // score for Computer programming 用浮点数可输入小数分数
        float physEducat; //score for Computer programming
        float commResech; //score for Communication and Research
        float averageScore; //average score
    }*p,students[NC]=
    {
        {"John","zy001",84,86,78,0},
        {"Xiaomin","zy002",77,82,90,0},
        {"Xiaohua","zy003",79,82,85,0},
        {"Jianguo","zy004",84,86,78,0},
        {"Xiaodon","zy005",60,55,40,0},
    };
    
    void insertAvgScore(struct studentRed *stu,int length)
    {
        for (int i = 0; i <length ; ++i)
        {
            stu[i].averageScore=(stu[i].compProgram+stu[i].physEducat+stu[i].commResech)/3;
        }
    }
    void printStudentInfo(struct studentRed *stu,int length)
    {
        printf("Name\tID\tComputer\tPhysical\tCommunication\tAverages\n");
        for(int i=0; i<length; i++)
        {
            printf("%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n",stu[i].studName,stu[i].studID,stu[i].compProgram,stu[i].physEducat,stu[i].commResech,stu[i].averageScore);
        }
    }
    void input(struct studentRed *stu,int i)
    {
        //for(int i=0; i<length; i++)
        {
            scanf("%s",stu[i].studName);
            getchar();
            scanf("%s",stu[i].studID);
            scanf("%f%f%f",&stu[i].compProgram,&stu[i].physEducat,&stu[i].commResech);
        }
    }
    int main()
    {
        insertAvgScore(students,5);
        printStudentInfo(students,5);
        input(students,5);
        printStudentInfo(students,6);
        return 0;
    }
    
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 5月30日
  • 创建了问题 5月22日

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办