SHARE
TWEET

Untitled

a guest Dec 10th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "conio.h"
  4. #define fio "NhanVien.txt"
  5. #define fbin "NhanVien.dat"
  6. struct NV
  7. {
  8.     char MaNV[5];
  9.     char HoTen[28];
  10.     int Year;
  11.     float Luong;
  12. };
  13. void Nhap1NV(NV &x){
  14.     printf("Nhap ma nhan vien: ");
  15.     scanf("%s", &x.MaNV);
  16.     printf("Nhap ho va ten: ");
  17.     fflush(stdin);
  18.     gets(x.HoTen);
  19.     printf("Nhap nam sinh: ");
  20.     scanf("%d", &x.Year);
  21.     printf("Nhap luong co ban: ");
  22.     scanf("%f", &x.Luong);
  23. }
  24. void Xuat1NV(NV x){
  25.     printf("\nMSNV: %s", x.MaNV);
  26.     printf("\nHo va Ten: ");
  27.     puts(x.HoTen);
  28.     printf("Nam sinh: %d", x.Year);
  29.     printf("\nLuong co ban: %.3f", x.Luong);
  30. }
  31. void DS(NV a[], int &n){
  32.     int i=0;
  33.     char c;
  34.     do{
  35.         printf("\nNhap sinh vien thu %d", n+1);
  36.         Nhap1NV(a[i]);
  37.         i++;
  38.         printf("\nAn t de tiep tuc, phim bat ki de thoat.");
  39.         c=getch();
  40.     }while(c == 't');
  41.     n=i;
  42.     printf("\n%d", n);
  43. }
  44. void XuatDS(NV a[], int n){
  45.     printf("\n\t ----------- * CHUONG TRINH QUAN LI NHAN VIEN * -----------");
  46.     printf("\n\n\t\t\t DANH SACH LUONG NHAN VIEN \n ");
  47.     printf("%-10s %-28s %-10s %-10s\n", "Ma", "HoTen", "Nam", "Luong");
  48.     for(int i=0; i<n; i++)
  49.         printf("%-10s %-28s %-10d %-10.2f\n", a[i].MaNV, a[i].HoTen, a[i].Year, a[i].Luong);
  50. }
  51. void Ghi(NV a[], int n){
  52.     FILE *f = fopen(fio,"w");
  53.     if(f==NULL) printf("Error load file");
  54.     for(int i=0; i<n; i++)
  55.         fprintf(f, "%-10s %-28s %-10d %-10.2f\n", a[i].MaNV, a[i].HoTen, a[i].Year, a[i].Luong);
  56.     fclose(f);
  57. }
  58. void Doc(NV a[], int &n){
  59.     FILE *f = fopen(fio,"r");
  60.     if(f==NULL) printf("Error load file");
  61.     for(int i=0; i<n; i++)
  62.         fscanf(f, "%-10s %-28s %-10d %-10.2f\n", &a[i].MaNV, &a[i].HoTen, &a[i].Year, &a[i].Luong);
  63.     fclose(f);
  64. }
  65. int main(){
  66.     NV a[100], x;
  67.     int n;
  68.     // DS(a,n);
  69.     // Ghi(a,n);
  70.     Doc(a,n);
  71.     XuatDS(a,n);
  72.    
  73.     // Nhap1NV(x);
  74.     // Xuat1NV(x);
  75. }
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