Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include "CourseMember.hpp" #include using namespace std;

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 #include "Student.hpp" #include using namespace std;

//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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

Q.No.1 Explain Large scale map ? Q.No.2 Explain small scale map ?

Answered: 1 week ago