如何比较1D阵列和2D阵列(C++)
How to compare 1D arrays to 2D arrays (C++)
我正在编写一个程序,该程序随机生成10名学生对5道题测试的答案(存储在2D数组中(。然后将测试答案与答案关键字(1D数组(进行比较并打分。我不知道如何将1D阵列与2D阵列进行比较并为测试打分。有人能帮忙吗?(我尽可能多地编码(
//Test grading program
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
//random answers to 10 text questions
srand(time(NULL));
const int KEY[5] = {1,1,3,2,4};
int studentAnswers[10][5];
int x = 0;
int scores[5];
int gradeAssignment (int KEY, int studentAnswers);
int correctAns = 0;
while ( x < 10)
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 5; j++)
{
studentAnswers[i][j] = rand() % 5+1;
cout<< studentAnswers[i][j]<< " ";
x++;
}
cout << endl;
}
}
//comparing scores
//PROBLEM AREA
这应该会得到每个学生的分数。为了将每个学生的答案与密钥进行比较,我们使用j索引值来单独比较这些值,然后将其存储到不同学生的相应i索引中。
int scores[10]={0};
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 5; j++)
{
studentAnswers[i][j] = rand() % 5+1;
cout<< studentAnswers[i][j]<< " ";
if(studentAnswers[i][j] == KEY[j])
{
scores[i]+=1;
}
}
cout <<endl;
}
for (int i = 0; i < 10; i++)
{
cout<<scores[i]<<endl;
}
相关文章:
- C++动态安全 2D 交错阵列
- 库特<<恩德尔;不适用于打印 2D 阵列
- 具有可变尺寸的 C++ 2D 阵列
- 如何通过Boost.MPI发送2d Boost.MultiArray的子阵列?
- 如何从2d Boost.MultiArray获取子阵列?
- 基于用户输入的 2D 动态阵列
- 2D 动态阵列被视为特洛伊木马?
- 如何遍历 2D 阵列?
- 超级对撞机2D阵列:生成嵌套:包装/尺寸问题
- 动态 2D 阵列.为什么分段错误?
- 尝试使用2D阵列
- 分配给阵列时出现分段错误?黑客排名 2D 阵列 - DS.
- 如何将1D阵列访问为2D阵列
- 分配/访问2d阵列,使得2d子块是连续的
- 重新分配2D阵列并删除旧阵列
- 不使用新的动态2D阵列
- 我正在为2D阵列参数而挣扎
- 特征和巨大的密集 2D 阵列
- 全球字符阵列(2D)
- 如何将内存映像分配给DLIB阵列2d或映像