Create the inheritance hierarchy displayed below. The Student class has name(string) as a private data member. The UndergraduateStudent class has private data member rank(string) that can be either freshman, sophmore, junior or senior. The GraduateStudent has private data member project (string). Include constrcutor and get/set functions as well as a print function in all classes. Test the class hierarchy by demonstrating polymorphic behiavior by decalring a vector containing Student, UndergraduatStudent, and GraduateStudent. Process the vector elements by calling the print function on each object in the array. Student Undergraduate Student Graduate Student

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
**Creating an Inheritance Hierarchy in Programming**

### Overview

The task is to create an inheritance hierarchy based on the design in the diagram. The hierarchy consists of a base class and two derived classes, each with specific attributes and functionalities.

### Class Descriptions

1. **Student Class**
   - **Attributes:** 
     - `name (string)`: A private data member to store the student's name.
   - **Functions:**
     - Include a constructor for initialization.
     - Get and set functions for accessing and updating the `name`.
     - A print function to display the student's information.

2. **UndergraduateStudent Class (Derived from Student)**
   - **Attributes:**
     - `rank (string)`: A private data member that can be one of the following—freshman, sophomore, junior, or senior.
   - **Functions:**
     - Include a constructor to initialize data members.
     - Get and set functions for accessing and updating the `rank`.
     - Override the print function to display undergraduate student details.

3. **GraduateStudent Class (Derived from Student)**
   - **Attributes:**
     - `project (string)`: A private data member to describe the student's project.
   - **Functions:**
     - Include a constructor to initialize data members.
     - Get and set functions for accessing and updating the `project`.
     - Override the print function to display graduate student details.

### Implementation

- **Polymorphic Behavior:** 
  - Demonstrate polymorphism by creating a vector containing objects of `Student`, `UndergraduateStudent`, and `GraduateStudent`.
  - Process each element in the vector by calling the print function, showcasing dynamic binding.

### Diagram Explanation

The diagram is a simple representation of class inheritance:

- **Student** is the base class.
- **UndergraduateStudent** and **GraduateStudent** are derived classes, each inheriting from the `Student` class.
- This hierarchy illustrates the "is-a" relationship central to object-oriented design, where both Undergraduate and Graduate students are types of Students.

By following this structure, one can efficiently manage and extend student-related functionalities in an educational software system.
Transcribed Image Text:**Creating an Inheritance Hierarchy in Programming** ### Overview The task is to create an inheritance hierarchy based on the design in the diagram. The hierarchy consists of a base class and two derived classes, each with specific attributes and functionalities. ### Class Descriptions 1. **Student Class** - **Attributes:** - `name (string)`: A private data member to store the student's name. - **Functions:** - Include a constructor for initialization. - Get and set functions for accessing and updating the `name`. - A print function to display the student's information. 2. **UndergraduateStudent Class (Derived from Student)** - **Attributes:** - `rank (string)`: A private data member that can be one of the following—freshman, sophomore, junior, or senior. - **Functions:** - Include a constructor to initialize data members. - Get and set functions for accessing and updating the `rank`. - Override the print function to display undergraduate student details. 3. **GraduateStudent Class (Derived from Student)** - **Attributes:** - `project (string)`: A private data member to describe the student's project. - **Functions:** - Include a constructor to initialize data members. - Get and set functions for accessing and updating the `project`. - Override the print function to display graduate student details. ### Implementation - **Polymorphic Behavior:** - Demonstrate polymorphism by creating a vector containing objects of `Student`, `UndergraduateStudent`, and `GraduateStudent`. - Process each element in the vector by calling the print function, showcasing dynamic binding. ### Diagram Explanation The diagram is a simple representation of class inheritance: - **Student** is the base class. - **UndergraduateStudent** and **GraduateStudent** are derived classes, each inheriting from the `Student` class. - This hierarchy illustrates the "is-a" relationship central to object-oriented design, where both Undergraduate and Graduate students are types of Students. By following this structure, one can efficiently manage and extend student-related functionalities in an educational software system.
Expert Solution
Step 1: Algorithm:
  1. Start.
  2. Include necessary header files: <iostream> and <vector>.
  3. Define a Student class with a private member name, a constructor, and methods to get and set the name, and a virtual print method.
  4. Define an UndergraduateStudent the class that inherits from Student, with an additional rank member and methods to get and set the rank, and an overridden print method.
  5. Define a GraduateStudent the class that inherits from Student, with an additional project member and methods to get and set the project, and an overridden print method.
  6. In the main function, create a vector of pointers to Student objects.
  7. Add instances of Student, UndergraduateStudent, and GraduateStudent to the vector.
  8. Loop through the vector and call the print method for each student, which dynamically dispatches to the appropriate class's print method due to polymorphism.
  9. Clean up the allocated memory by deleting the objects in the vector.
  10. Return 0 to indicate successful execution.
  11. End.
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education