Lab Steps: Step 1 Let's have some fun! In this lab, we are going to create an abstract Person class. Then, we are going to create Instructor and Student child classes! Create the UML class diagram to...

1 answer below »
would like someone to do this for me


Lab Steps: Step 1 Let's have some fun! In this lab, we are going to create an abstract Person class. Then, we are going to create Instructor and Student child classes! Create the UML class diagram to show the inheritance relationship between the Parent class and the Child classes. · Open Visio and create a new diagram using the UML Class template. · Save the diagram as Week 6—Abstract Parent Class With Person. · Drag a class shape to your work area. · Change the class name to Person.  · Add the following attribute and make it protected so that the Child classes have direct access to them. · name as a string (remember to make it protected by using a hashtag/pound symbol) · Add getter/setter for the name · Constructor and Destructors: · Person() · Person(string pName) · virtual ~Person(); · Add the following methods, and make them virtual so that the Child classes can override them. · Speak() that returns a string (needs to be virtual)  · toString() that returns a string (virtual) · We have a problem, though! How does a Person object speak? We have to know what kind of Person object it is so that we can tell it how to speak. In other words, an instructor is going to say something different than a Student. Because we do not know how a general Person object speaks, we have to make the method abstract. In Visio, we make the method abstract by italicizing it (make the whole line italics). · It is time to do some inheritance! Drag another class shape to your work area, and place it below the Person class. · Change the name of the new class to Instructor. · Constructor and Destructors: · Instructor() · Instructor(string pName, string pQuestion) · ~Instructor(); · Add the following attribute, and make it private because we do not expect to create Child classes off of the Instructor class. Notice that we do not need to add the name attribute because we inherit it from the Parent (Person) class! · question as a string · get/set for the question · Add the following methods to override the parent's methods and to allow the child objects to behave differently than the parent objects. · Speak() that returns a string · toString() that returns a string · Let's do some more inheritance! Drag another class shape to your work area and place it below the Person class and to the right of the Instructor class. · Change the name of the new class to Student. · Constructor and Destructors: · Student() · Student(string pName, string pResponse) · ~Student(); · Add the following attribute and make it private because we do not expect to create Child classes off of the Student class. Remember that we automatically get the name attribute because we inherit it from the Parent (Person) class. · response as a short · gets/sets to response · Add the following methods to override the parent's methods and to allow the child objects to behave differently than the parent objects. · Speak() that returns a string · toString() that returns a string · We have our three classes on our Visio diagram. We need to make them related! · Drag an inheritance arrow off the template and drop it on your diagram. · Drag the tail of the arrow to the Child class (Instructor) and the head of the arrow to the Parent class (Person). This inheritance arrow states that the Instructor inherits from the Person class. · Drag an inheritance arrow from the template, and connect the Student to the Person class. Remember that the arrowhead should point to the Parent class, which is the Person class. · Save your file! Step 2 Create a C++ project, and call it Week 6—Abstract Parent Class. Now, let's realize the UML class diagram (take the UML class diagram to code). · Create a Person class using a separate header file and implementation file. · Review your UML class diagram for the attributes and behaviors to code/create · The Speak() and the toString() methods should be abstract because we do not know how a Person speaks until we know what kind of Person the object is (they should be virtual). To make the method abstract, set the virtual method to 0 like this in the .h file: · · virtual string Speak() = 0;  pure virtual method -- abstract method · the toString() method returns a string and has no arguments. It is virtual as well · The implementation for Speak() should look like this (in the cpp file) · string Person::Speak(void) { return "My name is: " + getName(); } · The implementation for toString() should look like this: · string Person::toString(void) { return "Hello "; } · Create an Instructor class using a separate header file and implementation file based on your Visio diagram. · The Instructor class needs to inherit from the Person class · The Speak() method should return a statement that you would expect from an Instructor like this: return Person::Speak() + " and my question is : " + question; · The toString() method should return the Person toString() method plus a little more. For example: return Person::toString() + " I am an Instructor\n"; · Create a Student class using a separate header and implementation file. · The Student class needs to inherit from the Person class. · The Speak() method and toString methods are shown below: string Student::Speak(void) { cout < person::speak()="">< "="" i="" am="" a="" student"="">< endl;="" switch="" (response)="" {="" case="" 0:="" return="" "the="" lab="" was="" a="" piece="" of="" cake";="" break;="" case="" 1:="" return="" "the="" lab="" was="" somewhat="" difficult="" -="" but="" i="" got="" through="" it";="" break;="" case="" 2:="" return="" "the="" lab="" was="" a="" very="" tough="" -="" it="" drove="" me="" crazy!";="" break;="" case="" 3:="" return="" "yikes="" -="" i="" can't="" wait="" until="" this="" class="" is="" over!";="" break;="" default:="" return="" "error.="" something="" went="" wrong.";="" break;="" }="" }="" string="" student::tostring(void)="" {="" return="" person::tostring()="" +="" ",="" response="" id:="" "="" +="" to_string(response);="" }="" step="" 3="" let's="" test="" our="" classes="" and="" use="" polymorphism.="" open="" the="" source="" of="" your="" main="" program.="" ·="" in="" the="" main="" method,="" check="" for="" memory="" leaks="" using="" this="" code.="" check="" for="" memory="" leaks="" #if="" defined(debug)="" |="" defined(_debug)="" _crtsetdbgflag(="" _crtdbg_alloc_mem_df="" |="" _crtdbg_leak_check_df="" );="" #endif="" ·="" create="" an="" array="" of="" person="" pointers="" like="" this.="" person*="" arrperson[4];="" ·="" at="" each="" pointer="" reference,="" create="" a="" new="" child="" object="" (instructor="" and="" student).="" for="" example:="" ·="" arrperson[0]="new" instructor(="" "dr.="" roark",="" "anyone="" need="" help?"="" );="" ·="" arrperson[1]="new" student(="" "barney", ="" 3="" );="" ·="" create="" a for loop,="" and="" make="" two="" more="" person="" objects="" speak="" (student="" or="" instructor="" -="" your="" choice.)="" notice="" that="" the="" instructor="" objects="" return="" a="" different="" statement="" than="" the="" student="" even="" though="" they="" are="" all="" located="" in="" the="" person="" array!="" how="" does="" this="" happen? polymorphism! the="" parent="" morphs="" (changes="" into)="" the="" many="" different="" children="" and="" behaves="" like="" the="" children!="" remember="" that poly means many and morph means change="" into.="" ·="" for="" (int="" i="0;" i="">< 4;="" i++)="" {="" cout="">< "person="" number:="" "="">< to_string(i="" +="" 1)="">< endl;="" cout="">< arrperson[i]-="">toString() < endl;="" cout="">< arrperson[i]-="">Speak() < endl="">< endl; } · finally, we need to clean up our memory because we used the new keyword. remember that the new keyword creates the object on the memory heap, and we are responsible for cleaning up the memory heap. use a for loop to delete the four person objects that we created. · hint - delete arrperson[i]; // i is the for loop counter endl;="" }="" ·="" finally,="" we="" need="" to="" clean="" up="" our="" memory="" because="" we="" used="" the new keyword.="" remember="" that="" the new keyword="" creates="" the="" object="" on="" the="" memory="" heap,="" and="" we="" are="" responsible="" for="" cleaning="" up="" the="" memory="" heap.="" use="" a for loop="" to="" delete="" the="" four="" person="" objects="" that="" we="" created.="" ·="" hint="" -="" delete="" arrperson[i];="" i="" is="" the="" for="" loop="">
Answered Same DayDec 05, 2021

Answer To: Lab Steps: Step 1 Let's have some fun! In this lab, we are going to create an abstract Person class....

Arun Shankar answered on Dec 12 2021
148 Votes
Instructor.cpp
#include
#include "Instructor.h"
using namespace std;
string Instructo
r::Speak()
{
return Person::Speak() + " and my question is : " + question;
}
string Instructor::toString()
{
return Person::toString() + " I am an Instructor\n";
}
Instructor.h
#include
#ifndef INST_H
#define INST_H
using namespace std;
#include "Person.h"
class Instructor: public Person
{
private:
string question;
public:
Instructor() {}
Instructor(string pName, string pQuestion) : Person(pName)
{
question = pQuestion;
}
~Instructor() {}
string Speak();
string toString();
string getQuestion() {return question; }
void setQuestion(string a) {question = a; }
};
#endif
Person.cpp
#include
using namespace std;
#include "Person.h"
string Person::Speak(void)
{
return "My name is: " + getName();
}
string Person::toString(void)
{
return "Hello ";
}
Person.h
#include...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here