Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

home / study / engineering / computer science / questions and answers / design a

ID: 3692628 • Letter: H

Question

home / study / engineering / computer science / questions and answers / design and implement a c language program to help ...

Question

Edit question

Design and implement a C Language program to help a company manage its employee simplified human resources system. Your program should print a menu of choices with each choice handling a specific task.

The choices menu should be as follows:

1-Adding new employee: each employee can be added to the system by entering their identification number, department, and age, where id and age is an integer number, and department code is coded as a character.

Employee list should be maintained in an increasing order based on the employees’ id.

2-Finishing an employee services: when an employee finishes his services in the company, he should be removed from the list of current employees. You should request the id of employee to remove him from the list of current employees.

3-Transfer employee: an employee can change his current department to another department. You should request the id of employee to transfer him to the new department.

4-Print employee list: will print current employee list on console.

5-Store data: all current employees’ data should be stored in a data file named “EmpolyeesData.txt”.

6-Exit: terminate program.

The company has a Maximum employee capacity of 100 employees.

Your code should be modular. The main function should contain mostly function calls. Explore error handling places (e.g. file not found, employee id doesn’t exist in case of choice 2 and 3).

nter your 1Add new employee 2 · Finish an employee services 3. Transfer an employee 4Print empolyees data 5 · Store empolyees data 6. EXIT Enter employee ID, Dept, Age: 232 X 30 Enter your choice t 1 Add new employee 2 · Finish an employee services 3Transfer an employee 4.Print empolyees data 5 · Store empolyees data 6 . EXIT Enter employee ID, Dept, Age: 435 Y 35 Enter your choice 1 Add new employee 2 · Finish an employee services 3 Transfer an employee 4Print empolyees data 5 Store empolyees data 6 EXIT Enter employee ID, Dept, Age: 345 2 40 Enter your choice 1. Add new employee 2 · Finish an employee services 3 Transfer an employee 4Print empolyees data 5Store empolyees data 6. EXIT The Employees List Bmployee number Department character Employee age 435 345 232 35 40 30

Explanation / Answer

Ans;

#include<stdio.h>
#include<conio.h>
struct emp
{
int empno ;
char dept;
int age ;
} e[100] ;
int count = 0;
void addemployee(){
   if(count <=100){
printf(" Enter the employee ID, Dept, Age : ") ;
scanf("%d%c%d", &e[i].empno,&e[i].dept,&e[i].age);
count++;
   }else{
       printf("Sorry, it has capacity of 100 i.e exceeded now");
   }
  
}
void disemp(){
   int i=0;
   printf("--------------------------------------------------------------------");
       printf(" Employee List");
   printf("--------------------------------------------------------------------");
   printf(" Employee Number Department character Employee age ") ;
for(i<=count)
{
printf("%d %c %d ", e[i].empno,e[i].dept, e[i].age) ;
i++;
}
}
void transemp(int id,char d){
   i=0;
   while(i<= count){
       if(e[i].empno == id){
           e[i].dept = d;
           break;
       }
       i++;
   }
}
void deleteemp(int id){
   int i=0,j=0;
   emp et[100];
   while(i<=count)
{
if(e[i].empno!=id)
{
   et[i].empno = e[i].empno;
   et[i].dept = e[i].dept;
   et[i].age = e[i].age;
   j++;
}
i++;
}
count = j;
i =0;
while(i<=count)
{
   e[i].empno = et[i].empno;
   e[i].dept = et[i].dept;
   e[i].age = et[i].age;
   i++;
}
  
}
void storeData(){
   FILE *fp;
   fp = fopen("StoreData.txt", "w");
   while(i<=count){
   fwrite(e[i].empno, sizeof(e[i].empno), 1, fp);
fwrite(e[i].dept, sizeof(e[i].empdept), 1, fp);
fwrite(e[i].age, sizeof(e[i].age), 1, fp);
i++;
   }
   fclose(fp);
}
void main()
{
   int n;
   int id,d;
   printf("Enter your choices: ");
   printf("-----------------------------------------------------");
   printf("1. Add new employee ");
   printf("2. Finish an employee services ");
   printf("3. Transfer an employee ");
   printf("4. Print employee data ");
   printf("5. Store employee data ");
   printf("6. EXIT ");
printf("-----------------------------------------------------");
while(1){
   scanf("%d",&n);
switch(n){
   case 1: addemployee();break;
   case 2: printf("Enter the employee id to cancel his service");scanf("%d",&id);deleteemp(id);break;
   case 3: printf(" Enter the id number of transferred employee: ");
   scanf("%d",&id);printf(" Enter new Department code:");scanf("%d",&d);transemp(id,d)break;
   case 4: disemp();break;
   case 5: storeData();break;
   case 6: exit(-1);
}
}
getch() ;
}