m0_68362664
2022-04-24 22:18
采纳率: 78.9%
浏览 34

编程实现功能:可将整个students结构体数组存到硬盘上,并从存好的硬盘上读到内存的students结构体数组中


#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\t%f\t%f\t%f\t\t%f\n",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;
}

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题