using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace EmployeeManagement { public struct PerformanceLevel { // Private fields. private int numRankings; private int totalScore; // Helper functions. public PerformanceLevel(int numRankings = 1, int score = 0) { this.numRankings = numRankings; this.totalScore = score; } public override string ToString() { return string.Format("Rankings: {0}, Total: {1}, Effective Average: {2}", numRankings, totalScore, EffectiveAverageScore); } public int EffectiveAverageScore { get { return totalScore / numRankings; } } // Functions that are required if you override operator==. public override bool Equals(object obj) { // Try to convert other object to a PerformanceLevel type. PerformanceLevel? other = obj as PerformanceLevel?; if (other == null) { return false; } else { // Use operator== to determine if this object equals the other object. return this == other.Value; } } public override int GetHashCode() { // Return this object's average score as an effective hashcode. return EffectiveAverageScore; } // Operators. public static PerformanceLevel operator +(PerformanceLevel p1, int score) { return new PerformanceLevel(p1.numRankings + 1, p1.totalScore + score); } public static bool operator ==(PerformanceLevel p1, PerformanceLevel p2) { return p1.EffectiveAverageScore == p2.EffectiveAverageScore; } public static bool operator !=(PerformanceLevel p1, PerformanceLevel p2) { return p1.EffectiveAverageScore != p2.EffectiveAverageScore; } public static bool operator ==(PerformanceLevel p1, int otherScore) { return p1.EffectiveAverageScore == otherScore; } public static bool operator !=(PerformanceLevel p1, int otherScore) { return p1.EffectiveAverageScore != otherScore; } public static bool operator >(PerformanceLevel p1, PerformanceLevel p2) { return p1.EffectiveAverageScore > p2.EffectiveAverageScore; } public static bool operator <(PerformanceLevel p1, PerformanceLevel p2) { return p1.EffectiveAverageScore < p2.EffectiveAverageScore; } public static bool operator >(PerformanceLevel p1, int otherScore) { return p1.EffectiveAverageScore > otherScore; } public static bool operator <(PerformanceLevel p1, int otherScore) { return p1.EffectiveAverageScore < otherScore; } } }