array and vectors (arrayFunctions)

#include <iostream>
#include <iomanip>

using namespace std;

int getScores(int [], int ,int []);
void printScores(const int [], int ,const int []);
void countScores(const int [], int, int []);

int main()
{
const int ary_size = 5;
int studentscore[ary_size]; //Declaring array
int studentID[ary_size]; //Declaring array
int sum=0;
int gradeCount[7] = {};

sum = getScores(studentscore, ary_size, studentID);
countScores(studentscore, ary_size, gradeCount);
printScores(studentscore, ary_size, studentID);


cout<<"sum of all grades is"<<sum<<endl;
cout<<"Average grade is "<<sum/ary_size<<endl;

cout<<"Number of student(s) less than 50: "<<gradeCount[0]<<endl;
cout<<"Number of student(s) with 50s: "<<gradeCount[1]<<endl;
cout<<"Number of student(s) with 60s: "<<gradeCount[2]<<endl;
cout<<"Number of student(s) with 70s: "<<gradeCount[3]<<endl;
cout<<"Number of student(s) with 80s: "<<gradeCount[4]<<endl;
cout<<"Number of student(s) with 90s: "<<gradeCount[5]<<endl;
cout<<"Number of student(s) with 100: "<<gradeCount[6]<<endl;

system ("pause");
return 0;
}

int getScores(int studentscore[], int sizeofAry, int studentID[])
{
int sum=0;

for(int i=0;i<sizeofAry;i++) //Loop which inputs arrays data and
{
cout<<"Enter Grade "<<i+1<<endl;
cin>>studentscore[i];
if ((studentscore[i] < 0) || (studentscore[i] > 100))
{
cout<<"Invalid score. Please enter in between 0 and 100."<<endl;
i--;
}
else
{
studentID[i] = i+1;
sum += studentscore[i];
}
}

return sum;

}

void countScores(const int studentscore[], int sizeofAry, int countAry[])
{
for(int i=0;i<sizeofAry;i++) //Loop which inputs arrays data and
{
if (studentscore[i]<50)
countAry[0]++;
else if (studentscore[i]<60)
countAry[1]++;
else if (studentscore[i]<70)
countAry[2]++;
else if (studentscore[i]<80)
countAry[3]++;
else if (studentscore[i]<90)
countAry[4]++;
else if (studentscore[i]<100)
countAry[5]++;
else if (studentscore[i]==100)
countAry[6]++;
}
}

void printScores(const int studentscore[], int sizeofAry,const int studentID[])
{
cout <<setw(11)<< "Student ID"<<setw(13)<<"Score"<<endl;

for (int j=0; j<sizeofAry;j++)
{
cout<<setw(7)<<studentID[j]<<setw(13)<<studentscore[j]<<endl;
}
}


how change this program to (Convert the ArrayFunctionExample with two dimentional array to keep the student ID and scores together as one array.)???
closed account (48T7M4Gy)
Say studentID[50] is 512 then score[50] will be the score for student 512.

If you have more than 1 score per student score[50][10], score[50][2], ... etc
Topic archived. No new replies allowed.