Skip to main content

Featured

Merge Sort in C++

  Merge Sort in C++ Introduction Merge Sort is a popular sorting algorithm that follows the Divide and Conquer approach. It divides an array into smaller subarrays, recursively sorts those subarrays, and finally merges the sorted subarrays to produce a completely sorted array. In this tutorial, we will learn how to implement Merge Sort in C++ . The program divides the array into two halves using the mid index, recursively sorts both halves, and then combines them using the merge() function. Merge Sort has a time complexity of O(n log n) in the best, average, and worst cases. Table of Contents Algorithm C++ Program Input Sample Output Output Explanation Dry Run Flow of Execution Time Complexity Space Complexity Applications Key Points Interview Questions Frequently Asked Questions Keywords Conclusion Algorithm Start the program. Read the size of the array. Read the array elements from the user. Call the mer...

Employee Record System in c

 





Program

//=================================
#include<stdio.h>
#include<string.h>
struct employe
{
    char name[100];
    char mob[15];
    char gmail[100];
    float salary;
    char place[100];

};
void addemploy( struct employe e[],int *e_count)
{
    int i=*e_count;
    printf("Enter the name of the employe name:\n");
    scanf(" %[^\n]",e[i].name);


    while(1)
    {
    int valid=1;
    printf("Enter mobile number:\n");
    scanf(" %[^\n]",e[i].mob);
    for(int j=0;j<strlen(e[i].mob);j++)
    {
        if(e[i].mob[j]<'0'|| e[i].mob[j]>'9')// Check if character is not a digit
        {
            valid=0;
            break;
        }
    }
    if(valid && strlen(e[i].mob)==10)
    {
        break;
    }
    else
        {
            printf("Invalid mobile number! Please enter a 10-digit number containing only digits.\n");
        }

    }



   while(1)
   {

       int  duplecate=0,valid=1;

    printf("Enter gmail:\n");
    scanf(" %[^\n]",e[i].gmail);

   char *gmail=strstr(e[i].gmail,"@gmail.com");
   char *outlook=strstr(e[i].gmail,"@outlook.com");
   if(!(gmail&&strcmp(gmail,"@gmail.com")==0)&&(!(outlook&&strcmp(outlook,"@outlook.com")==0)))
    //if (!(gmail && strcmp(gmail, "@gmail.com") == 0) &&!(outlook && strcmp(outlook, "@outlook.com") == 0))
   {
       valid =0;

   }
   for(int j=0;j<*e_count;j++)
   {
       if(strcmp(e[i].gmail,e[j].gmail)==0)
       {
         duplecate=1;
         break;
       }
   }

   if(valid && ! duplecate)
   {
       break;
   }
   else if(!valid)
   {
        printf("Invalid email! Please enter a valid email ending with @gmail.com or @outlook.com.\n");
   }
   else if ( duplecate)
        {
            printf("This email already exists! Please enter a unique email.\n");
        }
 }


    printf("Enter salary:\n");
    scanf("%f",&e[i].salary);
    printf("Enter place:\n");
    scanf(" %[^\n]",e[i].place);
    (*e_count)++;
    printf("Employe Details Added successfully:\n");
}
void display( struct employe e[],int *e_count)
{
if(*e_count==0)
{
    printf("No employe details to display:\n");
}

      int i=*e_count;
      for(int i=0;i<*e_count;i++)
      {
     printf("===Employe details:===\n");
     printf("====================================\n");
     printf("Name:%s\n",e[i].name);
     printf("mobile number:%s\n",e[i].mob);
     printf("Gmail:%s\n",e[i].gmail);
     printf("salary:%f\n",e[i].salary);
     printf("place:%s\n",e[i].place);
     printf("===================================\n");
      }


}
void search( struct employe e[],int *e_count)
{

    if (*e_count == 0)
    {
        printf("No employees to search!\n");
        return;
    }
    int found=0;
    char gmail1[100];
    printf("Enter Gmail to search Employ:\n");
    scanf(" %[^\n]",gmail1);
    for(int i=0;i<*e_count;i++)
    {
    if(strcmp(e[i].gmail,gmail1)==0)
    {
    found=1;
    printf("===Employ found \xF0\x9F\x98\x8A\n===\n");
    printf("Name:%s \n",e[i].name);
     printf("mobile number:%s \n",e[i].mob);
     printf("Gmail:%s \n",e[i].gmail);
    printf("salary:%f \n",e[i].salary);
    printf("place:%s \n",e[i].place);
    break;

    }

}
     if(!found)
    {
      printf("Contact not found!\n");
    }
}
void edit(struct employe e[],int *e_count)
{
if(*e_count==0)
{
    printf("No contact details are available to edit.\n");
    return;
}

int choice,found=0,record=0;
int i=*e_count;
char gmail1[100];

printf("Enter the Gmail of the employee you want to edit:\n");
scanf(" %[^\n]",gmail1);
for(int i=0;i<*e_count;i++)
{
    if(strcmp(e[i].gmail,gmail1)==0)
    {
        found=1;
        record=i;
     printf("===Employ found \xF0\x9F\x98\x8A\n===\n");
     printf("===\u2705Current Details:\u2705===");
     printf("Name:%s \n",e[i].name);
     printf("mobile number:%s \n",e[i].mob);
     printf("Gmail:%s \n",e[i].gmail);
     printf("salary:%f \n",e[i].salary);
     printf("place:%s \n",e[i].place);

     printf("===which details you want update===");
     printf("1.Name:\n 2.Mobile NO:\n 3.Gmail\n 4.Salary:\n 5.Place:\n");
     printf("Enter your choice:\n");
     scanf("%d",&choice);

     switch(choice)
     {
     case 1:
        printf("Enter new name:\n");
        scanf(" %[^\n]",e[i].name);
        break;
        case 2:
        printf("Enter new mobile number:\n");
        scanf(" %[^\n]",e[i].mob);
         break;
        case 3:
            printf("Enter new Gmail:\n");
            scanf(" %[^\n]",e[i].gmail);
             break;
        case 4:
            printf("Enter new salary:\n");
            scanf(" %[^\n]",e[i].salary);
             break;
        case 5:
            printf("Enter new place:\n");
            scanf(" %[^\n]",e[i].place);
             break;
        default:
            printf("Invalid choice!!\n");

     }
     printf("Employ new details updated successfully:\n");
    }

}
if(!found)
{
  printf("No details are found!\n");
}


}

void trash(struct employe e[],int *e_count)
{
    if(*e_count==0)
    {
        printf("No contacts are found to delete\n");
        return;
    }
    char gmail1[100];
    int found=0;
    printf("Enter Gmail of the employe\n");
    scanf(" %[^\n]",gmail1);
    for(int i=0;i<*e_count;i++)
    {
        if(strcmp(e[i].gmail,gmail1)==0)
        {
         found=1;
         for(int j=i;j<*e_count-1;j++)
         {
             e[j]=e[j+1];
         }
         (*e_count)--;
         printf("Employe details are delated succesfully:\n");

        }
    }
    if(!found)
    {
        printf("Employe not found:\n");
    }
}
int main( )
{

    struct employe e[30];
    int choice,e_count=0;
    while(1)
    {


    printf("===Employes management system===\n\n");
    printf("1.Add Employ Details:\n");
    printf("2.Display Employ Details:\n");
    printf("3.Search Employ Details:\n");
    printf("4.Update Employ Details:\n");
    printf("5.Delete Employ Details:\n");
    printf("6.Exit:\n");
    printf("Enter Choice:\n");
    scanf(" %d",&choice);

    switch (choice)
    {
        case 1:addemploy(e,&e_count);
        break;
        case 2:display(e,&e_count);
        break;
        case 3:search(e,&e_count);
        break;
        case 4:edit(e,&e_count);
        break;
        case 5:trash(e,&e_count);
        break;
        case 6:
            printf("Exicting the program !thank you for using employe management system:\n");
           // exit(0);
            break;

        default:
        printf("Invalid choice:\n");
    }

       char choice;

        printf("Do you want to continue(y/n):\n");

        scanf(" %c",&choice);


     if (choice == 'y' || choice == 'Y')
    {
    choice = 1;
    }
    else
    {
     choice = 0;
    }




    }



}
//===============================================

Comments

Popular Posts

🌙