How to use arrays in class

Hey, I wanted to know if there was a way to use arrays in a class. I have a program that will calculate a students score, however I wanted to have an array where the "teacher" could type in the amount of students they have and could repeat the calculations as long as they have more students that need to be calculated. So far I have:

#include <iostream>
using namespace std;
class StudentScore{
private:
int quiz1, quiz2, midterm, final;
double total_quiz, final_mid, total_final, grade;
public:

int people;
void get_students();
void set_array_index();
void get_quizes();
void get_mid();
void get_final();
void total();

};

int main ()
{
StudentScore student[];


return 0;
}

void StudentScore::get_students()
{
cout<<"How many students do you have in your class?"<<endl;
cin>>people;
}

void StudentScore::set_array_index()
{
people=people+1;
}

void StudentScore::get_quizes()
{
const double QUIZ=.125;
cout<<"Input first quiz:"<<endl;
cin>>quiz1;
while ((quiz1>100)||(quiz1<0))
{
cout<<"Not a valid grade, try again."<<endl;
cout<<"Input first quiz:"<<endl;
cin>>quiz1;
}
cout<<"Input second quiz:"<<endl;
cin>>quiz2;
while ((quiz2>100)||(quiz2<0))
{
cout<<"Not a valid grade, try again."<<endl;
cout<<"Input second quiz:"<<endl;
cin>>quiz2;
}
total_quiz=(quiz1*QUIZ)+(quiz2*QUIZ);
}

void StudentScore::get_mid()
{
cout<<"Input Midterm Grade:"<<endl;
cin>>midterm;
while ((midterm>100)||(midterm<0))
{
cout<<"Not a valid grade, try again."<<endl;
cout<<"Input Midterm Grade:"<<endl;
cin>>midterm;
}
final_mid=midterm*.25;
}

void StudentScore::get_final()
{
cout<<"Input Final Exam Grade:"<<endl;
cin>>final;
while ((final>100)||(final<0))
{
cout<<"Not a valid grade, try again."<<endl;
cout<<"Input Final Exam Grade:"<<endl;
cin>>final;
}
total_final=final*.50;
}


void StudentScore::total()
{
grade=total_quiz+final_mid+total_final;
cout<<"Total Grade is: "<<grade<<endl;
}

I thought I might have to put people in a public name so I can use it in an array. Could someone please help a future programer in his freshman year of college out?

Thanks!!







Please use the [code][ /code] wrapper and indents so that we can understand your code. And point out the part of your code where you have the problem so that we can help.
Last edited on
Topic archived. No new replies allowed.