Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab21_Given.cpp is given here is the given code: #include #include #include using namespace std; /// Notice the personType base class has a pure virtual function.

Lab21_Given.cpp is given

image text in transcribed

here is the given code:

#include #include #include using namespace std; /// Notice the personType base class has a pure virtual function. class personType { public: personType(string, string); string getFirstName() const; string getLastName() const; virtual void printName() const = 0; void setName(string, string); private: string firstName; string lastName; }; /// The base class's pure virtual function must /// be implemented in derived classes. class doctorType : public personType { public: doctorType(string, string, string); string getSpecialty() const; void printName() const; void setSpecialty(string); private: string specialty; }; /// The base class's pure virtual function must /// be implemented in derived classes. class lawyerType : public personType { public: lawyerType(string, string, int); int getLicense() const; void printName() const; void setLicense(int); private: int license; }; personType::personType(string first, string last) { setName(first, last); } string personType::getFirstName() const { return firstName; } string personType::getLastName() const { return lastName; } void personType::printName() const { cout &vec) { // Implement your function here. } // TODO: Implement the addLawyer function. This function // gets input from the user, dynamically creates a new // lawyerType object and pushes it onto the back of the // vector of personType pointers. void addLawyer(vector &vec) { // Implement your function here. } // The printVec function is provided for you. // This function uses an iterator to call the print function of each object // that is pointed to. Think of this as a pointer to a pointer. The iterator // points to a specific position in the vector. And that position in the // vector contains a pointer that points to either a doctorType or lawyerType object. void printVec(vector &vec, vector::iterator &it) { for (it = vec.begin(); it != vec.end(); it++) (*it)->printName(); cout &vec, vector::iterator &it) { // Implement your function here. } int main() { vector vec; vector::iterator it; addDoctor(vec); addLawyer(vec); printVec(vec, it); clearVec(vec, it); return 0; }

Question: Download Lab21_Given.cpp. A base class, two derived classes, and a main function is provided 1. Read and understand the given code 2. Implement the following functions as described in each TODO task a. void addDoctor (vector &vec) c. d. &vec, &vec, void printvec(vector clearVec(vector vector::iterator vector?personType*>::iterator &it) &it) void // TODO: Implement the addDoctor function. This function // gets input from the user, dynamically creates a new // doctorType object and pushes it onto the back of the // vector of personType pointers. /I TODO: Implement the addLawyer function. This function // gets input from the user, dynamically creates a new // lawyerType object and pushes it onto the back of the // vector of personType pointers. // TODO: Implement the printVec function. This function uses an // iterator to call the print function of each object that is pointed to. // Think of this as a pointer to a pointer. The iterator points to a specific // position in the vector. And that position in the vector contains a // pointer that points to either a doctorType or lawyerType object. // TODO: Implement the clearVec function. This function uses an iterator // to step through every position of a vector and deletes the object // pointed to by personType pointer at each position. Afterwards, clear() // can be called to delete the positions themselves. 3. Consider what is achieved by creating a vector of pointers as opposed to storing the objects themselves in the vector? 4. Submit a single completed .cpp file on Blackboard

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions