Winforms C++;二维阵列

Winforms C++;二维阵列,winforms,multidimensional-array,Winforms,Multidimensional Array,我对学校的这个项目有一些问题。我试图利用一个二维数组,但得到了一些关于“没有从int到int*的转换,“>=”:“int[5]”与“int”的间接寻址级别不同的错误。我可以为一维数组编写它,但是我对二维数组的语法有困难。有人能给我指出正确的方向,我可能会错过什么吗?我在点击btnShow_后发表了评论,它工作正常,只是在点击btnGroup_时,我明显遗漏了一些东西 感谢所有可能分享一些知识的人 static const int NUMROWS = 4; static const

我对学校的这个项目有一些问题。我试图利用一个二维数组,但得到了一些关于“没有从int到int*的转换,“>=”:“int[5]”与“int”的间接寻址级别不同的错误。我可以为一维数组编写它,但是我对二维数组的语法有困难。有人能给我指出正确的方向,我可能会错过什么吗?我在点击btnShow_后发表了评论,它工作正常,只是在点击btnGroup_时,我明显遗漏了一些东西

感谢所有可能分享一些知识的人

    static const int NUMROWS = 4;
    static const int NUMCOLS = 5;
    int row, col;
    Graphics^ g;
    Brush^ redBrush;
    Brush^ yellowBrush;
    Brush^ greenBrush;
    Pen^ blackPen;


private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
             g = panel1->CreateGraphics();
             redBrush = gcnew SolidBrush(Color::Red);
             yellowBrush = gcnew SolidBrush(Color::Yellow);
             greenBrush = gcnew SolidBrush(Color::Green);
             blackPen = gcnew Pen(Color::Black);
         }

    private: System::Void btnShow_Click(System::Object^  sender, System::EventArgs^  e) {

         panel1->Refresh();

         for (int row = 0; row < NUMROWS; row++)
         {
             for (int col = 0; col < NUMCOLS; col++)
             {
                 Rectangle seat = Rectangle(75 + col * 75,40 + row *40,25,25);
                 g->DrawRectangle(blackPen, seat);
             }
         }
     }

private: System::Void btnGroup_Click(System::Object^  sender, System::EventArgs^  e) {
             int score[NUMROWS][NUMCOLS] = {{45,65,11,98,66},
                                        {56,77,78,56,56},
                                        {87,71,78,90,78},
                                        {76,75,72,79,83}};

         int mean;
         int student;
         mean = CalcMean(score[]);
         txtMean->Text = mean.ToString();

         for (int row = 0; row < NUMROWS; row++)
         {
             for (int col = 0; col < NUMCOLS; col++)
             {
                 student = (row*NUMCOLS) + (col);
                 Rectangle seat = Rectangle(75 + col * 75,40 + (row * 40),25,25);
                 if (score[student] >= 80
                     g->FillRectangle(greenBrush, seat);
                 else if (score[student] >= mean)
                     g->FillRectangle(yellowBrush, seat);
                 else 
                     g->FillRectangle(yellowBrush, seat);
                 g->DrawRectangle(blackPen, seat);
             }
         }
     }

     private: double CalcMean(int score[])
     {
         int sum = 0;
         int students = NUMROWS * NUMCOLS;
         for (int i=0; i< students; i++) sum += score[i];
         return sum / students;
     }
静态常量int NUMROWS=4;
静态常数int NUMCOLS=5;
int row,col;
图形^g;
画笔^红画笔;
刷子^黄色刷子;
刷子^绿色刷子;
黑笔;
private:System::Void Form1_Load(System::Object^sender,System::EventArgs^e){
g=panel1->CreateGraphics();
redBrush=gcnew SolidBrush(颜色:红色);
yellowBrush=gcnew SolidBrush(颜色:黄色);
greenBrush=gcnew SolidBrush(颜色:绿色);
blackPen=gc新笔(颜色:黑色);
}
private:System::Void btnShow\u单击(系统::对象^sender,系统::事件参数^e){
panel1->Refresh();
for(int行=0;行绘图矩形(黑色笔,座椅);
}
}
}
private:System::Void btnGroup\u单击(System::Object^sender,System::EventArgs^e){
整数分数[NUMROWS][NUMCOLS]={{45,65,11,98,66},
{56,77,78,56,56},
{87,71,78,90,78},
{76,75,72,79,83}};
整数均值;
国际学生;
平均值=计算平均值(分数[]);
txtMean->Text=mean.ToString();
for(int行=0;行=80
g->填充矩形(绿色刷,底座);
否则如果(分数[学生]>=平均值)
g->填充矩形(黄色刷,底座);
其他的
g->填充矩形(黄色刷,底座);
g->绘图矩形(黑色笔,座椅);
}
}
}
私人:双计算平均值(整数分数[])
{
整数和=0;
int students=NUMROWS*NUMCOLS;
对于(int i=0;i
Score[student]
相当于
*(Score+student)
,这是一个
*int
。相反,你可能应该使用
Score[row][col]
,或者它的等价物
*(Score+student)
(我强烈建议使用数组表示法)。它也相当于
*Score[student]
,但这很难看

另外,当我说“它是等价的”时,这只是因为
sizeof int==sizeof(*int)
。如果将指针逻辑与数组中的另一种类型一起使用,可能会得到令人生厌的结果