Question
This is a simple c++ Class Inheritance program. I am trying to get my derived class (Student) to work with my base class (CourseMember). Please
This is a simple c++ Class Inheritance program. I am trying to get my derived class (Student) to work with my base class (CourseMember). Please try to not change the .hpp members as they are apparently correct and should run as is. If there needs to be some change, please highlight the change.
CourseMember.hpp (BASE CLASS)
------------------------------------
#ifndef CourseMember_hpp #define CourseMember_hpp
#include
class CourseMember { public: /** Parameterized constructor @param id the student's unique identifier @param first the student's first name @param last the student's last name */ CourseMember(int id, std::string first, std::string last);
//********** Accessor Methods ****************
/** @return returns id_; */ int getID() const;
/** @return returns first_name_ */ std::string getFirstName() const;
/** @return returns last_name_ */ std::string getLastName() const;
protected: int id_; /** the CourseMember's ID */ std::string first_name_; /** the CourseMember's first name */ std::string last_name_; /** the CourseMember's last name */
}; //end CourseMember
#endif /* CourseMember_hpp */
----------------------------------------------------
CourseMember.cpp
------------------------------------------------------
#include
CourseMember::CourseMember(int id, std::string first, std::string last) { id_ = id; first_name_ = first; last_name_ = last; }
//Return ID int CourseMember::getID() const { return id_; }
/** @return returns first_name_ */ string CourseMember::getFirstName() const { return first_name_; }
/** @return returns last_name_ */ string CourseMember::getLastName() const { return last_name_; }
---------------------------------------------------------------
Student.hpp (DERIVED CLASS)
----------------------------------------------------------
#ifndef Student_hpp #define Student_hpp
#include "CourseMember.hpp" #include
class Student : public CourseMember { public: Student(int id, std::string first, std::string last); std::string getMajor() const; double getGpa() const; void setMajor(const std::string major); void setGpa(const double gpa);
protected: std::string major_; double gpa_; };
#endif
----------------------------------------------
Student.cpp
--------------------------------------------- #include
//Constructor Student::Student(int id, std::string first, std::string last) //error { id_ = id; first_name_ = first; last_name_ = last; }
//get student major string Student::getMajor() const { return major_; } //get GPA double Student::getGpa() const { return gpa_; } //set student major void Student::setMajor(const std::string major) { major = major_; //error } //set student GPA void Student::setGpa(const double gpa) { gpa = gpa_; // error }
Thank You
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started