Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

computer science . Please check my work.. Its not really working.?

Write a program to calculate students’ average test scores and their grades.

You may assume the following input data:

Johnson 85 83 77 91 76

Aniston 80 90 95 93 48

Cooper 78 81 11 90 73

Gupta 92 83 30 69 87

Blair 23 45 96 38 59

Clark 60 85 45 39 67

Kennedy 77 31 52 74 83

Bronson 93 94 89 77 97

Sunny 79 85 28 93 82

Smith 85 72 49 75 63

Use three arrays: a one-dimensional array to store the students’ names, a (parallel) two-dimensional array to store the test scores, and a parallel one dimensional array to store grades. Your program must contain at least the following functions: a function to read and store data into two arrays, a function to calculate the average test score and grade, and a function to output the results. Have your program also output the class average.

#include<iostream>

#include<cctype>

#include<string>

using namespace std;

const int numrows=10;

const int numcol=5;

int matrix [numrows][numcol];

void sumrows(int matrix[][numcol],int numrow);

int main()

{

const int Max=10;

string Name[Max]= {"Johnson","Aniston","Cooper","Gupta","Blair","Clark","Kennedy","Bronson","Sunny","Smith"};

for (int i=0; i < Max; i++)

//cout<<Name[i] <<endl; displays names

const int Rows=10;

const int Col=5;

int studentGrades[numrows][numcol]= {{85, 83, 77, 91, 76},

{80, 90, 95, 93, 48},

{78, 81, 11, 90, 73},

{23, 45, 96, 38, 59},

{60, 85, 45, 39, 67},

{77, 31, 52, 74, 83},

{93, 94, 89, 77, 97},

{79, 85, 28, 93, 82},

{85, 72, 49, 75, 63}};

sumrows(studentGrades, numrows);

cout<<endl;

return 0;

}

void sumRows(int matrix[][numcol],int numrows)

{

int row, col;

int sum;

for(row=0; row < numrows; row ++)

{

sum=0;

for(col =0; col < numcol; col++)

sum=sum+matrix[row][col];

cout<<"average =" <<(row+1)<<sum<<endl;

}

}

1 Answer

Relevance
  • david
    Lv 7
    8 years ago
    Favorite Answer

    It would help if you told us how it's "not working". Does it compile? Does it give a runtime error? Does it give the wrong answer?

    The first thing I notice is that you have "Rows" and "numrows" constants that do exactly the same thing. Ditto for columns. Get rid of one or the other. And then you have a const "Max" which appears to be yet ANOTHER duplicate of one of those values. Get rid of it too. You should have two constants: one for the max rows, and one for the max columns.

    The next thing I see is:

    void sumRows(int matrix[][numcol],int numrows)

    That line just looks wrong. Maybe you wanted something like this:

    void sumRows(int [][] matrix, int numcol, int numrows)

    Then change the call to it to pass numcol.

Still have questions? Get your answers by asking now.