Skip to main content

Featured

C++ Program to Perform Linear Search on a Vector

  C++ Program to Perform Linear Search on a Vector Introduction In this C++ program, we will learn how to perform a Linear Search on a vector. The program first takes the size of the vector and its elements as input. Then it asks the user for the element to search. If the element is found, it displays the index where it is located. Otherwise, it displays a message indicating that the element is not found. C++ Program #include<bits/stdc++.h> using namespace std; int main() { int num, search, found = 0; cout << "Enter the size of the vector:" << endl; cin >> num; vector<int> v(num); cout << "Enter " << num << " elements in vector:" << endl; for(int i = 0; i < num; i++) { cin >> v[i]; } cout << "Enter element that you want to search:" << endl; cin >> search; for(int i = 0; i < num; i++) { ...

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

🌙