Results 1 to 2 of 2

Thread: nyoobee

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    203

    nyoobee

    Q: A Company has many departments. an Employee of a company is associated with one department.Each department has a manager, the manager is one of the employees only.Create the necessary inheritance hierarchy and classes for the company.

    Ans: as given by teacher

    Class Company {/////}
    Class Department: public Company
    Class Employee : public Department
    Class Manager : public Employee


    Izzis correct ???...cause I dint thinkzo

    How Exactly r v supposed to represent a one-to-many or many-to-many relationship in classes ?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    class Employee { };
    
    class Manager : Employee { };
    
    class Department {
        Manager leader;
        vector<Employee> workers;
    };
    
    class Company {
        vector<Department> depts;
    };
    Or something similar I would think...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width