this program requires the creation of class objects that are used to store student information, grades, and find the average. It is pretty basic, and I understand most of it, however, there is one part that I can not wrap my head around. The assignment asks for pointers to the test scores and I can not find a solution to this, or at least understand anything remotely similar. I am still a bit rusty on pointers and I have been trying to go back to try to understand them better. I would like to figure this out on my own, but unfortunately, I feel like I am not getting anywhere. Here is what I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
#include <fstream>
using namespace std;
class StudentInfo
{
public:
void setId (int);
void setAverage (double);
void setName (string);
void setScore(double );
int getId ( ) const;
double getAverage ( ) const;
string getName ( ) const;
double calcAverage ( );
private:
int id;
double average,
scores;
string name;
};
void StudentInfo::setId (int ID) {id = ID;}
void StudentInfo::setName (string student_name) {name = student_name;}
void StudentInfo::setScore (double score) {scores = score;}
int StudentInfo::getId ( ) const {return id; }
double StudentInfo::getAverage( ) const {return average;}
string StudentInfo::getName ( ) const {return name; }
double StudentInfo::calcAverage( ) {} // need to do
int main()
{
const int SIZE = 15;
int id;
double score;
string name;
ifstream fin;
fin.open ("students.txt");
if(!fin)
cout << "***failed to open***" << endl;
ifstream test_fin;
test_fin.open ("test_scores.txt");
if(!fin)
cout << "***failed to open***" << endl;
StudentInfo students[SIZE];
for (int count = 0; count < SIZE; count++)
{
fin >> id >> name;
students[count].setId(id);
students[count].setName(name);
test_fin >> score;
students[count].setScore(score);
}
return 0;
}
|
Here is what the assignment calls for:
Create arrays of class objects for 15+ student records including student ID’s, student names, pointers point to each of student’s test scores, and the average of each student’s test scores.
The part I am having the most trouble on:
"pointers point to each of student’s test scores"
I would be more than grateful for any hints or other examples, thank you!