I am getting some strange compiler errors with my code. I have pasted both the code and the class definitions below. I have tried Googling it but to no avail; the only thing I get is my constructor for Grade is wrong somewhere.
These are the build errors:
Evalution.cpp: In constructor ‘Evaluation::Evaluation(char*, Grade*)’:
Evalution.cpp:20:55: error: no match for call to ‘(Grade) (char [30], double*)’
Grades[num](Graded[num].comments,&Graded[num].mark);
This is Evaluation's definition:
#include <iostream>
#include <cstring>
#include "Evalution.h"
Evaluation::Evaluation(){
code[0]='\0';
for(int num=0;num<50;num++)
Grades[num];
}
Evaluation::Evaluation(char coursecode[],Grade Graded[]){
if(coursecode[0]='\0'&& strlen(coursecode) !=6) {
for(int num=0;num<50;num++){
if(Graded[num].mark < 0)
Evaluation();
numgrades=num;
}
}
else{
strcpy(code,coursecode);
for(int num=0;num < 50; num++) {
Grades[num](Graded[num].comments,&Graded[num].mark);
numgrades=num;
}
}
}
bool Evaluation::empty()const{
if(code[0]=='\0'){
for(int num=0;num<numgrades;num++){
if(Grades[num].mark < 0)
return true;
}
}
else
return false;
}
float Evaluation::calculateAverage() const{
float total=0;
for(int num=0;num<=numgrades;num++)
total+=Grades[num].mark;
return total/numgrades;
}
void Evaluation::display(std::ostream& os) const{
if(empty())
return;
else{
float average=calculateAverage();
os<< code << average <<endl;
for(int num=0;num<=numgrades;num++)
Grades[num].display(std::cout);
}
}
bool operator<(const Evaluation& tested, double pass){
float average=tested.calculateAverage();
if (average < pass)
return true;
else
return false;
}
std::ostream& operator<<(std::ostream& os, const Evaluation& input){
os<<input.display(&os);
}
This is Grade's definition:
#include <iostream>
#include "Grade.h"
#include <cstring>
using namespace std;
Grade::Grade(){
mark = 0;
comments[0] = '\0';
}
Grade::Grade(char commented[], double &marked){
if (commented == '\0' && marked < 0)
Grade();
else{
strcpy(comments, commented);
mark = marked;
}
}
double Grade::get() const{
return mark;
}
void Grade::display(std::ostream& os) const{
os << mark <<"-"<< comments << endl;
}
Also if there are any logical issues in the Evaluation class please let me know. Am getting the below linker errors now:
/tmp/cc1F2Crw.o: In function `main':
15 w7part2.cpp:(.text+0x44): undefined reference to `Grade::Grade(char*, double)'
16 w7part2.cpp:(.text+0x6e): undefined reference to `Grade::Grade(char*, double)'
17 w7part2.cpp:(.text+0x98): undefined reference to `Grade::Grade(char*, double)'
18 w7part2.cpp:(.text+0xb3): undefined reference to `Evaluation::Evaluation(char*, Grade*)'
19 w7part2.cpp:(.text+0xc7): undefined reference to `Evaluation::display(std::ostream&) const'
20 w7part2.cpp:(.text+0xef): undefined reference to `operator<(Evaluation const&, double)'
21 collect2: error: ld returned 1 exit status