File Input and mutator/accessor function help
Code:
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
using namespace std;
class Student
{
private:
int hw_scores[10];
int total_percent;
char letter_grade;
public:
// Accessors
int get_max_hw_score();
int get_min_hw_score();
void get_hw_scores(int hw[10]);
int get_total_percent();
char get_letter_grade();
// Mutators
void set_hw_scores (int hw[10]);
// Constructor
Student ();
};
//*************************************************************
void main()
{
ifstream inFile;
int my_scores[10];
Student student1;
// INSERT FILE INPUT DETAILS HERE
inFile.open("my_scores.txt");
if(!inFile)
{
cout<<"ERROR!";
}
// Read in test scores.
for (int x=0;x<10;x++)
{
inFile >> my_scores[x];
}
student1.set_hw_scores(my_scores);
// INSERT SCREEN OUTPUT STATEMENTS HERE
cout<<"Your letter grade thus far is a(n): "<<student1.get_letter_grade();
cout<<"\n\nPercentage: "<<student1.get_total_percent();
cout<<"\n\nYour highest grade was a: "<<student1.get_max_hw_score();
cout<<"\n\nYour lowest grade was a: "<<student1.get_min_hw_score();
in_file.close();
getch();
}
//***********************************************************
int Student::get_max_hw_score()
{
int max=hw_scores[0];
for (int y=1; y<10; y++)
{
if (hw_scores[y] > max)
max = hw_scores[y];
}
return max;
}
//------------
int Student::get_min_hw_score()
{
int min=hw_scores[0];
for (int x=1; x<10; x++)
{
if (hw_scores[x] < min)
min = hw_scores[x];
}
return min;
}
//------------
void Student::get_hw_scores(int hw[10])
{
for (int g=0;g<10;g++)
{
hw_scores[g] = hw[g];
}
}
//------------
int Student::get_total_percent()
{
int sum=0;
for (int q=1; q<10; q++)
{
sum = sum + hw_scores[q];
}
total_percent=sum/10;
if (total_percent>=90)
{
letter_grade='A';
}
else if (total_percent>=80)
{
letter_grade='B';
}
else if (total_percent>=70)
{
letter_grade='C';
}
else if (total_percent>=60)
{
letter_grade='D';
}
else if (total_percent<60)
{
letter_grade='F';
}
return total_percent;
}
//------------
char Student::get_letter_grade()
{
return letter_grade;
}
//------------
void Student::set_hw_scores(int hw[10])
{
for (int h=0;h<10;h++)
{
hw[h] = hw_scores[h];
}
}
//------------
Student::Student()
{
for (int b=0;b<10;b++)
{
hw_scores[b] = 0 ;
}
}
When I run the program, all my integers=0 and my char = nothing...
Any suggestions would be greatly appreciated! Thanks!