Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9318219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:04:04+00:00 2026-06-19T03:04:04+00:00

I have an assignment which deals with inheritance. I have a Base Class of

  • 0

I have an assignment which deals with inheritance.

I have a Base Class of Employee(), which Manager(), and Intern() inherit from.

My instructor gave us the following instruction:

In main() declare an array of staff pointers and initialize them to the following records:

Manager("IT", 100, "MF1", "ML1")
Manager("HR", 50, "MF2", "ML2")
Intern("SIUE", 0, "IF1", "IL1")
Intern("SLU", 0, "IF2", "IL2")

Then i have to loop through and display the array. The output he provides as an example shows that the Manager() and Intern() toString() methods must have been called, as specific information related to the child classes was ouput. However, when accessing the array, im getting employee pointers, not pointers to the child. I’ve attached the screenshot he provided.

Screenshot of what my output needs to look like

I’m not sure how i’m supposed to accomplish this.

Here’s my staff array declaration:

Employee * staff = new Employee[4];

I can’t store a pointer to the Manager() object i don’t think. Unless there is someway i can fan-dangle this:

staff[0] = new Manager("IT", 100, "MF1", "ML1");

It seems my only option is doing something like this(how would i do this in one line btw?):

Employee * e = new Manager("IT", 100, "MF1", "ML1");
staff[0] = *e;

But obviously now when i do this:

cout << staff[0].toString();

I’m going to get the base class Employee() toString() method, not the child class.

Here are my following two classes definitions for Employee() and Manager() in case it’s relevant:

class Employee{

private:
    int eid;
    string firstName;
    string lastName;

public:
    Employee();
    Employee(int eid, string fname, string lname);
    void setEID(int eid);
    void setFirstName(string fname);
    void setLastName(string lname);
    int getEID();
    string getFirstName();
    string getLastName();
    virtual string toString();
};


class Manager : public Employee, IPayable{

private:
    string department;

public:
    Manager();
    Manager(string dept, int eid, string fname, string lname);
    double pay();
    void setDepartment(string d);
    string getDepartment();
    string toString();
};

And here is how i assumed i would implement the 2 toString() methods, with the Employee toString() embedded within the Manager() toString():

string Employee::toString(){
    return "{eid = " + std::to_string(getEID()) + ", firstName = " + getFirstName() + ", lastName = " + getLastName() + "}";  
}

string Manager::toString(){
    return "Manager{" + Employee::toString() + ", department = " + getDepartment() + ", salary = " + std::to_string(pay()) +"}";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T03:04:05+00:00Added an answer on June 19, 2026 at 3:04 am

    What you want is an array of pointers:

    Employee *staff[4];
    

    Now you can assign pointers to Employee, and therefore pointers to children of Employee to it:

    staff[0] = new Manager("IT", 100, "MF1", "ML1");
    

    And then you can call functions of Employee :

    staff[0]->toString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a base class which dictates the alignment of the objects
I have an assignment which says I have to read from file the distances
I have an Assignment model which has the following fields: :user_id , :company_id ,
I have an Assignment class which belongs to both a User class and a
I have a python script that I am writing for a class assignment which
In my class I have an assignment to create a Number class, which has
I have a homework assignment which requires input from the user and stores it
Aloha everyone, I have a class assignment in which I am tasked to build
I am taking a C++ class and have a assignment which requires me to
I have an assignment in which I have to allow a user to plot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.