平行阵列和结构?C

parallel arrays and structs? C++

本文关键字:结构 阵列      更新时间:2023-10-16

好吧,这是我试图放入一个结构的变量,我有点担心如何使用该结构实现并行数组。结构" StudentType"正确吗?

const int NUM_STUDENTS = 10; //global variables
const int NUM_SCORES = 5;

string studentNames[NUM_STUDENTS], letterGrades[NUM_STUDENTS]; //old program variables
float studentAverages[NUM_STUDENTS];
int studentScores[NUM_STUDENTS][NUM_SCORES];
struct studentType{ 
    string name;
    string grade;
    float average;
    int scores[NUM_SCORES];
};
studentType student[NUM_STUDENTS];

我感谢所有的帮助!

  • 您将结构宣布为全局。所以你不需要通过总是。只需保持数组的长度
  • 您最好使用类。

我已修复了汇编错误。(不是逻辑错误)

http://pastebin.com/zwdtxthz