For the given class code given below, create the associated class definition.
Our test cases already have the code below, we just need the correct definition (the
information placed in a .h file).
Program::Program()
{
studentName = "John Doe";
}
Program::Program(string name)
{
studentName = name;
}
bool Program::AddCourse(double value, string courseName)
{
if (credits.size() < 100)
{
credits.push_back(value);
courses.push_back(name);
return true;
}
return false;
}
double Program::CalcAverage()
{
int count=0;
double sum=0;
for (int i=0; i < credits.size(); i++)
if (credits[i] > 0.)
{
sum += credits[i];
count++;
}
if (count > 0)
return sum / count;
else
return 0;
}
int Program::CountCourses(double min_credits)
{
int count=0;
for (int i=0; i < credits.size(); i++)
if (credits[i] > min_credits)
count++;
return count;
}
int Program::CountSameCourse(string courseName)
{
int count=0;
for (int i=0; i < courses.size(); i++)
if (courses[i] == courseName)
count++;
return count;
}
Note: In this question, you might notice that the test cases are accessing private data
members. That is possible here because the private data members have been defined public
using "#define private public"