Trouble using array function in gradebook

Write a C++ program that will calculate the course grade for a student in some class whose gradebook is set up with weighted categories. In particular, this program must contain the following functions:
A void function named getPoints that will input grade points for a category. This function
a. takes two array parameters (one for points earned and one for points possible), one
call-by-reference parameter for the number of items in the category, and one call-byvalue
parameter for the array parameter size.
b. asks the user to enter the number of items in a category, stores the lesser of the value
entered and the array parameter size to the call-by-reference parameter.
c. then asks the user to enter the points earned followed by the points possible for each item
in the category, stores the points entered in the appropriate array parameters.
2. A function named sumArray that takes one array parameter of base type double and two callby-
value parameters named n and size of type int, where size represents the size of the array
parameter. This function will return the sum of the first m elements of the array parameter,
where m is the lesser of n and size. The const modifier must be added to the array parameter.
3. The main() function that does the followings:
a. Read in the number of categories in the gradebook, and the weight of each category.
b. For each category in the gradebook,
i. call function getPoints to input grade points for the category
ii. call function sumArray to compute total points earned and the total points
possible for all items in the category, then compute the grade for the category.
c. Compute and display the weighted grade for each category, which equals the weight
times the grade for the category.
d. Call function sumArray to compute the total weighted grades for all categories and the
total weights of all categories. Then compute and display the course grade as percentage,
which equals the total weighted grades for all categories divided by the total weights of
all categories.

My code is pretty much complete, but I cannot get it to correctly calculate the grade in each category or the total weighted grade in each category. Any help on what i'm doing wrong will be greatly appreciated. Here is the current code I have:




#include<iostream>
using namespace std;

void getPoints(double pointsEarned[], int pointsPossible[], int& categoryItems, int ARRAY_SIZE);
/*Preconditions: ARRAY_SIZE is a global constant for the maximum number of items possible in a gradebook.
categoryItems will set the number of index items used in pointsEarned and pointsPossible. Category items
cannot exceed the size of the global constant ARRAY_SIZE. The lesser of items entered by user and the size
of the two arrays will be stored in categoryItems.
Postcondition: categoryItems will be stored in the call by reference formal parameter. The arrays will
hold the values of the actual grade points and the maximim possible grade points according to the amount of
indexes needed by categoryItems.
*/

double sumArray(int n, const double total[], int size);
/*Precondition: takes values input by user, totals them up. stores them in total[]. The size of the array is
controlled by size. n is the number of items to be totalled which is regulated to be less than or equal to size-1.
Postcondition: the array sum will total values and return them to main when called.
*/

const int ARRAY_SIZE=16;

int main()
{
int totalCategories=1, categoryNum=1, aGradeBook=1, category=1, item=1, pointsPossible[16];
double weight=1.0;
double pointsAvg=0.0, weightGrade=0.0, possWeight=0.0, actWeight=0.0;
double pointAvgTotal=0.0, endPointAvg=0.0, pointAvgTotal_1=0.0, grade=0.0;

cout <<"How many categories in the gradebook?: ";
cin >>totalCategories;

//This loop prints categories in ascending order
do
{
cout <<"Enter the weight of Category " <<categoryNum <<": ";
categoryNum++;
cin >> weight;
}

while (categoryNum<=totalCategories);
cout<<endl;


do{
int categoryItem=0, pointsPoss_1[ARRAY_SIZE];
double points_1[ARRAY_SIZE], total=0.0;

cout<< "Input grade points for category "<<aGradeBook <<": " <<endl;
aGradeBook++;

//function call to getPoints
getPoints(points_1, pointsPoss_1, categoryItem, ARRAY_SIZE);

double aSumArray=sumArray(categoryItem, points_1, ARRAY_SIZE);
//total points divided by total points possible per category
//pointsAvg=((aSumArray/bSumArray)*100);

//compute and display the percentage grade of totalled items

cout << "Your grade for category " <<aGradeBook-1 <<" is " <<aSumArray <<" out of "
<<pointsPossible << " or " <<pointsAvg <<" % "<<endl;
cout <<endl;


//re-sets points to zero for the next iteration of the loop
//points_1=0.0;
//pointsPoss_1=0.0;

}
while(aGradeBook <= totalCategories);

cout <<"Your weighted grade for Category " <<"?" <<" = " <<endl;
cout <<"Your current course grade is " <<"?" <<endl;

return 0;
}
void getPoints(double pointsEarned[], int pointsPossible[], int& categoryItems, int ARRAY_SIZE)
{
int items = 1;

cout <<"How many items available in the Category?: ";
cin >>items;

if (items <= ARRAY_SIZE - 1)
{
categoryItems = items;
}
else categoryItems = ARRAY_SIZE - 1;

for(int item = 1; item <= categoryItems; item++)
{
//categoryItems is the size of the arrays.
cout <<"Enter points earned then points possible for item " <<item <<": ";
cin >>pointsEarned[item];
cin >>pointsPossible[item];
}
}

double sumArray(int n, const double total[ ], int size)
{
double m=0.0;
for (int count = 0; count <= n; count++)
{
m += total[count];
}
return(m);
}


Topic archived. No new replies allowed.