Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <string.h>
- typedef struct
- {
- char MaNV[11];
- char HoTen[31];
- float HeSoLuong;
- char ChucVu[4];
- float PhuCap;
- } NhanVien;
- typedef NhanVien *pNV;
- void nhapThongTinNV(pNV &list, int &n)
- {
- printf("Nhap so luong nhan vien: ");
- scanf_s("%d", &n);
- list = (pNV)calloc(n, sizeof(NhanVien));
- float tmp = 0;
- for (int i = 0; i < n; i++)
- {
- printf("Nhap thong tin nhan vien %d: \n", i+1);
- fflush(stdin);
- printf("Ho ten: ");
- gets_s(list[i].HoTen);
- printf("Ma nhan vien: ");
- gets_s(list[i].MaNV);
- printf("He so luong: ");
- scanf_s("%f", &tmp); list[i].HeSoLuong = tmp;
- fflush(stdin);
- printf("Chuc vu: ");
- gets_s(list[i].ChucVu);
- }
- }
- void xuatDanhSachNV(pNV list, int n)
- {
- printf("\nCo %d nhan vien trong danh sach, nhu sau: \n", n);
- for (int i = 0; i < n; i++)
- {
- printf("\nNhan vien %d \n", i);
- printf("Ma nhan vien: %s\n", list[i].MaNV);
- printf("Ho ten: %s\n", list[i].HoTen);
- printf("He so luong: %f\n", list[i].HeSoLuong);
- printf("Chuc vu: %s\n", list[i].ChucVu);
- printf("Phu cap: %f\n", list[i].PhuCap);
- }
- }
- void tinhPhuCap(pNV list, int n)
- {
- for (int i = 0; i < n; i++)
- {
- if (!strcmp(list[i].ChucVu,"GD") || !strcmp(list[i].ChucVu,"PGD"))
- list[i].PhuCap = (float)0.15*list[i].HeSoLuong;
- else if (!strcmp(list[i].ChucVu,"TP") || !strcmp(list[i].ChucVu,"PP"))
- list[i].PhuCap = (float)0.1*list[i].HeSoLuong;
- else list[i].PhuCap = (float)0.05*list[i].HeSoLuong;
- }
- }
- void xuatDanhSachTPvaPP(pNV list, int n)
- {
- printf("\nDanh sach truong phong va pho phong: \n");
- for (int i = 0; i < n; i++)
- {
- if (!strcmp(list[i].ChucVu,"TP") || !strcmp(list[i].ChucVu,"PP"))
- {
- printf("\nMa nhan vien: %s\n", list[i].MaNV);
- printf("Ho ten: %s\n", list[i].HoTen);
- printf("He so luong: %f\n", list[i].HeSoLuong);
- printf("Chuc vu: %s\n", list[i].ChucVu);
- printf("Phu cap: %f\n", list[i].PhuCap);
- }
- }
- }
- void swapNV(pNV a, pNV b)
- {
- NhanVien tmp;
- tmp.HeSoLuong = a->HeSoLuong;
- tmp.PhuCap = a->PhuCap;
- strcpy_s(tmp.ChucVu, a->ChucVu);
- strcpy_s(tmp.HoTen, a->HoTen);
- strcpy_s(tmp.MaNV, a->MaNV);
- a->HeSoLuong = b->HeSoLuong;
- a->PhuCap = b->PhuCap;
- strcpy_s(a->ChucVu, b->ChucVu);
- strcpy_s(a->HoTen, b->HoTen);
- strcpy_s(a->MaNV, b->MaNV);
- b->HeSoLuong = tmp.HeSoLuong;
- b->PhuCap = tmp.PhuCap;
- strcpy_s(b->ChucVu, tmp.ChucVu);
- strcpy_s(b->HoTen, tmp.HoTen);
- strcpy_s(b->MaNV, tmp.MaNV);
- }
- void xapXepDStheoHSL(pNV list, int n)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i; j < n; j++)
- {
- if (list[i].HeSoLuong < list[j].HeSoLuong)
- swapNV(&list[i], &list[j]);
- }
- }
- }
- int main()
- {
- pNV list = NULL;
- int n = 0;
- nhapThongTinNV(list, n);
- tinhPhuCap(list, n);
- printf("\nDanh sach nhan vien trong cong ty: \n");
- xuatDanhSachNV(list, n);
- xuatDanhSachTPvaPP(list, n);
- xapXepDStheoHSL(list, n);
- printf("\nDanh sach da sap xep theo thu tu giam dan he so luong: \n");
- xuatDanhSachNV(list, n);
- free(list);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment