0% found this document useful (0 votes)
2 views3 pages

Staff Management with Static Members

The document describes a C++ class 'Staff' that manages staff counts across multiple campuses using static and non-static data members. It highlights the benefits of using static members for overall staff tracking, such as memory efficiency and data consistency, while also addressing potential drawbacks like limited mutability and synchronization issues. The implementation allows for easy addition of new campuses and staff while maintaining encapsulation and flexibility.

Uploaded by

umershahid164
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Staff Management with Static Members

The document describes a C++ class 'Staff' that manages staff counts across multiple campuses using static and non-static data members. It highlights the benefits of using static members for overall staff tracking, such as memory efficiency and data consistency, while also addressing potential drawbacks like limited mutability and synchronization issues. The implementation allows for easy addition of new campuses and staff while maintaining encapsulation and flexibility.

Uploaded by

umershahid164
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#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.

You might also like