Trying to figure out how to write this program. I need some immediate help!


Define a base class person that will contain universal information, including name, address, birth date, gender and identification (student, worker etc). Derive from this class the following classes:
Student
Worker
Student_worker

Add variable school for student class and company for worker.

Write a program that asks user to input information (student, worker etc) and creates a list of persons (the list should accept any object type). Give user choice to view list by gender and by identification( list of people who are students, list of people who are workers etc).

Don't get overwhelmed. Break things down into smaller parts and develop them one at a time. For example, first review the process by which you declare a class and how to declare attributes (variables) and actions (methods) you need/wish the class objects to have. Then try to write out the bare bones of the base class declaration. Then try to write out any of the method definitions you think the base class should have. Once you get that done then you can review the information you have regarding inheritance and apply it to declaration and defining each of the two straight forward classes. Only when you have that all done should you even start thinking of the student-worker class, which could involve multiple inheritance instead of simple inheritance. Repost with specific questions regarding theory or application thereof. If the problem is with compiling or running then be sure to post appropriate code, error messages, expected output vs observed output with given input, etc.

Don't expect people to write the program for you, but if you ask intelligent questions and post relevant information demonstrating personal diligence you should be able to get the help you need, if any, to complete this program.

Here's a start ..

#include <vector>
#include <iostream>
#include <string>

class Person  {
        std::string Name;
        std::string Adress;
     public:
        Person() {}
        Person (std::string n,std::string a) : Name(n) , Adress(a) {}
        virtual void Display()  {
                std::cout << "Name: " << Name << "\tAdress: " << Adress;
             }
        virtual ~Person() {}
   };

class Student : public Person  {
        std::string Birthday;
     public:
        Student () {}
        Student (std::string nm,std::string ad,std::string bday)
           : Person(nm,ad), Birthday(bday) {}
        void Display()  {
                Person :: Display();
                std::cout << "\tBirthday: " << Birthday << "\n";
             }
   };

class Worker : public Person  {
        std::string domain;
     public:
        Worker () {}
        Worker (std::string name,std::string address,std::string dom)
          : Person (name,address) , domain(dom) {}
        void Display ()  {
                Person :: Display();
                std::cout << "\tOccupation: " << domain << "\n";
             }
   };

class List  {     
        std::vector<Person*> list;
     public:         
        void AddPerson(Person* p)  {
           list.push_back(p);
         }
        void Enum ()  {
           for (std::vector<Person*>::iterator i=list.begin();
                i!=list.end();++i)  {
                   (*i)->Display();
             }
          }
   };

int main ()  {
        List people;
        Student JM("John Malkovich","Melrose","12-12-1984");
        Worker MH("Mr Han","Japan","Janitor");
        people.AddPerson(&JM);
        people.AddPerson(&MH);
        people.Enum();
   }
Comments
You have been asked not to do this

Here's a start ..

#include <vector>
#include <iostream>
#include <string>

class Person  {
        std::string Name;
        std::string Adress;
     public:
        Person() {}
        Person (std::string n,std::string a) : Name(n) , Adress(a) {}
        virtual void Display()  {
                std::cout << "Name: " << Name << "\tAdress: " << Adress;
             }
        virtual ~Person() {}
   };

class Student : public Person  {
        std::string Birthday;
     public:
        Student () {}
        Student (std::string nm,std::string ad,std::string bday)
           : Person(nm,ad), Birthday(bday) {}
        void Display()  {
                Person :: Display();
                std::cout << "\tBirthday: " << Birthday << "\n";
             }
   };

class Worker : public Person  {
        std::string domain;
     public:
        Worker () {}
        Worker (std::string name,std::string address,std::string dom)
          : Person (name,address) , domain(dom) {}
        void Display ()  {
                Person :: Display();
                std::cout << "\tOccupation: " << domain << "\n";
             }
   };

class List  {     
        std::vector<Person*> list;
     public:         
        void AddPerson(Person* p)  {
           list.push_back(p);
         }
        void Enum ()  {
           for (std::vector<Person*>::iterator i=list.begin();
                i!=list.end();++i)  {
                   (*i)->Display();
             }
          }
   };

int main ()  {
        List people;
        Student JM("John Malkovich","Melrose","12-12-1984");
        Worker MH("Mr Han","Japan","Janitor");
        people.AddPerson(&JM);
        people.AddPerson(&MH);
        people.Enum();
   }

OOP is a beginner at the beginning of serious

This article has been dead for over six months. Start a new discussion instead.