Hello, I'm currently finishing up an assignment that was half written by my professor. Below in the testGrades section of code there are two errors both are the same message. Error: no matching function for call to Grades:: Grades(const char [15]) Test Grades
//Course: 4002-210
//Author: Rayno Niemi
//Lab 4 Exercise 1
//Name: testGradeEx1.cpp
//Purpose: Test program for the class Grades
// Create stu1 Grades object
// Add 5 grades to stu1 - only 3 can be stored in stu1 - other 2 discarded
// Create stu2 Grades object
// Add only 2 grades
#include <iostream>
#include <string>
#include <iomanip>
#include "Grades.h"
usingnamespace std;
int main ()
{
//extra set of braces added so that value of destructor will be printed
{
cout << endl;
//create Grades object to hold 4 grades and print it.
Grades stu1("Tom Terrific");
stu1.printGrades();
//add 3 grades for Tom T
stu1.addGrade(77.7);
cout << endl;
stu1.printGrades();
stu1.addGrade(88.8);
cout << endl;
stu1.printGrades();
stu1.addGrade(99.9);
cout << endl;
stu1.printGrades();
//attempt to add two more grades - no space to store grades
stu1.addGrade(100.0);
cout << endl;
cout << "Attempt to add grade of 100.0 - not stored" << endl;
stu1.printGrades();
stu1.addGrade(90.0);
cout << endl;
cout << "Attempt to add grade of 90.0 - not stored" << endl;
stu1.printGrades();
//add 2 grades for Mary M
cout << endl << endl;
Grades stu2("Mary Marvelous");
stu2.addGrade(92.5);
stu2.addGrade(98.0);
stu2.printGrades();
//compute and print averages
cout << setprecision(2) << showpoint << fixed;
cout << endl;
cout << "Average for " << stu1.getName() << " is " << stu1.calcAverage( ) << endl;
cout << "Average for " << stu2.getName() << " is " << stu2.calcAverage( ) << endl;
cout << endl;
}//Grades objects now destructed at end of braces in which created
cout << endl;
return 0;
} //end main
In other words: Add another constructor that takes just the name and maxGrades (you may use a default value).
In Grades.h on line 31: gradeList must not have a fixed size. Allocate the requried size according to maxGrades in your constructor.
In Grades.cpp: addGrade() is entirely wrong. You need to check numGrades against maxGrades. Store newGrade according to numGrades and then increase numGrades
The addGrade & the calcAverage method I'm currently confused about. I fixed the other two problems as specified by your comments thank you both. Can someone please help me with the addGrade & the calcAverage methods?
calcAverage
This is supposed to calculate the average of the 3 grades in the array.
1 2 3 4 5 6 7 8 9 10
double Grades :: calcAverage() {
for (int i = 0; i <= 3; i++)
{
gradeList[i] = gradeList[i] + gradeList[i];
}
cout << " this is gradeList " << gradeList[1];
};
addGrade
This is supposed to add the grade if the array isn't full (less than 3 elements).
calcAverage
This is supposed to calculate the average of the 3 grades in the array.
How does one calculate an average? You take the sum of all elements in the array and divide it by the number of elements. Where do you do that? Why aren't you returning a value like the function signature says you're going to do? Does it make sense to modify the array as you are doing? If it doesn't make sense to modify the array, why is this function not const?
for (int i = 0; i <= 3; i++)
If there are 3 elements in the array and you're using indices 0, 1, 2 and 3... how many elements are you accessing?
addGrade
This is supposed to add the grade if the array isn't full (less than 3 elements).
Given that numGrades is number of grades currently in the array, what index should you add the next element to? Does it make sense to increment an element of the array as you do? Does it make sense to assign numGrades the value of one of the grades in the list?