Ok so my question is when dividing up a program into header files and source files, as our teacher refers to as "Modules" I am running into a little confusion on exactly what goes where.
I know the function prototypes go in the header files, and that the meat of the code is implemented into the source files. But do those also include the function prototypes? This seems to kinda defeat the purpose but it obviously does it for the reason to not have to compile everything all over again.
My bigger question is that I am getting about 8 errors that are trivial but I cannot figure out why. I know that the code is probably in the wrong area or I am not putting it correctly in the separate files.
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
|
//Here is my student.cpp file
#include "student.h"
using namespace std;
Student::Student
{
}
struct Student () {
string name;
int credits;
double qualityPoints;
};
void addGrade(Student& aStudent, string grade, int credits)
{
aStudent.credits += credits;
double v = findGradeValue(gradeValues, 11, grade);
aStudent.qualityPoints += credits * v;
}
double Student::computeGPA (const Student& aStudent)
{
if (aStudent.credits > 0)
return aStudent.qualityPoints / aStudent.credits;
else
return 0.0;
}
//And here is my student.h file
#ifndef STUDENT_H_INCLUDED
#define STUDENT_H_INCLUDED
#include <fstream>
#include <string>
using namespace std;
class student
{
public:
void addGrade(Student& aStudent, std::string grade, int credits);
double computeGPA (const Student& aStudent);
};
#endif // STUDENT_H_INCLUDED
|
Most of the errors are forward declarations, and that they are not defined. Not that they are not defined in the scope, just not defined.
student.h|12|error: 'Student' has not been declared|
student.h|13|error: 'Student' does not name a type|
student.h|13|error: ISO C++ forbids declaration of 'aStudent' with no type [-fpermissive]|
student.cpp|4|error: 'Student' does not name a type|
student.cpp|7|error: expected unqualified-id before ')' token|
student.cpp||In function 'void addGrade(Student&, std::string, int)':|
student.cpp|15|error: invalid use of incomplete type 'struct Student'|
student.cpp|7|error: forward declaration of 'struct Student'|
student.cpp|16|error: 'gradeValues' was not declared in this scope|
student.cpp|16|error: 'findGradeValue' was not declared in this scope|
student.cpp|17|error: invalid use of incomplete type 'struct Student'|
student.cpp|7|error: forward declaration of 'struct Student'|
student.cpp|20|error: invalid use of incomplete type 'struct Student'|
student.cpp|7|error: forward declaration of 'struct Student'|
I know a few fixes would make all the errors go away. But my limited knowledge keeps me from understanding what it is I am doing wrong. Any insight on my problems would be much appreciated.