Hi im trying to create a code where it would read from a separate text file some names and grades, then display them. However i am asked to use a class to "store"(if thats the word) them as below:
#include <iostream>
#include <fstream>
using namespace std;
class student
{
private:
string name;
string model;
int price;
public:
void display(student a);
void grade();
};
void student::display(student a)
{
cout<<a.name<<" "<<a.model<<endl;
cout<<"score: "<<a.price<<endl;
cout<<" "<<endl;
}
int main(){
student end;
int count=0;
student prods[100];
ifstream infile;
infile.open("C:\\students.dat");
while(infile.peek()!=EOF) {
infile
>>prods[count].name
>>prods[count].model
>>prods[count].price;
count++;
}
infile.close();
for(int i=0; i<count; i++)
end display(prods[i]);
system("pause");
return 0;
}
when using a "struct" style. it computes effectively and reads out fine. However i am unable to do this using the class as there is errors saying "the string name is set to private". any help is much appreciated.