View the step-by-step solution to:

Question: Download Lab21. A base class, two derived classes, a main function, and a print function is provided. Read and understand the given code....

this is the c++ code given, .cpp file used. implement this file do not change the code. attached is the question. display output making sure to match the one given. 

#include <iostream>
#include <string>
#include <vector>

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 << firstName << " " << lastName << endl;
}

void personType::setName(string first, string last)
{
	firstName = first;
	lastName = last;
}

doctorType::doctorType(string first, string last, string s)
	:personType(first, last)
{
	setSpecialty(s);
}

string doctorType::getSpecialty() const
{
	return specialty;
}

void doctorType::printName() const
{
	personType::printName();
	cout << specialty << endl << endl;
}

void doctorType::setSpecialty(string s)
{
	specialty = s;
}

lawyerType::lawyerType(string first, string last, int lic)
	:personType(first, last)
{
	setLicense(lic);
}

int lawyerType::getLicense() const
{
	return license;
}

void lawyerType::printName() const
{
	personType::printName();
	cout << license << endl << endl;
}

void lawyerType::setLicense(int lic)
{
	license = lic;
}

// 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.
void addDoctor(vector<personType*> &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<personType*> &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<personType*> &vec, vector<personType*>::iterator &it)
{
	for (it = vec.begin(); it != vec.end(); it++)
		(*it)->printName();

	cout << endl;
}

// 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.
void clearVec(vector<personType*> &vec, vector<personType*>::iterator &it)
{
	// Implement your function here.
}

int main()
{
	vector<personType*> vec;
	vector<personType*>::iterator it;

	addDoctor(vec);
	addLawyer(vec);

	printVec(vec, it);

	clearVec(vec, it);

	return 0;
}

IMG_7938 2.jpg

Question: Download Lab21.cpp. A base class, two derived classes, a main function, and a print function is
provided. 1. Read and understand the given code.
2. Implement the following functions as described in each TODO task:
a. void addDoctcr(vector&lt;personType*&gt; &amp;vec) b. void addLawyer(vector&lt;personType*&gt; &amp;vec)
C. void clearVec(vector&lt;personType*&gt; &amp;vec, vector&lt;personType*&gt;::iterator &amp;it) // 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. // 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 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. 1|Page Sample Output: Enter first name: John
Enter last name: Smith
Enter specialty: Ears
Enter first name: Mary
Enter last name: Jones
Enter license: 123
John Smith Ears 'Ilary Jones
123

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question