dreamer2908

THDC CSC01.D31 - De 2009 - 2010 - NhanVien

Aug 21st, 2013
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <string.h>
  5.  
  6. typedef struct
  7. {
  8.     char MaNV[11];
  9.     char HoTen[31];
  10.     float HeSoLuong;
  11.     char ChucVu[4];
  12.     float PhuCap;
  13. } NhanVien;
  14.  
  15. typedef NhanVien *pNV;
  16.  
  17. void nhapThongTinNV(pNV &list, int &n)
  18. {
  19.     printf("Nhap so luong nhan vien: ");
  20.     scanf_s("%d", &n);
  21.     list = (pNV)calloc(n, sizeof(NhanVien));
  22.     float tmp = 0;
  23.     for (int i = 0; i < n; i++)
  24.     {
  25.         printf("Nhap thong tin nhan vien %d: \n", i+1);
  26.         fflush(stdin);
  27.         printf("Ho ten: ");
  28.         gets_s(list[i].HoTen);
  29.         printf("Ma nhan vien: ");
  30.         gets_s(list[i].MaNV);
  31.         printf("He so luong: ");
  32.         scanf_s("%f", &tmp); list[i].HeSoLuong = tmp;
  33.         fflush(stdin);
  34.         printf("Chuc vu: ");
  35.         gets_s(list[i].ChucVu);
  36.     }
  37. }
  38.  
  39. void xuatDanhSachNV(pNV list, int n)
  40. {
  41.     printf("\nCo %d nhan vien trong danh sach, nhu sau: \n", n);
  42.     for (int i = 0; i < n; i++)
  43.     {
  44.         printf("\nNhan vien %d \n", i);
  45.         printf("Ma nhan vien: %s\n", list[i].MaNV);
  46.         printf("Ho ten: %s\n", list[i].HoTen);
  47.         printf("He so luong: %f\n", list[i].HeSoLuong);
  48.         printf("Chuc vu: %s\n", list[i].ChucVu);
  49.         printf("Phu cap: %f\n", list[i].PhuCap);
  50.     }
  51. }
  52.  
  53. void tinhPhuCap(pNV list, int n)
  54. {
  55.     for (int i = 0; i < n; i++)
  56.     {
  57.         if (!strcmp(list[i].ChucVu,"GD") || !strcmp(list[i].ChucVu,"PGD"))
  58.             list[i].PhuCap = (float)0.15*list[i].HeSoLuong;
  59.         else if (!strcmp(list[i].ChucVu,"TP") || !strcmp(list[i].ChucVu,"PP"))
  60.             list[i].PhuCap = (float)0.1*list[i].HeSoLuong;
  61.         else list[i].PhuCap = (float)0.05*list[i].HeSoLuong;
  62.     }
  63. }
  64.  
  65. void xuatDanhSachTPvaPP(pNV list, int n)
  66. {
  67.     printf("\nDanh sach truong phong va pho phong: \n");
  68.     for (int i = 0; i < n; i++)
  69.     {
  70.         if (!strcmp(list[i].ChucVu,"TP") || !strcmp(list[i].ChucVu,"PP"))
  71.         {
  72.             printf("\nMa nhan vien: %s\n", list[i].MaNV);
  73.             printf("Ho ten: %s\n", list[i].HoTen);
  74.             printf("He so luong: %f\n", list[i].HeSoLuong);
  75.             printf("Chuc vu: %s\n", list[i].ChucVu);
  76.             printf("Phu cap: %f\n", list[i].PhuCap);
  77.         }
  78.     }
  79. }
  80.  
  81. void swapNV(pNV a, pNV b)
  82. {
  83.     NhanVien tmp;
  84.  
  85.     tmp.HeSoLuong = a->HeSoLuong;
  86.     tmp.PhuCap = a->PhuCap;
  87.     strcpy_s(tmp.ChucVu, a->ChucVu);
  88.     strcpy_s(tmp.HoTen, a->HoTen);
  89.     strcpy_s(tmp.MaNV, a->MaNV);
  90.  
  91.     a->HeSoLuong = b->HeSoLuong;
  92.     a->PhuCap = b->PhuCap;
  93.     strcpy_s(a->ChucVu, b->ChucVu);
  94.     strcpy_s(a->HoTen, b->HoTen);
  95.     strcpy_s(a->MaNV, b->MaNV);
  96.  
  97.     b->HeSoLuong = tmp.HeSoLuong;
  98.     b->PhuCap = tmp.PhuCap;
  99.     strcpy_s(b->ChucVu, tmp.ChucVu);
  100.     strcpy_s(b->HoTen, tmp.HoTen);
  101.     strcpy_s(b->MaNV, tmp.MaNV);
  102. }
  103.  
  104. void xapXepDStheoHSL(pNV list, int n)
  105. {
  106.     for (int i = 0; i < n; i++)
  107.     {
  108.          for (int j = i; j < n; j++)
  109.          {
  110.              if (list[i].HeSoLuong < list[j].HeSoLuong)
  111.                  swapNV(&list[i], &list[j]);
  112.          }
  113.     }
  114. }
  115.  
  116. int main()
  117. {
  118.     pNV list = NULL;
  119.     int n = 0;
  120.  
  121.     nhapThongTinNV(list, n);
  122.     tinhPhuCap(list, n);
  123.     printf("\nDanh sach nhan vien trong cong ty: \n");
  124.     xuatDanhSachNV(list, n);
  125.     xuatDanhSachTPvaPP(list, n);
  126.     xapXepDStheoHSL(list, n);
  127.     printf("\nDanh sach da sap xep theo thu tu giam dan he so luong: \n");
  128.     xuatDanhSachNV(list, n);
  129.  
  130.     free(list);
  131.     _getch();
  132.     return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment