Answered step by step
Verified Expert Solution
Question
1 Approved Answer
code in c please Prelab: Week of February 24th For this week the goal is to get more familiar with the use of structs. We'll
code in c please
Prelab: Week of February 24th For this week the goal is to get more familiar with the use of structs. We'll assume the following Employee data type: typedef struct { int ID, jobType; float salary; } Employee; Now implement the following function: Employee * readEmployeeInfo (FILE *fp, int *numElems) which returns an array of Employee structs similarly to what you've done before where you can assume an integer at the beginning telling you how many records follow, which tells you how big the array needs to be. (You should feel free to eliminate the second parameter if you want to implement with a getSize function instead -- which would also allow a parameter to be eliminated from the following function.) Each record will consist of two integers and a float corresponding to the members of the Employee struct. This is just like the prelab for Lab 2 except that instead of creating an array of floats you'll be creating an array of Employee structs. Okay, so after readEmployeelnfo is called the user will have an array of Employee records. The following function is useful if the user wants to retrieve the record of a particular employee based on her/his employee ID: Employee * get EmployeeByID (Employee *, int numEmps, int ID) where the first two parameters are the array of employees and the number of employees, and the third parameter is the employee ID. The function returns a pointer to the record (i.e., address of an array element struct) for the employee with that ID. Note that this just requires a loop to find the employee with the specified ID. What do you do if there is no employee with that ID? Now you need to implement get and set interface functions: void setID (Employee *p, int id) int getID (Employee *p) void set Salary (Employee *p, float salary) etc. It's important to understand why such functions are needed: They ensure that users never have to directly access any member of the Employee struct. Suppose we did allow users to access the members directly, then what would happen to their programs if we later change the member "ID" to "employeeID Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started