#include <iostream>
using namespace std;
// Amount of students
#define ROW 2
// Amount of grades per subject
#define COL 3
#define SIZE_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define SIZE2D_ARRAY(array) (sizeof(array[0])/sizeof(array[0][0]))
//proto types
void sortRow(int list[][COL],int r,int c);
void createStudents(string *s, int r);
void enterGrades(string *s,int m[][COL],
int h[][COL],int e[][COL],int r,int c);
void gradesLowHigh(string *s,int m[][COL],
int h[][COL], int e[][COL],int r,int c);
void listGradesDescendingOrder(string *s,
int m[][COL],int h[][COL],int e[][COL],int r,int c);
int main(){
string students[ROW];
/*
2D arrays
**/
int math[ROW][COL];
int history[ROW][COL];
int english[ROW][COL];
int r=0,c=0,i=0;
//string name;
createStudents(students,ROW);
enterGrades(students,math,
history,english,ROW,COL);
/*
Just 3 different ways of passing
size of arrays
**/
//use of macro. helps insure proper size
//incase values have been changed elsewhere
sortRow(math,SIZE_ARRAY(math),SIZE2D_ARRAY(math));
//getting sizeof just before pasing the values
r = sizeof(history)/sizeof(history[0]);
c = sizeof(history[0])/sizeof(history[0][0]);
sortRow(history,r,c);
// USING DEFINE VALUES
sortRow(english,ROW,COL);
gradesLowHigh(students,math,history,english,
ROW,COL);
listGradesDescendingOrder(students,math,
history,english,ROW,COL);
double msum=0,hsum=0,esum=0;
double count=0;
double maverage,haverage,eaverage,average;
for(int i=0;i<ROW;i++){
cout<<"\n Averages \n";
for(int s=0;s<COL;s++){
msum += math[i][s];
hsum += history[i][s];
esum += english[i][s];
}
maverage = msum / COL;
haverage = hsum / COL;
eaverage = esum / COL;
cout<<students[i]<<"\n"
<<"Average,\n"
<<"Math "<<maverage<<"\n"
<<"History "<<haverage<<"\n"
<<"English "<<eaverage<<"\n";
maverage=0; haverage=0; eaverage=0;
msum=0; hsum=0; esum=0;
}
return 0;
}
void createStudents(string *s, int r){
// auto create students names
string name;
for(int i=0;i<r;i++)
{
auto name = "bob " + to_string(i+1);
s[i] = name;
}
}
void enterGrades(string *s,int m[][COL],
int h[][COL],int e[][COL],
int r,int c)
{
//enter grades
for(int i=0;i<r;i++)
{
cout<<"Enter "<<c<<" grades percent "
<<"for\n "<<s[i]<<" "
<<"\nMath \n";
for(int g=0;g<c;g++)
cin>>m[i][g];
cout<<"History \n";
for(int p=0;p<c;p++)
cin>>h[i][p];
cout<<"English \n";
for(int k=0;k<c;k++)
cin>>e[i][k];
}
cout<<"\n\n";
}
void gradesLowHigh(string *s,int m[][COL],
int h[][COL],int e[][COL],int r,int c)
{
int ck=0;
for(int i=0;i<r;i++){
ck++;
cout<<"Student Name\n"<<s[i]<<"\n";
if(ck==1)
{
cout<<"Highest Grade\tLowest Grade\n";
ck=0;
}
cout<<"\nMath\n"
<<m[i][0]<<"\t\t"<<m[i][c-1]<<"\n"
<<"History\n"
<<h[i][0]<<"\t\t"<<h[i][c-1]<<"\n"
<<"English\n"
<<e[i][0]<<"\t\t"<<e[i][c-1]<<"\n\n";
}
}
void listGradesDescendingOrder(string *s,
int m[][COL],int h[][COL],int e[][COL],
int r,int c){
cout<<"\nGrades\n";
for(int i=0;i<r;i++){
cout<<"Student Name\n";
cout<<s[i]<<"\n";
cout<<"\nMath\n";
for(int k=0;k<c;k++)
cout<<m[i][k]<<" ";
cout<<"\nHistory\n";
for(int j=0;j<c;j++)
cout<<h[i][j]<<" ";
cout<<"\nEnglish\n";
for(int n=0;n<c;n++)
cout<<e[i][n]<<" ";
cout<<"\n";
}
}
void sortRow(int list[][COL],int r,int c){
//loop rows
for(int i=0;i<r;i++){
//loop column
for(int j=0; j<c;j++){
//loop comparison and swap
for(int k=0;k<c-j-1;k++){
// if(list[i][k] > list[i][k+1]){
if(list[i][k] < list[i][k+1]){
//swap ellrment
swap(list[i][k],list[i][k+1]);
}
}
}
}
}