I'm new to C++ and I'm trying to learn how to use constructors and classes. I have the code running correctly in C through structs, but when I try to implement classes in C++ I get errors I don't know where from.
The code is meant for me to input a numerical grade and a letter, e.g. 100 F. And in return it should tell me the letter grade for the first value, and the numerical value for the letter: 100:A and 45:F. I'm sure the functions are correct and I main makes sense. The error I get says there's no matching function for Grade g; in my main.
class Grade {
public:
int* percent;
char* letter;
char GRADE_MAP [11] = {'F', 'F', 'F', 'F', 'F', 'F', 'D', 'C', 'B', 'A', 'A'};
Grade(int p, char l){
percent = new int;
letter = new char;
*percent = p;
*letter = l;
}
~Grade(){
delete percent;
delete letter;
}
void setByPercent(int p){
p = *percent;
*letter = GRADE_MAP[p / 10];
}
void setByLetter(char l){
l = *letter;
*percent = 100 - (l - 'A') * 10 - 5;
}
void print(){
printf("Grade: %d: %c \n", *percent, *letter);
}
};
int main() {
int percent;
Grade g;
printf("Enter two grades separated by a space. Use a percentage for the first and letter for the second: \n");
scanf("%d", &percent);
scanf("\n");
g.setByPercent(percent);
g.print();
g.setByLetter(getchar());
g.print();
return 0;
}