【问题标题】:parallel arrays and structs? C++并行数组和结构? C++
【发布时间】:2014-04-10 00:31:37
【问题描述】:

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

提前感谢所有帮助!

【问题讨论】:

  • “并行数组”是什么意思?
  • 在 studentScores[NUM_STUDENTS][NUM_SCORES] 中的并行数组;我如何将它实现到结构中?使其成为结构中的数组,然后将结构的变量声明为数组?
  • “平行”是指“多维”吗?你的方法不正确吗?
  • 不,这是我的代码和错误pastebin.com/GzPTb76h

标签: c++ arrays struct parallel-processing


【解决方案1】:
  • 您将该结构声明为全局结构。所以你不需要通过它 总是。只保留数组的长度
  • 你最好使用类。

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

http://pastebin.com/zWDtXtHZ

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-12
    • 2012-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多