繁体   English   中英

并行数组和结构? C ++

[英]parallel arrays and structs? C++

好的,这是我要放入一个结构中的变量,我有点担心如何使用该结构实现并行数组。 结构“ 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM