Question: This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to
This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class).
The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is LAB_ASSISTANT.
CourseMember and Student does not need any changing, only TeachingAssistant.hpp/TeachingAssistant.cpp.
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
// corrected the constructor issue here
Student::Student(int id, std::string first, std::string last) : CourseMember(id, first, 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; } //set student GPA void Student::setGpa(const double gpa) { gpa_ = gpa; }
-------------------------------------------------
TeachingAssistant.hpp (Derived Class)
-------------------------------------------------------
#ifndef TeachingAssistant_hpp #define TeachingAssistant_hpp
#include "CourseMember.hpp" #include "Student.hpp" #include
class TeachingAssistant :public Student { public: TeachingAssistant(int id, std::string first, std::string last); //constructor int getHours() const; //get hours ta_role getRole() const; //set TA role NEEDS TO ADD void setHours(const int hours); // set Hours void setRole(const ta_role role); // setRole TESTING NEEDS TO ADD private: int hours_per_week_; //ta_role role_; };
#endif
----------------------------------------------------------
TeachingAssistant.cpp (Derived Class)
----------------------------------------------------------
#include
//Constructor TeachingAssistant::TeachingAssistant(int id, std::string first, std::string last) : Student(id,first,last){}
//get hours int TeachingAssistant::getHours() const { return hours_per_week_; }
// ta_role getRole() const; // NEEDS TO ADD
//set the hours void TeachingAssistant::setHours(const int hours) { hours_per_week_ = hours; }
// void setRole(const ta_role role); // NEEDS TO ADD
Thank You
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
