These are the specifications for the assignment:
Write the following members functions:
(a) Constructor that creates objects of the student class.
(b) read that prompts the user to enter from the keyboard student name, age and gpa.
To terminate reading the user should enter the EOF (ctrl-D in Unix and Ctrl-Z in
DOS).
(c) show that displays on the screen student name, age and gpa.
(d) writefile that writes a record (name, age, gpa) into the file student.dat.
(e) getgpa that returns gpa of the student.
(f) readfile that reads the student record from the file student.dat .
Here is ONE version, the latest , of what I was trying.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#define W setw
using namespace std;
class student{
private:
string name;
int age ;
float gpa;
public:
student(){};
student(string n,int a,float g){
name = n;age = a;gpa = g;
}
int read();
void show();
void writefile();
void readfile();
};
int student::read(){
}
void student::show(){
cout << W(10) << name << W(4) << age << W(4) << gpa << endl;
}
void student::writefile(){
ofstream OF ( "student.dat",fstream::app);
OF << W(10) <<name <<W(6)<<age<<W(4)<<gpa<<endl;
OF.close();
}
void student::readfile(){
}
}
int main(){
return 0;
}
Question: An earlier version I got the "read" function to work properly, but it would only get 1 student record, which I ASSUMED was NOT the point of using an EOF character to cease input.
These streams are confusing me and the instructor's specifications are even confusing me!
WHY oh WHY would "readfile" be a member function here?
Any input greatly appreciated!