Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

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

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

Students also viewed these Databases questions

Question

What is the order of packets in the DHCP lease process?

Answered: 1 week ago

Question

Which form of proof do you find most persuasive? Why?

Answered: 1 week ago