Answer to Question #187954 in C# for abhi

Question #187954

Using Structures write an interactive program in C language to create an application program for a small office to maintain the employee’s database. This application should be having menu options like

• Creating a New Record

• Reading/Listing of Records

• Modify the record

• Delete the record

Each employee record should have Employee Name, Employee ID, Department Name, Salary, Position, Date of Joining, etc.). The application should be designed user-friendly.


1
Expert's answer
2021-05-01T14:36:30-0400
#include <stdio.h>
#include <string.h>


struct Employee{
	char Name[50];
	int ID;
	char DepartmentName[50];
	float Salary;
	char Position[50];
	char DateJoining[50];
};


int main(){
	struct Employee employees[100];
	int totalEmployees=0;
	struct Employee employee;
	int i;
	int indexSelectedEmployee;




	int ch=0;
	while(ch!=5){
		printf("1. Creating a New Record\n");
		printf("2. Reading/Listing of Records\n");
		printf("3. Modify the record\n");
		printf("4. Delete the record\n");
		printf("5. Exit\n");
		printf("Your choice: ");
		scanf("%d",&ch);
		if(ch==1){
			fflush(stdin);
			printf("Enter employee name: ");
			gets(employee.Name);
			printf("Enter employee ID: ");
			scanf("%d",&employee.ID);
			fflush(stdin);
			printf("Enter employee department name: ");
			gets(employee.DepartmentName);
			printf("Enter employee salary: ");
			scanf("%f",&employee.Salary);
			fflush(stdin);
			printf("Enter employee position: ");
			gets(employee.Position);
			printf("Enter employee date joining: ");
			gets(employee.DateJoining);
			employees[totalEmployees]=employee;
			totalEmployees++;
			printf("\nA new employee has been added.\n\n");
		}else if(ch==2){
			for(i=0;i<totalEmployees;i++){
				printf("Employee name: %s\n",employees[i].Name);
				printf("Employee ID: %d\n",employees[i].ID);
				printf("Employee department name: %s\n",employees[i].DepartmentName);
				printf("Employee salary: %.2f\n",employees[i].Salary);
				printf("Employee position: %s\n",employees[i].Position);
				printf("Employee date joining: %s\n\n",employees[i].DateJoining);
			}
		}else if(ch==3){
			indexSelectedEmployee=-1;
			printf("Enter employee ID: ");
			scanf("%d",&employee.ID);
			for(i=0;i<totalEmployees;i++){
				if(employee.ID==employees[i].ID){
					indexSelectedEmployee=i;
				}
			}
			if(indexSelectedEmployee!=-1){
				fflush(stdin);
				printf("Enter a new employee name: ");
				gets(employees[indexSelectedEmployee].Name);
				printf("Enter a new employee ID: ");
				scanf("%d",&employees[indexSelectedEmployee].ID);
				fflush(stdin);
				printf("Enter a new employee department name: ");
				gets(employees[indexSelectedEmployee].DepartmentName);
				printf("Enter a new employee salary: ");
				scanf("%f",&employees[indexSelectedEmployee].Salary);
				fflush(stdin);
				printf("Enter a new employee position: ");
				gets(employees[indexSelectedEmployee].Position);
				printf("Enter a new employee date joining: ");
				gets(employees[indexSelectedEmployee].DateJoining);
				printf("\nEmployee info has been updated.\n\n");
			}else{
				printf("\nEmployee ID does not exist.\n\n");
			}
		}else if(ch==4){
			indexSelectedEmployee=-1;
			printf("Enter employee ID: ");
			scanf("%d",&employee.ID);
			for(i=0;i<totalEmployees;i++){
				if(employee.ID==employees[i].ID){
					indexSelectedEmployee=i;
				}
			}
			if(indexSelectedEmployee!=-1){
				for(i=indexSelectedEmployee;i<totalEmployees-1;i++){
					employees[i]=employees[i+1];
				}	
				totalEmployees--;
				printf("\nEmployee info has been deleted.\n\n");
			}else{
				printf("\nEmployee ID does not exist.\n\n");
			}
		}else if(ch==5){


		}else{
			printf("\nWrong selection\n\n");
		}
	}
	getchar();
	getchar();
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS