Well for my CSC homework I was told to make a program using classes and files to organize student information. Well I got the programming done however I can't figure out my error and I was wondering if you guys could help me debug. I will post my code and the list of errors that are coming up.
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <istream.h>
#define W setw
class student
{
private:
char first[20], mi[20], last[20], year[20];
int age;
double gpa;
Public:
student();
int read(ifstream &);
void show();
double gpa();
int better(double);
};
student::student() {gpa=0;}
int student::read(ifstream & IS)
{
IS>>first>>mi>>last>>year>>age>>gpa;
return !IS.eof();
}
void student::show()
{
cout<<'\n'<<W(10)<<first<<W(4)<<mi<<W(15)<<last<<W(12)<<year<<W(3)<<age;
}
double student::gpa() {return gpa;}
int student::better(double bestgpa)
{
return gpa>bestpga && !strcmp(year, "senior");
}
int main(void)
{
student s, best;
ifstream IS = "student.dat"; cout<<"\nstudent file:";
while(s.read(IS))
{
s.show();
if(s.better(best.gpa())) best=s;
}
cout<<"\n\n the best senior: "; best.show();
return 0;
}
now here are there errors that Microsoft Visual 6 found.
Code:
Compiling...
gpa.cpp
C:\mjk\gpa.cpp(19) : error C2514: 'student' : class has no constructors
C:\mjk\gpa.cpp(11) : see declaration of 'student'
C:\mjk\gpa.cpp(19) : error C2056: illegal expression
C:\mjk\gpa.cpp(19) : error C2501: 'Public' : missing storage-class or type specifiers
C:\mjk\gpa.cpp(22) : error C2040: 'gpa' : 'double (void)' differs in levels of indirection from 'double'
C:\mjk\gpa.cpp(26) : error C2600: 'student::student' : cannot define a compiler-generated special member function (must be declared in the class first)
C:\mjk\gpa.cpp(43) : error C2063: 'gpa' : not a function
C:\mjk\gpa.cpp(43) : error C2040: 'gpa' : 'double (void)' differs in levels of indirection from 'double'
C:\mjk\gpa.cpp(43) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
gpa.obj - 8 error(s), 0 warning(s)