Question
Please help me fix my code. It won't print the names. C++ class Person { public: Person(); Person(string input_name, int input_age); string get_input_name() { return
Please help me fix my code. It won't print the names. C++
class Person
{
public:
Person();
Person(string input_name, int input_age);
string get_input_name() { return name;}
int get_input_age() { return age;}
virtual void print() const {
cout
}
protected:
string name;
int age;
};
class Student : public Person
{
public:
Student();
Student(string input_name, int input_age, string input_college) :
Person(input_name, input_age) { }
string get_input_college() const { return college;}
virtual void print() {
cout
}
protected:
string college;
};
int main () {
vector
everybody[0] = new Person("Monica", 18);
everybody[1] = new Student( "Ross", 20, "NYU");
everybody[2] = new Student("Rachel", 19, "UCLA");
for ( int n = 1 ; n
everybody[n]->print();
return 0; }
(c) (5 points) Consider the base class Person and its derived class Student. Complete the portion of the code that is missing and correct errors so that the code compiles. L.e. implement the constructors and the member function print such that all the member fields of the objects are printed using polymorphism. class Person public: Person); Person (string input_name, int input_age); rivate: string name; int age; t; class Student : public Person public: Student O; Student (string input_ name, int input_age, string input college) private string college int main() vector
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