Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Perform the following exercises under lab5 sub directory. 2. Implement class Person with the following protected fields: name dob gender Add the default constructor

1. Perform the following exercises under lab5 sub directory.

2. Implement class Person with the following protected fields:

name

dob

gender

Add the default constructor and a constructor that sets all three fields. Add a virtual print() function to printout the name and date-of-birth. Test your class by writing your own main().

3. Derive derived classes Student and Instructor from Person. A student has the additional field major and instructor has the additional field salary. In case of Student add the default constructor, a constructor that sets all fields, and a print() function which a. calls the base class print() and b. prints student major. In case of Instructor add the default constructor, a constructor that sets all fields, and a print() function which a. calls the base class print() and b. prints instructor salary. Test your new code by expanding main() written in 2. Use a vector of pointers to Person to use polymorphism. You may refer to the following code in your development.

image text in transcribed

image text in transcribed

4. ArgoUML is a free UML editor one could use to develop UML diagrams and generate code. At home you may download it from ArgoUML web site. Start ArgoUML by finding and clicking its icon under CSE menu option.

Once ArgoUML is open, click on Create menu option and select New Class Diagram.

Click on the yellow button on the right which consists of three sections (it should say New Class if you hover on it) and then click on the main pane to get a class box. Click on the first section of the box and name it Person.

Repeat the previous three steps to create class boxes (diagrams) for Instructor and Student.

Double click on second section of Person and add protected attribute:

name: string on the pane below the main pane change visibility to protected. Right click on the second section and use the + icon to also add the following protected attributes to Person: dob: string gender: string

Add protected attribute

major: string

to Student. Add protected attribute

salary: int

to Instructor.

Since we want derived classes Student and Instructor to have access to attributes name and dob, we make these attributes protected. The same reasoning holds for major and salary.

Double click on third section of each class and add their corresponding (public) constructors. For example, add

Person() Person(n: string, d: string, g: string)

to Person.

Perform the following steps for each constructor: a. Select a constructor by clicking on it, locate the Parameter box in the bottom pane, click on the small key in front of it, click on return, and delete it. As you know, constructors don't have a return type. b. Locate modifiers option and click on isLeaf. Constructors are not virtual functions.

Add operation print() to all three classes. Click on New Generalization icon (a yellow tip arrow) and then click on Student and drag to Person. Click on New Generalization again and click on Instructor and drag to Person. Generalization is another name for inheritance. Place the triangles on top of each other.

At this point, you should have the following UML diagram:

image text in transcribed

5. In a terminal window (outside of ArgoUML) under lab5 create uml sub-directory. You should have a directory structure similar to cs202/lab5/uml.

6. Back in ArgoUML, click on Generation menu option and select Generate All Classes. Click on the boxes under cpp, type cs202/lab5/uml under Output Directory, and click the Generate button. This will generate source files *.cpp and *.h in your uml directory.

7. Open and edit Person.h. Remove #include "int.h". Modify #include "string.h" to #include . Add using namespace std;

Do the same for the other two *.h files.

8. Add the code for all operations in *.cpp files (use the code in step 3. above). Add your own main(), develop your makefile, and compile and run your program.

9. Hand in printouts of your *.cpp and *.h files, makefile, percent completed, and typescript of the sample run.

s nam s file name s date * description #include #include #include using namespace std; class Person protected: string name; string dob; string gender; public: Person (): name( "), dob(""), gender)f Person (string n, string d, string g): name(n), dob (d), gender(g) virtual void print) f cout

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

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

Recommended Textbook for

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions

Question

KEY QUESTION Refer to columns 1 and 6 in the table for question

Answered: 1 week ago