Question

This is a simple C++ class using inheritance, I have trouble getting the program to work....

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

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 <iostream>
#include "CourseMember.hpp"
#include <string>
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 <string>

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

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

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

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// CourseMember.hpp

#ifndef CourseMember_hpp
#define CourseMember_hpp

#include <string>

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

#include "CourseMember.hpp"

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_;

}

//end of CourseMember.cpp

// Student.hpp

#ifndef Student_hpp
#define Student_hpp

#include "CourseMember.hpp"

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

//end of Student.hpp

// Student.cpp

#include <iostream>

#include "Student.hpp"

using namespace std;

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

}

//end of Student.cpp

// TeachingAssistant.hpp

#ifndef TeachingAssistant_hpp
#define TeachingAssistant_hpp

#include "Student.hpp"

// define enum ta_role

enum ta_role

{

               LAB_ASSISTANT,

               LECTURE_ASSISTANT,

               BOTH

};

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

//end of TeachingAssistant.hpp

// TeachingAssistant.cpp

#include <iostream>

#include "TeachingAssistant.hpp"

using namespace std;

//Constructor

TeachingAssistant::TeachingAssistant(int id, std::string first, std::string last) : Student(id,first,last),hours_per_week_(0),role_(LAB_ASSISTANT){}

//get hours

int TeachingAssistant::getHours() const

{

   return hours_per_week_;

}

ta_role TeachingAssistant:: getRole() const // NEEDS TO ADD

{

               return role_;

}

//set the hours

void TeachingAssistant::setHours(const int hours)

{

   hours_per_week_ = hours;

}

void TeachingAssistant::setRole(const ta_role role) // NEEDS TO ADD

{

               role_ = role;

}

//end of TeachingAssistant.cpp

Add a comment
Know the answer?
Add Answer to:
This is a simple C++ class using inheritance, I have trouble getting the program to work....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • My main() file does not call to the class created in a .hpp file. It comes...

    My main() file does not call to the class created in a .hpp file. It comes out with the error "undefined reference to "___" const. I want to solve this by only changing the main() .cpp file, not the .hpp file. .cpp file .hpp file Thank you! include <iostream> include <string> tinclude "CourseMember.hpp using namespace std int main0 CourseMember CourseMember(90, "Jeff", "Goldblum"): // initializing the constructor cout<< "Member ID is <<CourseMember.getID) << endl; 1/ calling getID) accessor cout <<"First Name...

  • Greetings, everybody I already started working in this program. I just need someone to help me...

    Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...

  • C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab...

    C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab9b.cpp to the project. Copy and paste the code is listed below: Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information: Shift (an integer) Hourly pay rate (a double) // Specification file for the ProductionWorker Class #ifndef PRODUCTION_WORKER_H #define PRODUCTION_WORKER_H #include "Employee.h" #include <string> using namespace std; class ProductionWorker...

  • Complete Course.cpp by implementing the PrintRoster() function, which outputs a list of all students enrolled in a course and also the total number of students in the course.

    Complete Course.cpp by implementing the PrintRoster() function, which outputs a list of all students enrolled in a course and also the total number of students in the course.Given files: main.cpp - contains the main function for testing the program.Course.cpp - represents a course, which contains a vector of Student objects as a course roster. (Type your code in here)Course.h - header file for the Course class.Student.cpp - represents a classroom student, which has three data members: first name, last name, and...

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

  • Write a C++ program that includes the following: Define the class Student in the header file Stu...

    Write a C++ program that includes the following: Define the class Student in the header file Student.h. #ifndef STUDENT_H #define STUDENT_H #include <string> #include <iostream> using namespace std; class Student { public: // Default constructor Student() { } // Creates a student with the specified id and name. Student(int id, const string& name) { } // Returns the student name. string get_name() const { } // Returns the student id. int get_id () const { } // Sets the student...

  • #ifndef PROCESSREQUESTRECORD_CLASS #define PROCESSREQUESTRECORD_CLASS #include <iostream> #include <string> using namespace std; class procReqRec { public: //...

    #ifndef PROCESSREQUESTRECORD_CLASS #define PROCESSREQUESTRECORD_CLASS #include <iostream> #include <string> using namespace std; class procReqRec { public: // default constructor procReqRec() {} // constructor procReqRec(const string& nm, int p); // access functions int getPriority(); string getName(); // update functions void setPriority(int p); void setName(const string& nm); // for maintenance of a minimum priority queue friend bool operator< (const procReqRec& left, const procReqRec& right); // output a process request record in the format // name: priority friend ostream& operator<< (ostream& ostr, const procReqRec&...

  • This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a fun...

    This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a function and three overloaded operators. You don't need to change anything in the Multiplex.h file or the main.cpp, though if you want to change the names of the movies or concession stands set up in main, that's fine. Project Description: A Multiplex is a complex with multiple movie theater screens and a variety of concession stands. It includes two vectors: screenings holds pointers...

  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • C++ Error. I'm having trouble with a pointer. I keep getting the error "Thread 1: EXC_BAD_ACCESS...

    C++ Error. I'm having trouble with a pointer. I keep getting the error "Thread 1: EXC_BAD_ACCESS (code=1, address=0x18)" The objective of the assignment is to revise the public method add in class template LinkedBag so that the new node is inserted at the end of the linked chain instead of at the beginning. This is the code I have: linkedBag-driver.cpp BagInterface.hpp LinkedBag.hpp Node.hpp int main) LinkedBag<string> bag; cout << "Testing array-based Set:" << endl; cout << "The initial bag is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT