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 49
|
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
const int MAX_CHAR = 100;
class Student
{
public:
Student::Student(const char initId[], float initGpa){
strcpy(id, initID);
gpa = initGpa;
}
bool Student::isLessThanByGpa(const Student& aStudent){
if (gpa < aStudent.getGpa()){
return true;
}
else{
return false;
}
}
bool Student::isLessThanByID(const Student& aStudent){
if (strcmp(id, aStudent.getId()) > 0){
return true;
}
else {
return false;
}
}
char getId(){
return id;
}
float getGpa(){
return gpa;
}
private:
char id[MAX_CHAR];
float gpa;
};
|
/*Errors:
Error 1 error C2065: 'initID' : undeclared identifier
Error 2 error C2662: 'float Student::getGpa(void)' : cannot convert 'this' pointer from 'const Student' to 'Student &'
Error 3 error C2662: 'char Student::getId(void)' : cannot convert 'this' pointer from 'const Student' to 'Student &'
Error 4 error C2660: 'strcmp' : function does not take 1 arguments
Error 5 error C2440: 'return' : cannot convert from 'char [100]' to 'char'
6 IntelliSense: identifier "initID" is undefined
7 IntelliSense: the object has type qualifiers that are not compatible with the member function
object type is: const Student
8 IntelliSense: the object has type qualifiers that are not compatible with the member function
object type is: const Student
9 IntelliSense: return value type does not match the function type
*/