Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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++

image text in transcribed

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(3);

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 everybody (3); everybody [O] new Person( 'Monic'", 18); everybody [1] = new Student( Ross,, , 20, ("NYU"); everybody [2] - new Student( Rachel'', 19, UCLA') for ( n = 1 ; n

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

More Books

Students also viewed these Databases questions

Question

suggest a range of work sample exercises and design them

Answered: 1 week ago