Untitled
unknown
plain_text
a year ago
1.4 kB
4
Indexable
Never
#include <string> #include <iostream> using namespace std; struct Employee { string name; int accessLevel; double salary; int contractDuration; }; int main() { int N; N = 3; Employee* employees = new Employee[N]; employees[0].name = "John"; employees[0].accessLevel = 7; employees[0].salary = 4000.0; employees[0].contractDuration = 12; employees[1].name = "Mary"; employees[1].accessLevel = 8; employees[1].salary = 4500.0; employees[1].contractDuration = 24; employees[2].name = "Bob"; employees[2].accessLevel = 9; employees[2].salary = 5000.0; employees[2].contractDuration = 6; int maxAccessLevel = 0; double maxSalary = 0.0; string maxName; int counter = 0; for (int i = 0; i < N; i++) { if (employees[i].accessLevel > maxAccessLevel) { maxAccessLevel = employees[i].accessLevel; maxName = employees[i].name; maxSalary = employees[i].salary; } else if (employees[i].accessLevel == maxAccessLevel ) { counter++; } } if (counter > 0) { maxSalary = 0; for (int i = 0; i < N; i++) { if (employees[i].salary > maxSalary) { maxName = employees[i].name; } } } cout << "Employee with maximum access level or maximum salary: " << maxName << endl; }