Please use C++ struct Employee { char name[20]; int empID; double salary; }; A v
ID: 3835431 • Letter: P
Question
Please use C++
struct Employee
{
char name[20];
int empID;
double salary;
};
A variable of type Employee is then declared below.
Employee empArr[100];
Write a function called highestPay that takes an array of Employees like the one above and prints out the name of the employee with the highest salary. Write a fragment of code to call this function with the array empArr. Show the definition of the function and the function call assuming it is called from the main.
Is my answer below correct?
void highestPay(Employee arr)
{
double amount;
double highestAmount = 0.0;
for (int i = 0; i < 100; i++)
{
if (arr[i].salary > highestAmount)
{
amount = highestAmount;
}
}
for( int i = 0, int j = 0; i < 100, j < 20; i++, j++)
{
if (arr[i].salary == amount)
{
cout << arr[i].name[j];
}
}
}
Explanation / Answer
Dear Student,
Your code is not correct.
See below I have corrected the code.
--------------------------------------------------------------------------------------------------------------------------------------
void highestPay(struct Employee arr[])
{
double amount;
int j;
double highestAmount = arr[0].salary;
for (int i = 0; i < 100; i++)
{
if (arr[i].salary > highestAmount)
{
highestAmount = arr[i].salary;
j = i;
}
}
cout << "The name of the employee who is having highest amount of salary is: "<<arr[j].name<<endl;
}
Now you can easely find the mistakes in your code by comparing with my code.
-------------------------------------------------------------------------------------------------------------------------------------
Kindly Check and Verify Thanks...!!!