If I try to call any of my get functions in main, it returns the wrong answer. For getCourseName, the strings return empty. For getAverage, a negative number is returned. For getMaxE, a large number is returned. I have tried changing my constructor and get functions but the answer stays the same. I have also tested the different index numbers.
#include <string>
#include <iostream>
using namespace std;
class CCourse {
public:
CCourse()
{
string name = "p";
double average = 0.0;
unsigned int maxEnrollment = 0;
}
CCourse(string course101, double avg, unsigned int MaxE)
{
string name = course101;
double average = avg;
unsigned int maxEnrollment = MaxE;
}
~CCourse()
{
cout << "CCourse destructed" << endl;
}
void setCourseName(string course101)
{
string name = course101;
}
void setAverage(double avg)
{
double average = avg;
}
void setMaxE(unsigned int MaxE)
{
unsigned int maxEnrollment = MaxE;
}
string getCourseName()
{
return name;
}
double getAverage()
{
return average;
}
unsigned int getMaxE()
{
return maxEnrollment;
}
private:
string name;
double average;
unsigned int maxEnrollment;
};
const int NUM_COURSES = 10;
int main()
{
CCourse courses[NUM_COURSES] = { { "BIT2400", 71.0, 90 },
{ "BIT1400", 52.7, 140 },
{ "ITEC2100", 85.3, 15 },
{ "BIT2000", 85.3, 15 } };
string x = courses[0].getCourseName();
cout << x;
}