The Program in C to Develop a Database software for Company is given below:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_EMPLOYEES 100
struct Employee {
int id;
char name[50];
int age;
char department[50];
float salary;
};
int employeeCount = 0;
struct Employee employees[MAX_EMPLOYEES];
void addEmployee(int id, char name[], int age, char department[], float salary) {
if (employeeCount < MAX_EMPLOYEES) {
employees[employeeCount].id = id;
strcpy(employees[employeeCount].name, name);
employees[employeeCount].age = age;
strcpy(employees[employeeCount].department, department);
employees[employeeCount].salary = salary;
employeeCount++;
} else {
printf("Error: Unable to add employee. Maximum number of employees reached.\n");
}
}
void listEmployees() {
int i;
for (i = 0; i < employeeCount; i++) {
printf("Employee ID: %d\n", employees[i].id);
printf("Name: %s\n", employees[i].name);
printf("Age: %d\n", employees[i].age);
printf("Department: %s\n", employees[i].department);
printf("Salary: $%.2f\n", employees[i].salary);
printf("\n");
}
}
int main() {
addEmployee(1, "John Doe", 30, "IT", 50000.00);
addEmployee(2, "Jane Smith", 25, "Marketing", 45000.00);
addEmployee(3, "Bob Johnson", 35, "HR", 55000.00);
listEmployees();
return 0;
}
Output:
Employee ID: 1
Name: John Doe
Age: 30
Department: IT
Salary: $50000.00
Employee ID: 2
Name: Jane Smith
Age: 25
Department: Marketing
Salary: $45000.00
Employee ID: 3
Name: Bob Johnson
Age: 35
Department: HR
Salary: $55000.00
Pro-Tips💡
‘addEmployee'
function accepts the employee information as arguments (id, name, age, department, and salary) instead of reading them from the user input.
The ‘main'
function uses the 'addEmployee'
function to add three employees to the database with predefined values.
The ‘listEmployees
‘ function is used to display the information of all employees in the database
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.