Question: I am having a hard time converting this code to normal pointer notation, it is in shared pointer notation currently and I am supposed to
I am having a hard time converting this code to normal pointer notation, it is in shared pointer notation currently and I am supposed to switch it. I have been unsuccessful for the past few hours so I figured I'd ask for help. The professor wants anything that says shared_ptr or make_shared gone and replaced with regular pointers.
OUTPUT:
Professor Indiana Jones teaches Archeology. Sean Bolster's advisor is Indiana Jones.
iheritance1.h
#include #include using namespace std;
enum class Discipline {ARCHEOLOGY, BIOLOGY, COMPUTER_SCIENCE}; enum class Classification {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR};
class Person { protected: string name; public: Person() { setName(""); } Person(const string& pName) { setName(pName); } void setName(const string& pName) { name = pName; } string getName() const { return name; } };
class Student : public Person { private: Discipline major; shared_ptradvisor; public: // Constructor Student(const string& sname, Discipline d, const shared_ptr& adv);
void setMajor(Discipline d) { major = d; } Discipline getMajor() const { return major; } void setAdvisor(const shared_ptr& p) { advisor = p; } shared_ptr getAdvisor() const { return advisor; } };
class Faculty :public Person { private: Discipline department; public: // Constructor Faculty(const string& fname, Discipline d) { // Access the protected base class member name = fname; department = d; } // Other member functions void setDepartment(Discipline d) { department = d; } Discipline getDepartment() const { return department; } };
inheritance1.cpp
#include "inheritance1.h" //********************************************* // Constructor for the Student class. * //********************************************* Student::Student(const string& sname, Discipline d, const shared_ptr& adv) { // Access the protected member name name = sname;
// Access the other members major = d; advisor = adv; }
pr11-23(1).cpp
//This program demonstrates the use of //objects of derived classes. #include "inheritance1.h" #include #include using namespace std;
// These arrays of string are used to print // values of enumerated types const string dName[] = { "Archeology", "Biology", "Computer Science" };
const string cName[] = { "Freshman", "Sophomore", "Junior", "Senior" };
int main() { // Create Faculty and Student objects shared_ptr prof = make_shared("Indiana Jones", Discipline::ARCHEOLOGY); shared_ptr st = make_shared("Sean Bolster", Discipline::ARCHEOLOGY, prof); cout << "Professor " << prof->getName() << " teaches " << dName[static_cast(prof->getDepartment())] << "." << endl;
//Get student's advisor shared_ptr pAdvisor = st->getAdvisor(); cout << st->getName() << "\'s advisor is " << pAdvisor->getName() << "."; cout << endl;
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
