May 25, 2015 at 4:20am UTC
Why isn't my array of class cout<<ary[1].getname()<<endl; printing out correctly in c++?
What I would like to do is take information from a student file containing Name/id and assignment scores then calculate their final grade and assigning them a letter grade. I chose the method of printing out their ary element.
Here is my code so far:
Class StudentClass
{
public:
void setname(string x)
{
x=namep;
}
string getname()
{
return namep;
}
void setid(double y)
{
y=idp;
}
double getid()
{
return idp;
}
private:
string namep;
double idp;
double classgrade;
char lettergrade;
};
int main()
{
string name;
double id;
fstream file;
string filename;
StudentClass ary[100];
int i;
cout<<"Enter an input file: ";
cin>>filename;
file.open(filename); //File opened
while(!file.eof())
{
double q1, q2, q3, q4, q5, m1, m2, fin;
double quizgrade,midtermgrade,finalexamgrade,cl...
file>> name >> id >> q1 >> q2 >> q3 >> q4 >> q5 >> m1 >> m2 >> fin;
cout << "Have read in " << name << "'s student information\n"; //temporary, delete later
ary[i].setname(name);
quizgrade=((q1+q2+q3+q4+q5-(min(min(min(... min quiz and dropping
midtermgrade=(m1+m2)/200*100*0.40/40*100... //Grade calculation algorithms
finalexamgrade=fin/100*100*0.40/40*100;
classgrade=quizgrade+midtermgrade+finale...
i++;
}
cout<<ary[1].getname()<<endl;
Last edited on May 25, 2015 at 8:07am UTC
May 25, 2015 at 4:30am UTC
I believe it's because you didn't name the class, at the top, I only see curly braces. I hope this helped.
May 25, 2015 at 4:35am UTC
Sorry! Left that part out;Just included it; but this is the updated code ^^^ still does not work.
May 25, 2015 at 11:14pm UTC
You are missing a lot of pre-processor directives. Remember to do #include to include them in your file.