Change the value of SIZE to 4.
- Expand the menu list (printing) to include options 3 & 4 after option 2 with the following
o Update Employee Salary
o Remove Employee
- Create two switch-cases for option 3 & 4 after case 2. Do not forget to include break; statements at the end of each case.
IMPLEMENT UPDATE EMPLOYEE DATA FUNCTIONALITY IN CASE 3
• Display the following initially
> Update Employee Salary < > ====================== <
• Prompt the user for the employee identification number using a do-while loop. While the number is not found in the employee array, keep prompting the user.
• Once the number is found, display the current salary for the employee with that identification number and prompt the user to input the new salary. Replace the old salary with the input value.
Case 4:
• Copy and paste from case 3 the do-while loop that prompts the user for the employee identification number.
• Once the number is found, display the following message and change the employee identification number to indicate an empty slot.
> Employee [REPLACE WITH EMP ID] will be removed <
• Decrement the valid employee count by one
• DO NOT REORDER the items in the array!
Code:
// Workshop <Workshop 4>
// Name: <JAYA SUMANTH YELAMANCHILI>
// Email: [email protected]
// Student #: <150249183>
// Course: IPC144 Winter 2019
// File: <W5_HOME>
#define _CRT_SECURE_NO_WARNINGS
#define SIZE 4
#include <stdio.h>
struct Employee
{
int id;
int age;
double salary;
};
int main(void)
{
int option,flag=0;
int i = 0, j = 0;
int limit = 0;
int idsearch = 0;
int idsave = 0;
int count = 0;
struct Employee emp[SIZE] = { 0,0,0.0 };
printf("---=== EMPLOYEE DATA ===---\n\n");
do {
printf("1. Display Employee Information\n");
printf("2. Add Employee\n");
printf("3. Update Employee Salary\n");
printf("4. Remove Employee\n");
printf("0. Exit\n\n");
printf("Please select from the above options: ");
scanf("%d", &option);
printf("\n");
switch (option)
{
case 0:
printf("Exiting Employee Data Program. Good Bye!!! ");
break;
case 1:
printf("EMP ID EMP AGE EMP SALARY\n");
printf("====== ======= ==========\n");
for (i = 0;i < SIZE;i++)
{
if (emp[i].id > 0)
printf(" % 6d % 9d% 11.2lf", emp[i].id, emp[i].age, emp[i].salary);
printf("\n");
}
printf("\n");
break;
case 2:
printf("Adding Employee\n");
printf("===============\n");
if (limit < SIZE)
{
printf("Enter Employee ID: ");
scanf("%d", &emp[limit].id);
printf("Enter Employee Age : ");
scanf("%d", &emp[limit].age);
printf("Enter Employee Salary : ");
scanf("%lf", &emp[limit].salary);
limit++;
}
else if (flag==idsave)
{
printf("Enter Employee ID: ");
scanf("%d", &emp[flag].id);
printf("Enter Employee Age : ");
scanf("%d", &emp[flag].age);
printf("Enter Employee Salary : ");
scanf("%lf", &emp[flag].salary);
limit++;
}
else
printf(" ERROR!!! Maximum Number of Employees Reached \n");
printf("\n");
break;
case 3:
printf("Update Employee Salary\n");
printf("======================\n");
do
{
count = 1;
printf("Enter Employee ID: ");
scanf("%d", &idsearch);
for (i = 0;i < limit;i++)
{
if (emp[i].id == idsearch)break;
else if (i == limit - 1)
{
printf("*** ERROR: Employee ID not found!***\n");
}
}
if (i != limit)
{
printf("The current salary is %.2f\n", emp[i].salary);
printf("Enter Employee New Salary: ");
scanf("%lf", &emp[i].salary);
printf("\n");
count = 0;
}
} while (count);
break;
case 4:
printf("Remove Employee\n");
printf("===============\n");
do
{
count = 1;
printf("Enter Employee ID: ");
scanf("%d", &idsearch);
for (i = 0;i < limit;i++)
{
if (emp[i].id==idsearch)
{
break;
}
else if (i == limit - 1)
{
printf("*** ERROR: Employee ID not found!***\n");
}
}
if (i != limit)
{
count = 0;
idsave = i;
printf("Employee %d will be removed\n\n", emp[idsave].id);
flag = idsave;
for (i = idsave;i < limit;i++)
{
if (i != limit - 1)
{
emp[i] = emp[i+1];
}
else
{
emp[i].id = -1;
}
}
limit -= 1;
}
} while (count);
break;
default:
printf("ERROR: Incorrect Option: Try Again\n\n");
}
} while (option != 0);
}