home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / CL187A.ZIP / EXAMP302.CPP < prev    next >
C/C++ Source or Header  |  1994-03-15  |  2KB  |  75 lines

  1. // Container Lite (CL v 1.87a)
  2. // (C) Copyright John Webster Small 1994
  3. // All rights reserved
  4. // examp302.cpp -- link with cl.obj
  5. // rework of examp205.cpp
  6.  
  7. // #define CL_NO_TEMPLATES
  8.  
  9. #include "cl.h"
  10.  
  11. class Employee  {
  12.     char name[20];
  13.     unsigned salary;
  14.     static    Employee * THIS;
  15.     static    ostream& SHOW(ostream& os)
  16.     {
  17.        return os << "Employee name: "
  18.           << setw(20)
  19.           << (THIS->name? THIS->name : "n/a")
  20.           << "\tsalary: " << THIS->salary;
  21.     }
  22. public:
  23.     Employee(const char * name = 0,
  24.         unsigned salary = 0)
  25.     {
  26.         if (name)
  27.             strncpy(this->name,name,
  28.                 sizeof(Employee::name));
  29.         else
  30.             this->name[0] = '\0';
  31.         this->salary = salary;
  32.     }
  33.     ostream& (*show())(ostream&)
  34.         { THIS = this; return SHOW; }
  35. };
  36.  
  37. Employee * Employee::THIS;
  38.  
  39. #define EmployeeFile "employs.tmp"
  40.  
  41. #ifdef CL_NO_TEMPLATES
  42.     #define ITEM Employee
  43.     #define CL_CMP_BYTES
  44.     #define CL_ASSIGN_BYTES
  45.     #define CL_CLONE_BYTES
  46.     #define CL_STRM_BYTES
  47.     #define CL CL_Employee
  48.     #include "cl.hf"
  49. #else
  50.     CL_CMP_BYTES(Employee)
  51.     CL_ASSIGN_BYTES(Employee)
  52.     CL_CLONE_BYTES(Employee)
  53.     CL_STRM_BYTES(Employee)
  54.     #define CL_Employee CL<Employee>
  55. #endif
  56.  
  57.  
  58. main()
  59. {
  60.     CL_Employee cE(CL_ANDS);
  61.     cE.ins(new Employee("Doe, John",1000));
  62.     Employee E("Small, John",100);
  63.     cE.insQNew(&E);
  64.     cE.push(new Employee("Morgan, Maria",10000));
  65.     cE.save(EmployeeFile);
  66.     cE.allClr();
  67.     cE.load(EmployeeFile);
  68.     cE.sort();
  69.     cout << "\nEmployees in alphabetical order: "
  70.         << endl;
  71.     while (cE.nextAsg(&E))
  72.         cout << E.show() << endl;
  73.     return 0;
  74. }
  75.