dimanche 15 mars 2015

Compile Error with Code


I am getting some strange compiler errors with my code and can't seem to figure them I will paste both the code and the class definitions below. I am tried goggling it but to no avail, the only thing I found is my constructor for Grade is wrong somewhere. Any help would be greatly appreciated.


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);
^
Evalution.cpp: In function ‘std::ostream& operator<<(std::ostream&, const Evaluation&)’:
Evalution.cpp:60:23: error: no matching function for call to ‘Evaluation::display(std::ostream*) const’
os<<input.display(&os);
^
Evalution.cpp:60:23: note: candidate is:
Evalution.cpp:42:6: note: void Evaluation::display(std::ostream&) const
void Evaluation::display(std::ostream& os) const{
^
Evalution.cpp:42:6: note: no known conversion for argument 1 from ‘std::ostream* {aka std::basic_ostream<char>*}’ to ‘std::ostream& {aka std::basic_ostream<char>&}’


I will paste both Class Definitions below:


This is the Class Evaluation's definiton:



#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 class Grade's definiton:

#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 anyone spots logical issues in the Evaluation class please let me known.




Aucun commentaire:

Enregistrer un commentaire