【问题标题】:print the content of 3 dimension array in c++ .. its dimensions 1st come from index and 2nd from another array and 3rd from another array?在 c++ 中打印 3 维数组的内容 .. 它的第一个维度来自索引,第二个来自另一个数组,第三个来自另一个数组?
【发布时间】:2020-05-10 09:28:12
【问题描述】:

从下面的代码中,我想制作保留在第 3 行值中的表“数组” 1 - sub_num'主题编号' 2 - 它是“来自数组”的标记 3 - 它是“来自最后一个数组”的等级

变成这样 the wanted outcome 我对 C++ 更感兴趣,并在这方面挣扎

#include <iostream>
#include <istream>
#include <cstdio>

using namespace std;

int main(){
//-----------------------------the 1st dimension-------------------------
int sub_num;
cout<<"enter number of subject registered this semester : ";
cin>>sub_num;

//-----------------------------the 2nd dimension-------------------------
float mark[sub_num];
    for(int m=1; m<sub_num+1; m++){
            printf("\n \t Enter marks that you obtained in subject number %d :",m);
            cin>>mark[m];
    }

//-----------------------------the 3rd dimension-------------------------
char *grade[sub_num];
    for(int i=0; i<sub_num; i++){
        if(mark[i]>80)
    {
        grade[i]="E";
    }
    else if(mark[i]>60 && mark[i]<=80)
    {
        grade[i]="V";
    }
    else if(mark[i]>50 && mark[i]<=60)
    {
        grade[i]="G";
    }
    else if(mark[i]>40 && mark[i]<=50)
    {
        grade[i]="P";
    }
    else {
        grade[i]="f";
    }
    }

【问题讨论】:

  • 看来你要使用struct

标签: c++ arrays multidimensional-array solver


【解决方案1】:

我想出了一个解决方案,它只是将这 2 行添加到代码中:D

for (int i=0; i<sub_num; i++){
    cout<<i<<"\t"<<mark[i]<<"\t"<<grade[i]<<"\n";

我觉得在问XD之前我必须多尝试一下

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 2021-02-22
    • 1970-01-01
    • 2022-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多