Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab Assignment # 2 Consider the following structures and the main function shown below: finclude cstring.h ainclude estalio.hs sinclude cstdlib,hs typedef struct StringType & char

image text in transcribed
image text in transcribed
Lab Assignment \# 2 Consider the following structures and the main function shown below: finclude cstring.h ainclude estalio.hs sinclude cstdlib,hs typedef struct StringType \& char "string: lat length; \} StringType; typedef struct Employee \&. StringType "ealme; double salary; ) Employee: Employee* createEmployees(char names[][50], double *salaries, int empCount) \& 1 int main0 \{ const int EMPLOYEE_COUNT = 4; //array of employees' names char namelist[][50) = ("Bil", " Mary", "Kevin", "Denise"); //array of salaries, where 15.80 is the salary of 8 ill, 13.50 is II the salary of Mary, etc. double salaries []={15.80,13.5,20.9,12.99}} Imployee "pEmployees = createEmployees(nametht, salaries, EMPLOYEE_COUNT): // Print Employees int e=0; Employee "pEmployee = pEmployees: printt'ItEMPLOYEE NAMEUtUSALARY(n"); for (e-0jeoEMPLOYEE_COUNT;++e) f pEmployeett: 1 If Deallocate memory ptimployee * pfimployees; for (e=0;eef AAPLOVEE_COUNT; ++e) \& free(pEmployee->ename->string); pEmployee->ename->string = NULL; free(pEmployee->ename); pEmployee->ename = NULL; pEmployee++; \} free(pEmployees); pEmployees = NULL; return 0; Write a function createEmployees() that takes the list of employees' names, list of their salaries, and length of the list (empCount) as the parameters, and returns a pointer to a dynamically allocated array of Employee storing the relevant information for empCount employees. The function dynamically allocates memory for empCount number of employees and assigns the name and salaries for each of them from the input parameters. During this process, the names are stored in the dynamically allocated memory of StringType, and also make sure you assign the length of the name appropriately. Your code should use exact amount of memory needed to store the corresponding names. You may assume no name is longer than 49 characters. Employee* createEmployees(char names[][50], double *salaries, int empCount)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions