Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.61 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdlib>
  4. #include<iomanip>
  5. #include<windows.h>
  6. //#include <ctime>
  7. //#include <dos.h>
  8. #include<dos.h>
  9. #include<conio.h>
  10. #include<cstdio>
  11. #define max 20
  12. using namespace std;
  13.  
  14. struct employee
  15. {
  16.  char name[20];
  17.  long int code;
  18.  char designation[20];
  19.  int exp;
  20.  int age;
  21. };
  22. int num;
  23. employee emp[max],tempemp[max],sortemp[max],sortemp1[max];
  24. int main()
  25. {
  26.  system("cls"); //clears screen using windows command cls
  27.  void build();
  28.  void list();
  29.  void insert();
  30.  void deletes();
  31.  void edit();
  32.  void search();
  33.  void sort();
  34.  char option;
  35.  void menu();
  36.  menu();
  37.  while((option=cin.get())!='q')
  38.  {
  39.   switch(option)
  40.   {
  41.    case 'b':
  42.              build();
  43.              break;
  44.    case 'l':
  45.              list();
  46.              break;
  47.    case 'i':
  48.              insert();
  49.              break;
  50.    case 'd':
  51.              deletes();
  52.              break;
  53.    case 'e':
  54.            edit();
  55.             break;
  56.    case 's':
  57.             search();
  58.             break;
  59.    case 'n':
  60.              sort();
  61.              break;
  62.   }
  63.    menu();
  64.   }
  65.   return 0;
  66.  }
  67.  void menu()
  68.  {
  69.   system("cls");
  70.  // highvideo();
  71. cout<<"           ";
  72. printf("\n*****  Employees Management System 1.0 ***** ");
  73.  
  74.  
  75. //normvideo();
  76. cout<<endl;
  77. cout<<"              ";
  78. cout<<"\n\t\t Press  b---->Built The Employee Table ";
  79. cout<<"              ";
  80. cout<<"\n\t\t Press  l---->List The Employee Table  ";
  81. cout<<"              ";
  82. cout<<"\n\t\t Press  i---->Insert New Entry        ";
  83. cout<<"              ";
  84. cout<<"\n\t\t Press  d---->Delete An Entry         ";
  85. cout<<"              ";
  86. cout<<"\n\t\t Press  e---->Edit An Entry           ";
  87. cout<<"              ";
  88. cout<<"\n\t\t Press  s---->Search Arecord          ";
  89. cout<<"              ";
  90. cout<<"\n\t\t Press  n---->Sort The Table          ";
  91. cout<<"              ";
  92. cout<<"\n\t\t Press  q---------->Quit Program              ";
  93. cout<<"              ";
  94. cout<<"\n\n \t\t Select Your Option Please ====> ";
  95. }
  96.  
  97. void build()
  98. {
  99.  
  100.  system("cls");
  101. // highvideo();
  102.  printf("Build The Table");
  103.  cout<<endl;
  104.  //normvideo();
  105.  cout<<"maximum number of entries  -----  >  20"<<endl;
  106.  cout<<"how many do you want    ----->";
  107.  cin>>num;
  108.  cout<<"Enter The Following Items"<<endl;
  109.  for(int i=0;i<=num-1;i++)
  110.  {
  111.   cout<<" Name  ";
  112.   cin>>emp[i].name;
  113.   cout<<"Code   ";
  114.   cin>>emp[i].code;
  115.   cout<<"Designation    ";
  116.   cin>>emp[i].designation;
  117.   cout<<"Years of Experience    ";
  118.   cin>>emp[i].exp;
  119.   cout<<"Age    ";
  120.   cin>>emp[i].age;
  121.  }
  122.   cout<<"going to main menu";
  123.  Sleep(500);
  124. }
  125.  
  126. void  list()
  127. {
  128.  system("cls");
  129. // highvideo();
  130.  printf("       ********List The Table********");
  131.  cout<<endl;
  132.  //normvideo();
  133.  cout<<"     Name        Code        Designation         Years(EXP)      Age "<<endl;
  134.  cout<<"    ------------------------------------------------------"<<endl;
  135.  for(int i=0;i<=num-1;i++)
  136.  {
  137.   cout<<setw(13)<<emp[i].name;
  138.   cout<<setw(6)<<emp[i].code;
  139.   cout<<setw(15)<<emp[i].designation;
  140.   cout<<setw(10)<<emp[i].exp;
  141.   cout<<setw(15)<<emp[i].age;
  142.   cout<<endl;
  143.  }
  144.   cout<<"going to main menu";
  145.  getch();
  146.   }
  147.   void insert()
  148.   {
  149.   system("cls");
  150.   int i=num;
  151.   num+=1;
  152.  // highvideo();
  153.   printf("Insert New Record");
  154.   cout<<endl;
  155.   //normvideo();
  156.   cout<<"Enter The Following Items"<<endl;
  157.   cout<<"Name   ";
  158.   cin>>emp[i].name;
  159.   cout<<"Code   ";
  160.   cin>>emp[i].code;
  161.   cout<<"Designation    ";
  162.   cin>>emp[i].designation;
  163.   cout<<"Years of Experience    ";
  164.   cin>>emp[i].exp;
  165.   cout<<"Age    ";
  166.   cin>>emp[i].age;
  167.   cout<<endl<<endl;
  168.   cout<<"going to main menu";
  169.  Sleep(500);
  170.  
  171.   }
  172.  
  173.  
  174.   void deletes()
  175.   {
  176.    system("cls");
  177.   // highvideo();
  178.    int code;
  179.    int check;
  180.    printf("Delete An Entry");
  181.    //normvideo();
  182.    cout<<endl;
  183.    cout<<"Enter An JobCode To Delete That Entry ";
  184.    cin>>code;
  185.    int i;
  186.    for(i=0;i<=num-1;i++)
  187.    {
  188.     if(emp[i].code==code)
  189.     {
  190.       check=i;
  191.     }
  192.    }
  193.    for(i=0;i<=num-1;i++)
  194.    {
  195.     if(i==check)
  196.     {
  197.     continue;
  198.     }
  199.     else
  200.     {
  201.     if(i>check)
  202.     {
  203.      tempemp[i-1]=emp[i];
  204.     }
  205.     else
  206.     {
  207.      tempemp[i]=emp[i];
  208.     }
  209.      }
  210.    }
  211.   num--;
  212.  
  213.   for(i=0;i<=num-1;i++)
  214.   {
  215.    emp[i]=tempemp[i];
  216.   }
  217.  }
  218.  
  219. void edit()
  220. {
  221.  system("cls");
  222.  int jobcode;
  223. // highvideo();
  224.  printf("          Edit An Entry           ");
  225.  cout<<endl;
  226.  cout<<endl;
  227.  int i;
  228.  void editmenu();
  229.  void editname(int);
  230.  void editcode(int);
  231.  void editdes(int);
  232.  void editexp(int);
  233.  void editage(int);
  234.  char option;
  235.  //normvideo();
  236.  cout<<"Enter An jobcode To Edit An Entry----   ";
  237.  cin>>jobcode;
  238.   editmenu();
  239.  for(i=0;i<=num-1;i++)
  240.    {
  241.     if(emp[i].code==jobcode)
  242.     {
  243.  
  244. while((option=cin.get())!='q')
  245. {
  246.       switch(option)
  247.       {
  248.        case 'n':
  249.                    editname(i);
  250.                    break;
  251.        case 'c':
  252.                    editcode(i);
  253.                    break;
  254.        case 'd':
  255.                    editdes(i);
  256.                    break;
  257.        case 'e':
  258.                    editexp(i);
  259.                    break;
  260.        case 'a':
  261.                   editage(i);
  262.                   break;
  263.      }
  264.    editmenu();
  265.     }
  266.   }
  267.   }
  268.   }
  269.   void editmenu()
  270.   {
  271.    system("cls");
  272.    cout<<"           What Do You Want To edit";
  273.    cout<<"               n--------->Name ";
  274.    cout<<"               c--------->Code ";
  275.    cout<<"               d--------->Designation";
  276.    cout<<"               e--------->Experience ";
  277.    cout<<"               a--------->Age        ";
  278.    cout<<"              q----->QUIT                            ";
  279.    cout<<"   Options Please ---->>> ";
  280.   }
  281.   void editname(int i)
  282.   {
  283.      cout<<"Enter New Name----->    ";
  284.      cin>>emp[i].name;
  285.   }
  286.   void editcode(int i)
  287.   {
  288.    cout<<"Enter New Job Code----->  ";
  289.    cin>>emp[i].code;
  290.   }
  291.   void editdes(int i)
  292.   {
  293.    cout<<"enter new designation----->   ";
  294.    cin>>emp[i].designation;
  295.   }
  296.   void editexp(int i)
  297.   {
  298.    cout<<"Enter new Years of Experience";
  299.    cin>>emp[i].exp;
  300.   }
  301.   void editage(int i)
  302.   {
  303.    cout<<"Enter new Age ";
  304.    cin>>emp[i].age;
  305.   }
  306.  
  307. void search()
  308. {
  309.  system("cls");
  310.  // highvideo();
  311.   printf("Welcome To Search Of Employee Database ");
  312.   //normvideo();
  313.   cout<<endl;
  314.   cout<<endl;
  315.   int jobcode;
  316.   cout<<"You Can Search Only By Jobcode Of An Employee";
  317.   cout<<"Enter Code Of An Employee                    ";
  318.  cin>>jobcode;
  319.  for(int i=0;i<=num-1;i++)
  320.    {
  321.     if(emp[i].code==jobcode)
  322.     {
  323.  
  324.     cout<<"     Name         Code        Designation         Years(EXP)      Age ";
  325.  cout<<"     ------------------------------------------------------                                  ";
  326.   cout<<setw(13)<<emp[i].name;
  327.   cout<<setw(6)<<emp[i].code;
  328.   cout<<setw(15)<<emp[i].designation;
  329.   cout<<setw(10)<<emp[i].exp;
  330.   cout<<setw(15)<<emp[i].age;
  331.   cout<<endl;
  332.  }
  333.  
  334.   }
  335.     cout<<"going to main menu";
  336.  getch();
  337.  
  338.  
  339. }
  340.  
  341. void sort()
  342. {
  343.  system("cls");
  344. // highvideo();
  345.  printf("Sort The Databse By JobCode");
  346.  //normvideo();
  347.  void sortmenu();
  348.  void sortname();
  349.  void sortcode();
  350.  void sortdes();
  351.  void sortexp();
  352.  char option;
  353.  void sortage();
  354.  
  355.  cout<<endl;
  356.  cout<<endl;
  357.  sortmenu();
  358.  while((option=cin.get())!='q')
  359.  {
  360.   switch(option)
  361.   {
  362.    case 'n':
  363.                  sortname();
  364.                  break;
  365.    case 'c':
  366.                  sortcode();
  367.                  break;
  368.    case 'd':
  369.                  sortdes();
  370.                  break;
  371.    case 'e':
  372.                  sortexp();
  373.                  break;
  374.    case 'a':
  375.                  sortage();
  376.                  break;
  377.    }
  378.    sortmenu();
  379.   }
  380.  }
  381.  
  382.  
  383.  void sortmenu()
  384.  {
  385.     system("cls");
  386.    cout<<"               What Do You Want To edit";
  387.    cout<<"               n--------->Name         ";
  388.    cout<<"               c--------->Code         ";
  389.    cout<<"               d--------->Designation  ";
  390.    cout<<"               e--------->Experience   ";
  391.    cout<<"               a--------->Age          ";
  392.    cout<<"                               q----->QUIT            ";
  393.    cout<<"   Options Please ---->>> ";  }
  394.  
  395.  
  396.  
  397. void sortname()
  398. {
  399.  system("cls");
  400.  int i,j;
  401.  struct employee temp[max];
  402.  for(i=0;i<=num-1;i++)
  403.  {
  404.   sortemp1[i]=emp[i];
  405.  }
  406.  for(i=0;i<=num-1;i++)
  407.   {
  408.    for(j=0;j<=num-1;j++)
  409.    {
  410.     if(strcmp(sortemp1[i].name,sortemp1[j].name)<=0)
  411.     {
  412.      temp[i]=sortemp1[i];
  413.      sortemp1[i]=sortemp1[j];
  414.      sortemp1[j]=temp[i];
  415.     }
  416.    }
  417.  }
  418.  
  419.  for( i=0;i<=num-1;i++)
  420.    {
  421.  
  422.     cout<<"     Name         Code        Designation         Years(EXP)      Age ";
  423.  cout<<"     ------------------------------------------------------                                  ";
  424.  for( i=0;i<=num-1;i++)
  425.  {
  426.   cout<<setw(13)<<sortemp1[i].name;
  427.   cout<<setw(6)<<sortemp1[i].code;
  428.   cout<<setw(15)<<sortemp1[i].designation;
  429.   cout<<setw(10)<<sortemp1[i].exp;
  430.   cout<<setw(15)<<sortemp1[i].age;
  431.   cout<<endl;
  432.  }
  433.   cout<<"Press Any Key To Go Back";
  434.  getch();
  435.  
  436. } }
  437.  
  438. void sortcode()
  439. {
  440.  system("cls");
  441.  int i,j;
  442.  struct employee temp[max];
  443.  for(i=0;i<=num-1;i++)
  444.  {
  445.   sortemp1[i]=emp[i];
  446.  }
  447.  for(i=0;i<=num-1;i++)
  448.   {
  449.    for(j=0;j<=num-1;j++)
  450.    {
  451.     if(sortemp1[i].code<sortemp1[j].code)
  452.     {
  453.      temp[i]=sortemp1[i];
  454.      sortemp1[i]=sortemp1[j];
  455.      sortemp1[j]=temp[i];
  456.     }
  457.    }
  458.  }
  459.  
  460.  for( i=0;i<=num-1;i++)
  461.    {
  462.  
  463.     cout<<"     Name         Code        Designation         Years(EXP)      Age ";
  464.  cout<<"     ------------------------------------------------------                                  ";
  465.  for( i=0;i<=num-1;i++)
  466.  {
  467.   cout<<setw(13)<<sortemp1[i].name;
  468.   cout<<setw(6)<<sortemp1[i].code;
  469.   cout<<setw(15)<<sortemp1[i].designation;
  470.   cout<<setw(10)<<sortemp1[i].exp;
  471.   cout<<setw(15)<<sortemp1[i].age;
  472.   cout<<endl;
  473.  }
  474.   cout<<"Press Any Key To Go Back";
  475.  getch();
  476.  
  477. } }
  478.  
  479.  
  480. void sortdes()
  481. {
  482.  system("cls");
  483.  int i,j;
  484.  struct employee temp[max];
  485.  for(i=0;i<=num-1;i++)
  486.  {
  487.   sortemp1[i]=emp[i];
  488.  }
  489.  for(i=0;i<=num-1;i++)
  490.   {
  491.    for(j=0;j<=num-1;j++)
  492.    {
  493.     if(strcmp(sortemp1[i].designation,sortemp1[j].designation)<=0)
  494.     {
  495.      temp[i]=sortemp1[i];
  496.      sortemp1[i]=sortemp1[j];
  497.      sortemp1[j]=temp[i];
  498.     }
  499.    }
  500.  }
  501.  
  502.  for( i=0;i<=num-1;i++)
  503.    {
  504.  
  505.     cout<<"     Name         Code        Designation         Years(EXP)      Age";
  506.  cout<<"     ------------------------------------------------------                                 ";
  507.  for( i=0;i<=num-1;i++)
  508.  {
  509.   cout<<setw(13)<<sortemp1[i].name;
  510.   cout<<setw(6)<<sortemp1[i].code;
  511.   cout<<setw(15)<<sortemp1[i].designation;
  512.   cout<<setw(10)<<sortemp1[i].exp;
  513.   cout<<setw(15)<<sortemp1[i].age;
  514.   cout<<endl;
  515.  }
  516.   cout<<"Press Any Key To Go Back";
  517.  getch();
  518.  
  519. } }
  520.  
  521. void sortage()
  522. {
  523.  system("cls");
  524.  int i,j;
  525.  struct employee temp[max];
  526.  for(i=0;i<=num-1;i++)
  527.  {
  528.   sortemp1[i]=emp[i];
  529.  }
  530.  for(i=0;i<=num-1;i++)
  531.   {
  532.    for(j=0;j<=num-1;j++)
  533.    {
  534.     if(sortemp1[i].age<sortemp1[j].age)
  535.     {
  536.      temp[i]=sortemp1[i];
  537.      sortemp1[i]=sortemp1[j];
  538.      sortemp1[j]=temp[i];
  539.     }
  540.    }
  541.  }
  542.  
  543.  for( i=0;i<=num-1;i++)
  544.    {
  545.  
  546.     cout<<"     Name         Code        Designation         Years(EXP)      Age";
  547.  cout<<"     ------------------------------------------------------                                 ";
  548.  for( i=0;i<=num-1;i++)
  549.  {
  550.   cout<<setw(13)<<sortemp1[i].name;
  551.   cout<<setw(6)<<sortemp1[i].code;
  552.   cout<<setw(15)<<sortemp1[i].designation;
  553.   cout<<setw(10)<<sortemp1[i].exp;
  554.   cout<<setw(15)<<sortemp1[i].age;
  555.   cout<<endl;
  556.  }
  557.   cout<<"Press Any Key To Go Back";
  558.  getch();
  559.  
  560. } }
  561.  
  562.  
  563. void sortexp()
  564. {
  565.  system("cls");
  566.  int i,j;
  567.  struct employee temp[max];
  568.  for(i=0;i<=num-1;i++)
  569.  {
  570.   sortemp1[i]=emp[i];
  571.  }
  572.  for(i=0;i<=num-1;i++)
  573.   {
  574.    for(j=0;j<=num-1;j++)
  575.    {
  576.     if(sortemp1[i].exp<sortemp1[j].exp)
  577.     {
  578.      temp[i]=sortemp1[i];
  579.      sortemp1[i]=sortemp1[j];
  580.      sortemp1[j]=temp[i];
  581.     }
  582.    }
  583.  }
  584.  
  585.  for( i=0;i<=num-1;i++)
  586.    {
  587.  
  588.     cout<<"     Name         Code        Designation         Years(EXP)      Age ";
  589.  cout<<"  ------------------------------------------------------ ";
  590.  for( i=0;i<=num-1;i++)
  591.  {
  592.   cout<<setw(13)<<sortemp1[i].name;
  593.   cout<<setw(6)<<sortemp1[i].code;
  594.   cout<<setw(15)<<sortemp1[i].designation;
  595.   cout<<setw(10)<<sortemp1[i].exp;
  596.   cout<<setw(15)<<sortemp1[i].age;
  597.   cout<<endl;
  598.  }
  599.   cout<<"Press Any Key To Go Back";
  600.  getch();
  601.  
  602. } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement