Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // Amount of subjects
- #define ROW 6
- // Amount of grades taken in per subject
- #define COL 1
- //for holding both student
- //and subjects average
- #define ACOL 2
- #define SIZE_ARRAY(array) (sizeof(array)/sizeof(array[0]))
- #define SIZE2D_ARRAY(array) (sizeof(array[0])/sizeof(array[0][0]))
- //proto typesj
- void
- sortRow(int list[][COL],int r,int c);
- void
- getGrades(string *s,
- int p[][COL],int m[][COL],
- int a[][COL],int e[][COL],
- int h[][COL],int b[][COL],
- string *sb, int r,int c);
- void
- Average(string *s,
- int p[][COL],int m[][COL],
- int a[][COL],int e[][COL],
- int h[][COL],int b[][COL],
- double av[][ACOL],int r,int c);
- void
- printStudentAverage (string *s,
- int p[][COL],int m[][COL],
- int a[][COL],int e[][COL],
- int h[][COL],int b[][COL],
- double av[][ACOL],int r,int c);
- void
- printSubjectAverage(string *sb,
- double av[][ACOL],int r);
- void
- largest(string *s,
- double arr[][ACOL], int r,int c);
- int main(){
- //string arrays
- string
- subjects[]={
- "Physics","Math",
- "Arabic","English",
- "History","Biology"},
- students[]={
- "Fadi","Salem",
- "Rehab","Ahamad",
- "Hahahahab"};
- /*
- 2D arrays
- **/
- int physics[ROW][COL];
- int math[ROW][COL];
- int arabic[ROW][COL];
- int english[ROW][COL];
- int history[ROW][COL];
- int biology[ROW][COL];
- double average[ROW][ACOL];
- cout<<"Hello, please input grades for the "
- <<"following stidents\n";
- getGrades(students,physics,math,arabic,
- english,history,biology,subjects,ROW,COL);
- Average(students,physics,math,arabic,
- english,history,biology,average,ROW,COL);
- printStudentAverage(students,physics,math,
- arabic,english,history,biology,average,
- ROW,COL);
- printSubjectAverage(subjects,average,ROW);
- largest(students,
- average,ROW,COL);
- cout<<"\n";
- return 0;
- }
- void printSubjectAverage(string *sb,
- double av[][ACOL],int r)
- {
- cout<<"\nSubject Averages\n";
- int d=0;
- for(int i=0;i<r;i++){
- cout<<sb[d]<<" "
- <<av[i][1]<<endl;
- d++;
- }
- }
- void getGrades(string *s,
- int p[][COL],int m[][COL],
- int a[][COL],int e[][COL],
- int h[][COL],int b[][COL],
- string *sb,int r,int c)
- {
- int i,q,ss=0;
- for(i=0;i<r-1;i++){
- //students name
- cout<<"\nEnter grades for "<<s[i]<<"\n";
- for(q=0;q<c;q++){
- cout<<sb[ss]<<endl;
- cin>>p[i][q];
- cout<<sb[++ss]<<endl;
- cin>>m[i][q];
- cout<<sb[++ss]<<endl;
- cin>>a[i][q];
- cout<<sb[++ss]<<endl;
- cin>>e[i][q];
- cout<<sb[++ss]<<endl;
- cin>>h[i][q];
- cout<<sb[++ss]<<endl;
- cin>>b[i][q];
- ss=0;
- }
- }
- /*
- for cross compiling.
- clear screen after input
- **/
- #ifdef __linux__
- system("clear");
- #elif _WIN32
- system("cls");
- #endif
- }
- void Average(string *s,
- int p[][COL],int m[][COL],
- int a[][COL],int e[][COL],
- int h[][COL],int b[][COL],
- double av[][ACOL],int r,int c)
- {
- int x,z;
- double sum=0.0;
- for(x=0;x<r;x++){
- for(z=0;z<c;z++){
- sum += p[x][z];
- sum += m[x][z];
- sum += a[x][z];
- sum += e[x][z];
- sum += h[x][z];
- sum += b[x][z];
- }
- av[x][0]=(sum/r);
- sum=0;
- }
- // might as well figure out subject average
- //
- sum=0;
- for(x=0;x<c;x++)
- for(z=0;z<r;z++){
- sum += p[x][z];
- sum += m[x][z];
- sum += a[x][z];
- sum += e[x][z];
- sum += h[x][z];
- sum += b[x][z];
- av[z][1]=(sum/r);
- sum=0;
- }
- }
- void
- printStudentAverage (string *s,
- int p[][COL],int m[][COL],
- int a[][COL],int e[][COL],
- int h[][COL],int b[][COL],
- double av[][ACOL], int r,int c)
- {
- int k,t;
- cout<<"\nStudent Averages\n";
- for(k=0;k<ROW-1;k++){
- cout<<endl<<s[k]<<" ";
- for(t=0;t<COL;t++)
- cout<<av[k][t];
- }
- 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]);
- }
- }
- }
- }
- }
- void largest(string *s,
- double arr[][ACOL], int r,int c)
- {
- int i,j,hold;
- // Initialize maximum element
- double max = arr[0][0];
- for(i=0;i<r-1;++i){
- for(j=0;j<c;++j)
- if(arr[i][j]>max){
- max=arr[i][j];
- hold=i;
- }
- }
- cout<<"\nStudent with highest average \n"
- <<s[hold]<<" "<<max<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement