Question
Help in C++ class Person { // this is the base class private: string name; int idNumber; public: void print(); string getName(); }; class Student
Help in C++
class Person { // this is the base class private: string name; int idNumber; public: void print(); string getName(); };
class Student : public Person { // this class inherits from the base class Person private: string major; int gradYear; public: void print(); void changeMajor(const string& newMajor); }; void Person::print() { cout
Person person("Mary", 12345); // declare a Person Student student("Bob", 98764, "Math", 2018); // declare a Student cout
Person* pp[100]; // array of 100 Person pointers pp[0] = new Person(); // declare a Person pp[1] = new Student(); // declare a Student cout getName() print(); // invokes Person.print() pp[1]->print(); // also invokes Person.print() pp[1]->changeMajor("Physics"); // ERROR!
virtual void Person::print() { // ... } virtual void Student::print() { // ... }
Person* pp[100]; // array of 100 Person pointers pp[0] = new Person(); // declare a Person pp[1] = new Student(); // declare a Student pp[0]->print(); // invokes Person.print() pp[1]->print(); // invokes Student.print()
I have included the person-student class which needs to be modified. Please comment code and write in C++.
2. Programming exercise. Generalize the Person-Student class hierarchy to include classes Faculty, UndergraduateStudent, GraduateStudent, Professor, Instructor. Clearly show the inheritance structure of these classes. Propose some appropriate member variables for each class. (20 pts.)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started