1

while trying to create two classes and use it i encountered an error saying my "class 'GraduateStudent' does not have any field named 'advisor'" of the object he code is as follows; please help me resolve it thank you This program demonstrates the creation and use of two objects, one of class Student and a second of GraduateStudent. The output of this program is as follows:

constructing student Cy N
6
Sense constructing student Matt Madox 
constructing graduate student Matt Madox
2
adding grade to Cy N Sense
adding grade to Matt Madox Matt’s qualifier grade = 1.5
Press any key to continue . . . 

Code:

//inheritanceexample
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <strings.h>

using namespace std;
// Advisor empty class

class Advisor{};
class Student
{
public:
Student((char* pName="no name")
    :   average(0.0), SemesterHours(0)
{
strncpy(name, pName, MAXNAMESIZE);
name[MAXNAMESIZE -1] = '\0';
cout << "constructing object"
 << name
 << endl;
}
 void addcourse(int Hours, float grade) 
 {
cout << "adding grade to " << name << average << endl;
average = ( SemesterHours * average + grade );
SemesterHours +=Hours;
average = average / SemesterHours; 
}
int hours(){return SemesterHours;}
float gpa(){return average;}
}

void addCourse(int hours, float grade)
{
cout << "adding grade to " << name << average << endl;
average = ( SemesterHours * average + grade );
SemesterHours +=Hours;
average = average / SemesterHours; 
}
int hours(){return SemesterHours;}
int gpa(){return average;} 
protected:
char name[MAXNAMESIZE];
 int SemesterHours;
 float average; 

};
// my sublass

class GraduateStudent : public Student
{
public:
GraduateStudent(char  *pName, Advisor &adv, float qG = 0.0) : Student(pName), advisor(adv), qualifierGrade(qG)
{
advisor;
        float qualifiergrade;       
        cout<< "constructing graduate students"
            <<pName
            <<endl;
}
};

int main(int nNumberofargs, char* PSZArgs[])
{
Advisor advisor;
// create two objects

Student llu("Cy N Sense");
GraduateStudent gs("Matt Madox", advisor, 1.5);
llu.addCourse(3, 2.5); gs.addCourse(3, 3.0);
// display the graduate student’s qualifier grade

    cout << "Matt’s qualifier grade = "
<< gs.qualifier() 
<< endl; 
cout << "Matt’s qualifier grade = "
 << gs.qualifier()
 << endl;
// wait until user is ready before terminating program 

syestem("PAUSE")
return 0;

};

leo adigwe
  • 23
  • 5
  • 4
    why are you not using `std::string` ? – 463035818_is_not_an_ai Jan 17 '20 at 13:49
  • there is quite some formatting problems in the code, please check it again. You have `int hours(){return SemesterHours;}` three times, probably a copy-paste error – 463035818_is_not_an_ai Jan 17 '20 at 13:50
  • 2
    And the compiler is right. Neither the class `Student` nor the class `GraduateStudent` have a member variable named `advisor`. It seems you might need to invest in and spend some time with [a few good books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282). – Some programmer dude Jan 17 '20 at 13:52
  • On a totally unrelated note, there's no standard C++ `` header file. There is a [``](https://en.cppreference.com/w/cpp/header/cstring) header file and its C backward compatibility `` header file. There is a POSIX [``](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/strings.h.html) header file, but it's not something you use (or need) in your program. I'm guessing you really meant `` (without the ending `s`). – Some programmer dude Jan 17 '20 at 14:07

1 Answers1

1

"class 'GraduateStudent' does not have any field named 'advisor'"

And this is right your class, both the Student and the GraduateStudent, doesn't have a member variable called advisor.

Maybe this piece of code:

class GraduateStudent : public Student
{
public:
GraduateStudent(char  *pName, Advisor &adv, float qG = 0.0) : Student(pName), advisor(adv), qualifierGrade(qG)
{
advisor;
        float qualifiergrade;       
        cout<< "constructing graduate students"
            <<pName
            <<endl;
}
};

is messed up and you want to write this:

class GraduateStudent : public Student
{
public:
Advisor advisor;
float qualifiergrade;    
GraduateStudent(char  *pName, Advisor &adv, float qG = 0.0) : Student(pName), advisor(adv), qualifierGrade(qG)
{

        cout<< "constructing graduate students"
            <<pName
            <<endl;
}
};
Zig Razor
  • 3,381
  • 2
  • 15
  • 35