#include <iostream>
using namespace std;
class Staff {
private:
static int totalStaff; // Static member for overall staff count
int campusStaff; // Non-static member for campus-specific staff count
public:
// Constructor to update totalStaff and initialize campusStaff
Staff(int staffCount) {
campusStaff = staffCount;
totalStaff += staffCount;
// Static method to retrieve total staff count
static int getTotalStaff() {
return totalStaff;
// Method to retrieve campusStaff
int getCampusStaff() const {
return campusStaff;
// Destructor to update totalStaff upon object destruction
~Staff() {
totalStaff -= campusStaff;
}
};
// Initialize static member
int Staff::totalStaff = 0;
int main() {
// Create Staff objects for campuses
Staff campus1(100); // Campus 1 employs 100 people
Staff campus2(150); // Campus 2 employs 150 people
// Print staff counts
cout << "Total staff: " << Staff::getTotalStaff() << endl;
cout << "Campus 1 staff: " << [Link]() << endl;
cout << "Campus 2 staff: " << [Link]() << endl;
return 0;
Static Data Members:
1. totalStaffCount: Tracks the total number of staff members across all campuses.
2. campusStaffCount: A map that tracks the number of staff members per campus.
Non-Static Data Member:
1. campusName: Stores the campus name for each staff member.
Justification:
Since these variables are common to all instances of the Staff class, static data members are
utilized to track the overall staff count as well as campus-specific staff counts.
- Since every employee is linked to a certain school, the campus name is stored in a non-static
data member.
Effect on the Factors:
1. Uniformity across campuses: Static data members guarantee that the overall number of
employees and the number of employees on each campus are the same.
2. Memory Efficiency: All instances share static data members, which lowers memory use.
3. Encapsulation: The data is encapsulated and securely retrieved through the use of public static
getter methods and private static data members.
4. Flexibility: New campuses and employees may be added with ease thanks to the architecture.
Benefits:
1. Effective memory management
2. Scalability and ease of maintenance
3. Data that is consistent across all campuses
Drawbacks:
1. Limited ability to change members of static data
2. Possible problems with synchronization in situations with many threads
This approach effectively controls the number of active staff members across all campuses while
preserving consistency, memory efficiency, encapsulation, and flexibility by combining static
and non-static data members.