垂直表显示与每个int大小相关的星星



我正在为我的C 课程编写一个程序,在该课程中,我需要显示一个垂直表,该表根据每个数组大小,该垂直表保持长度。数组尺寸每次运行都会改变,因为它是100个随机生成的数字,在五个不同的INT中分类。

这是我的ints:

        int sizeA=0, sizeB=0, sizeC=0, sizeD=0, sizeF=0, arraySize=100, 
biggest=0, aB=0, cD=0;
        int grades[arraySize];
        std::vector<int> gradeA, gradeB, gradeC, gradeD, gradeF;

在我的代码中,我使用了100个随机数,并使用向量将它们分类为5个新数组。尊重地归类为gradea,gradeb,.. f;

i然后使用.size((;要获取每个阵列的大小,然后找到最大的阵列大小作为我的INT最大的,以声明表的大小。我被困的地方。我不知道如何正确显示列和/或表。

for(int row = biggest; row > 0; row--){
    for(int column = 0; column < 6; column++){
        cout << row << " ";
        if()
    } cout << endl;
}

我的桌子看起来像这样,假设sizea = 3,sizeb = 2,3,1,2谨慎地:

3 *   *
2 * * *   *
1 * * * * * 
  A B C D F

任何帮助都将不胜感激,谢谢

if(gradeA.size() >= row)
   cout<<"* "; // One space at the end to separate from next star
else
   cout<<"  "; // Two spaces here to keep aligned your table

与gradec相同,Gradec ...

编辑:然后可以删除列循环

for(int row = biggest; row > 0; row--)
{
    cout << row << " ";
    if(gradeA.size() >= row)
        cout<<"* "; // One space at the end to separate from next star
    else
        cout<<"  "; // Two spaces here to keep aligned your table
    if(gradeB.size() >= row)
        cout<<"* "; // One space at the end to separate from next star
    else
        cout<<"  "; // Two spaces here to keep aligned your table
    // Same for gradeC, D, E and F
    cout << endl;
}

最新更新