SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //cho n nhan vien. Nhap, xuat, sap xep theo he so luong
  2. #include <iostream>
  3.  
  4. using namespace std;
  5. struct Date {
  6.     int dd, mm, yyyy;
  7. };
  8. struct Employee {
  9.     char* name;
  10.     Date d;
  11.     float hsLuong;
  12. };
  13.  
  14. void inputDate(Date& d)
  15. {
  16.     cout << "Enter date : ";
  17.     cin >> d.dd >> d.mm >> d.yyyy;
  18. }
  19. void displayDate(Date d) {
  20.     (d.dd < 10) ? cout << 0 << d.dd << "/" : cout << d.dd << "/";
  21.     (d.mm < 10) ? cout << 0 << d.mm << "/" << d.yyyy : cout << d.mm << "/" << d.yyyy;
  22. }
  23. Employee inputEmployee(Employee *p){
  24.     p->name = new char[31];
  25.     cout << "\nEnter name: ";
  26.     cin.ignore();
  27.     cin.getline(p->name, 31);
  28.     inputDate(p->d);
  29.     cout << "Enter Hsl: ";
  30.     cin >> p->hsLuong;
  31.     return *p;
  32. }
  33. void inputListEmployee(Employee **&e, int numOfEmployee)
  34. {
  35.     e = new Employee*[numOfEmployee];
  36.     cout << "Enter List Employee: ";
  37.     for (int i = 0; i < numOfEmployee; i++)
  38.     {
  39.         e[i] = new Employee();
  40.         inputEmployee(e[i]);
  41.     }
  42. }
  43. void swap(Employee *A, Employee *B){
  44.     Employee temp = *A;
  45.     *A = *B;
  46.     *B = temp;
  47. }
  48. void sortIncreasingBySalary(Employee **&e, int numOfEmployee)
  49. {
  50.     for (int i = 0; i < numOfEmployee-1; i++)
  51.         for (int j = i+1; j < numOfEmployee; j++)
  52.         {
  53.             if (e[i]->hsLuong > e[j]->hsLuong)
  54.                 swap(e[i], e[j]);
  55.         }
  56. }
  57. void displayListEmployee(Employee **e, int numOfEmployee)
  58. {
  59.     cout << "Info Employee: \n";
  60.     cout << "--------------------\n";
  61.     for (int i = 0; i < numOfEmployee; i++)
  62.     {
  63.         cout << e[i]->name << endl;
  64.         displayDate(e[i]->d);
  65.         cout << endl <<  e[i]->hsLuong << endl;
  66.     }
  67. }
  68. int main()
  69. {
  70.     int numOfEmployee;
  71.     cout << "Enter number of Employee: "; cin >> numOfEmployee;
  72.     Employee **s;
  73.     inputListEmployee(s,numOfEmployee);
  74.     sortIncreasingBySalary(s,numOfEmployee);
  75.     displayListEmployee(s,numOfEmployee);
  76.     delete[] s;
  77.     return 0;
  78.  
  79. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top