C Examples

WAP in C to Develop a Database software for Company!

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.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X