001: #include <string>
002: #include <iostream>
004: using namespace std;
005: 
006: #include "ccc_empl.h"
008: /**
009:    A department in an organization.
010: */
011: class Department {
013: public:
014:    Department(string n);
015:    Department(string n, Employee e);
016:    ~Department();
017:    Department& operator=(const Department& b);
018:    Department(const Department& b);
019:    void print() const;
020: private:
021:    string name;
022:    Employee* receptionist;
023: };
024: 
025: /**
026:    Constructs a department with a given name and no receptionist.
027:    @param n the department name
028: */
029: Department::Department(string n)
030: {  name = n;
032:    receptionist = NULL;
034:    cout << "Constructor: ";
035:    print();
036: }
037: 
038: /**
039:    Constructs a department with a given name and receptionist.
040:    @param n the department name
041:    @param e the receptionist
042: */
043: Department::Department(string n, Employee e)
044: {  name = n;
046:    receptionist = new Employee(e.get_name(), e.get_salary());  
048:    cout << "Constructor: ";
049:    print();
050: }
051: 
052: /**
053:    Deletes the Employee object that this Department
054:    object manages.
055: */
056: Department::~Department()
057: {  cout << "Destructor: ";
059:    print();
061:    delete receptionist; 
062: } 063: 064: /** 065: Constructs a Department object as a copy of another 066: Department object. 067: @param b the object to copy 068: */ 069: Department::Department(const Department& b) 070: { cout << "Copy constructor: "; 072: b.print(); 073: 074: name = b.name; 075: if (b.receptionist == NULL) receptionist = NULL; 077: else 078: receptionist = new Employee(b.receptionist->get_name(), 079: b.receptionist->get_salary()); 080: } 081: 082: /** 083: Sets this Department object to a copy of another 084: Department object. 085: @param b the object to copy 086: */ 087: Department& Department::operator=(const Department& b) 088: { cout << "Assignment: "; 090: print(); 091: cout << "= "; 092: b.print(); 093: 094: if (this != & b) 095: { name = b.name; 097: delete receptionist; 098: if (b.receptionist == NULL) receptionist = NULL; 100: else 101: receptionist = new Employee(b.receptionist->get_name(), 102: b.receptionist->get_salary()); 103: } 104: return *this; 105: } 106: 107: /** 108: Prints a description of this department. 109: */ 110: void Department::print() const 111: { cout << "[name=" << name << ",receptionist="; 113: if (receptionist == NULL) cout << "NULL"; 115: else cout << receptionist->get_name(); 117: cout << "]\n"; 118: } 119: 120: int main() 121: { Department shipping("Shipping"); 123: Department qc("Quality Control",
124: Employee("Tester, Tina", 50000)); 125: Department dept(qc);
126: dept = shipping; 127: return 0; 128: }