Follow us on...
Follow us on Facebook

VN-Zoom.com chung tay vì Cộng đồng

Kaka - ứng dụng hát Karaoke trên mobile

Tuyển Mod Mobile diễn dàn Vn-Zoom.com 2014

Chiêm ngưỡng BaoMoi đẹp "tuyệt diệu" trên Windows Phone

Vui thể thao quà ý nghĩa

Toàn cảnh Vn-Zoom tham gia họp báo Asus Zenfone
kết quả từ 1 tới 13 trên 13

Đề tài: giúp em bài tập C

  1. #1
    ktxsv's Avatar
    ktxsv vẫn chưa có mặt trong diễn đàn Búa Đá
    Tham gia
    Apr 2008
    Bài
    61
    Cảm ơn
    21
    Điểm
    8/5 bài viết
    VR power
    0

    Default giúp em bài tập C

    bài tập là: viết chương trình tính tiền điện cho 100 hộ dân với thông tin la: họ tên chủ hộ, số điện thoại, địa chỉ,chỉ số cũ, chỉ số mới,mã công tơ, số điện tiêu thụ, số tiền phải trả
    biết:
    100kw đầu tiên là 550 đ
    50 kw tiếp theo 1150 đ
    50 kw tiếp theo 1450 đ
    201 kw trở đi là 1850 đ
    yêu cầu
    in ra hộ dân dùng nhiều điện nhất
    và trung bình số điện các hộ dùng trong tháng
    the end
    bài này em mới chỉ làm được nhập thành công còn cái yêu cầu kia em vẫn chưa làm xong:
    #include<conio.h>
    #include<stdio.h>
    struct QLTD
    {
    char hoten[30], diachi[20],mact[5];
    long sdt,csm,csc,dtt;
    float tiendien;
    }
    sh[100];
    int main()
    {
    int i,n,e,j,f,tg,d,m;
    float t;
    clrscr();
    printf("nhap vao so ho");
    scanf("%d",&n);
    for (i=0;i<n;i++)

    {
    printf("\n ho ten: "); scanf("%s",sh[i].hoten);
    printf("\n dia chi: ");scanf("%s",sh[i].diachi);
    printf("\nma cong to: "); scanf("%d",sh[i].mact);
    printf("\nso dien thoai: "); scanf("%d",&d);
    printf("\nchi so cu: "); scanf("%d",e);
    printf("\n chi so moi: "); scanf("%d",f);
    sh[i].sdt=d;
    sh[i].csc=e;
    sh[i].csm=f;
    sh[i].dtt=sh[i].csm-sh[i].csc;
    m=sh[i].dtt;
    if (m<=100)
    t=m*550;
    else
    if (m<150)
    t+=(m-100)*1150;
    else
    if (m<=200)
    t=100-550+(50-1150)+(m-150)*1450;
    else
    t=100*550+50*1150+50*1450+(m-200)*1850;
    sh[i].tiendien=t;
    }


    printf ("\n ho dan duoc sap xep:");
    for (i=0;i<n;i++)
    printf ("%d ",sh[i].dtt);
    getch();
    return 0;
    }

    mong các anh chị giúp đỡ.

  2. #2
    Long231298's Avatar
    Long231298 vẫn chưa có mặt trong diễn đàn Búa Gỗ
    Tham gia
    Oct 2007
    Bài
    11
    Cảm ơn
    519
    Điểm: 1/1 bài viết
    VR power
    0

    Default

    Bài của em đây:
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>

    /************************************************** *****************************/

    struct data
    {
    char name[30], address[150], metter_code[20];
    long int tele_num, new_index, old_index, amount_used, money;
    } *cust;

    int n; // so ho dan

    /************************************************** *****************************/

    void input_data();
    void money_to_pay(long int a,long int *b);
    void max();
    void average();

    /************************************************** *****************************/

    void main()
    {
    int choice;
    do
    {
    clrscr();
    printf("========================================== ========================\n");
    printf(" MENU\n");
    printf("========================================== ========================\n\n");
    printf("1. INPUT INFORMATION\n\n");
    printf("2. FIND MAX\n\n");
    printf("3. AVERAGE\n\n");
    printf("4. EXIT\n\n");
    do
    {
    printf("Please choose one (1-4): ");
    scanf("%d%*c", &choice);
    } while (choice<1 || choice>4);
    switch (choice)
    {
    case 1: input_data();
    break;

    case 2: max();
    break;

    case 3: average();
    break;

    case 4: exit(0);
    }
    } while (1);
    }

    /************************************************** *****************************/

    void input_data()
    {
    n = 0;
    cust = (data*) calloc(1,sizeof(data));
    do
    {
    clrscr();
    cust = (data*) realloc(cust,(n+1)*sizeof(data));
    printf("========================================== ========================\n");
    printf(" INPUT INFORMATION\n");
    printf("========================================== ========================\n\n");
    printf("Input customer number %d (press ENTER to finish): \n\n", n+1);
    printf("NAME: ");
    gets(cust[n].name);
    if (cust[n].name[0] == '\0')
    break;
    printf("\nADDRESS: ");
    gets(cust[n].address);
    printf("\nTELEPHONE NUMBER: ");
    scanf("%ld%*c", &cust[n].tele_num);
    printf("\nNEW INDEX: ");
    scanf("%ld%*c", &cust[n].new_index);
    printf("\nOLD INDEX: ");
    scanf("%ld%*c", &cust[n].old_index);
    cust[n].amount_used = cust[n].new_index - cust[n].old_index;
    money_to_pay(cust[n].amount_used,&cust[n].money);
    n++;
    } while (1);
    }

    /************************************************** *****************************/

    void money_to_pay(long int a,long int *b)
    {
    if (a<=100)
    *b = a*550;
    else if (a<=150)
    *b = 100*550 + (a-100)*1150;
    else if (a<=200)
    *b = 100*550 + 50*1150 +(a-150)*1450;
    else if (a>200)
    *b = 100*550 + 50*1150 + 50*1450 + (a-200)*1850;
    }

    /************************************************** *****************************/

    void max()
    {
    int i, maxi;
    long int maxa = 0;
    for (i=1;i<n;i++)
    if (maxa < cust[i].amount_used)
    maxi = i;
    clrscr();
    printf("========================================== ========================\n");
    printf(" THE MOST USED\n");
    printf("========================================== ========================\n\n");
    printf("NAME: %s\n\n", cust[maxi].name);
    printf("ADDRESS: %s\n\n", cust[maxi].address);
    printf("TELEPHONE NUMBER: %ld\n\n", cust[maxi].tele_num);
    printf("AMOUNT USED: %ld\n\n", cust[maxi].amount_used);
    printf("MONEY TO PAY: %ld\n\n", cust[maxi].money);
    printf("\n\n\npress anykey to continue");
    getch();
    }

    /************************************************** *****************************/

    void average()
    {
    int i;
    long int sum_amount = 0;
    float _average;
    clrscr();
    for (i=0;i<n;i++)
    sum_amount += cust[i].amount_used;
    _average = (float) sum_amount/n;
    printf("\n\n\n\n\n\n\t\t\tTHE AVERAGE AMOUNT OF ELECTRIC USED: %.3f\n\n", _average);
    printf("\n\npress anykey to continue");
    getch();
    }

    /************************************************** *****************************/

  3. #3
    ktxsv's Avatar
    ktxsv vẫn chưa có mặt trong diễn đàn Búa Đá
    Tham gia
    Apr 2008
    Bài
    61
    Cảm ơn
    21
    Điểm
    8/5 bài viết
    VR power
    0

    Default

    bài của anh long chưa chạy được. anh coi lại giùm em với

  4. #4
    xuanhung_cntt's Avatar
    xuanhung_cntt vẫn chưa có mặt trong diễn đàn Rìu Sắt Đôi
    Tham gia
    Apr 2008
    Bài
    224
    Cảm ơn
    63
    Điểm
    64/46 bài viết
    VR power
    0

    Default

    PHP Code:
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    #include <stdlib.h>
    int kt(char st[])
    {
      
    int n=strlen(st);
      
    int trave=0;
    if (
    n>0)
     {
       while (
    st[n-1]==' ' && n>0)
         {
        
    strcpy(&st[n-1],&st[n-2]);
        
    n--;
         }
        while (
    st[0]==' ' && n>0)
         {
        
    strcpy(&st[0],&st[1]);
        
    n--;
         }
         for (
    int i=0;i<strlen(st);i++)
         if(
    st[0]=='q' || st[0]=='Q')
             {
               
    trave= -2;
              }
          else
             if (
    st[i]<'0' || st[i]>'9')
               {
            
    trave=-1;
               }
         if (
    st=='\0')
        
    trave=-1;
        if (
    trave!=-&& trave!=-2)
            
    trave=atoi(st);


     }
     else 
    trave=-1;
     return 
    trave;
    }
    void main()
    {
    trolai:    clrscr();
        
    printf("Tinh TIen Dien Sinh Hoat. Nhan Q De Thoat\n");
        
    char stt,st[10];
        
    int i,j,k,l;
        
    float tien;
    tt1:    printf("Chi So Dien Cu:");
        
    fflush(stdin);gets(st);
        
    i=kt(st);
        if (
    i==-1)
          {
        
    printf("Ban Nhap Khong Dung!, Hay Nhap Lai\n");
        goto 
    tt1;
          }
         if (
    i==-2)
        goto 
    ket;
    tt2:    printf("Chi So Dien Moi:");
        
    fflush(stdin);gets(st);
        
    j=kt(st);
        if (
    j==-1)
          {
        
    printf("Ban Nhap Khong Dung!, Hay Nhap Lai\n");
        goto 
    tt2;
          }
         if (
    j==-2)
        goto 
    ket;
        
    i=j-i;
        if (
    i<0)
        {
           
    printf("Xin Loi! Ban Nhap khong Dung, Xin Vui long Nhap lai\n");
           goto 
    tt1;
         }
        else
         {
           
    printf("\n  So Dien trong Thang                             :%6d    (Kwh)",i);
           
    k=j=l=0;
           if (
    i<=100)
            {
                
    j=i;    // so dien muc 1
                
    i=0;
            }
           else
                {
                    
    j=100;  // muc 1:100so dau tien
                    
    i-=j;
                    if (
    i<=50)
                    {
                        
    k=i;    //muc 2:50kw so tiep theo
                        
    i=0;
                    }
                    else
                    {
                        
    k=50;    //muc 2:50 so tiep theo
                        
    i-=k;
                        if (
    i<=50)
                        {
                            
    l=i;    //muc 3:50 so tiep theo
                            
    i=0;
                        }
                        else
                        {
                            
    l=50;    // muc 3
                            
    i-=l;    // muc 4:>200 so
                        
    }
                    }
                }
           
    printf("\n  So Tien Tra ap dung cho so dien <=100kw         :%9.2f (dong)",(float)j*550);
           
    printf("\n  So Tien Nop ap dung cho 100Kw < so dien <=150kw :%9.2f (dong)",(float)k*1150);
           
    printf("\n  So Tien Nop ap dung cho 150Kw < so dien <=200kw :%9.2f (dong)",(float)l*14500);
           
    printf("\n  So Tien Tra ap dung cho so dien >200kw          :%9.2f (dong)",(float)i*1850);
           
    printf("\n\n  Tong So Tien Phai Nop                         :%9.2f  (Dong)",(float)j*550+(float)k*1150+(float)l*14500+(float)i*1850);
         }
         
    stt=getch();
         if (
    stt!='Q' && stt!='q')
         goto 
    trolai;
    ket:     printf(" ");

    cái này mình hơi văn hoa 1 chút. bạn có thể loại bỏ hàm kiểm tra đi.
    Mình cũng có bài tập này nên làm trước. tại thầy bắt kiểm tra dữ liệu nhập vào nên hơi dài hihi...
    Chúc bạn thành công

  5. #5
    ktxsv's Avatar
    ktxsv vẫn chưa có mặt trong diễn đàn Búa Đá
    Tham gia
    Apr 2008
    Bài
    61
    Cảm ơn
    21
    Điểm
    8/5 bài viết
    VR power
    0

    Default

    anh xuân hùng coi lại giùm em cái. đề em muốn in ra là:
    + in ra số hộ sử dụng điện nhiều nhất
    + tính bình quân lượng điện sử dụng trong tháng.

  6. #6
    95135784627's Avatar
    95135784627 vẫn chưa có mặt trong diễn đàn Rìu Bạc
    Tham gia
    Feb 2009
    Đến từ
    Ai mà biết?
    Bài
    418
    Cảm ơn
    106
    Điểm
    321/143 bài viết
    VR power
    0

    Default

    bai nay duoc roi do ban

  7. #7
    ktxsv's Avatar
    ktxsv vẫn chưa có mặt trong diễn đàn Búa Đá
    Tham gia
    Apr 2008
    Bài
    61
    Cảm ơn
    21
    Điểm
    8/5 bài viết
    VR power
    0

    Default

    bai nay duoc roi do ban
    bài nào cơ hả bạn?

  8. #8
    Long231298's Avatar
    Long231298 vẫn chưa có mặt trong diễn đàn Búa Gỗ
    Tham gia
    Oct 2007
    Bài
    11
    Cảm ơn
    519
    Điểm: 1/1 bài viết
    VR power
    0

    Default

    Bài của bạn đây (hơi nhầm tí về tìm max):

    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>

    /************************************************** *****************************/

    struct data
    {
    char name[30], address[150], metter_code[20];
    long int tele_num, new_index, old_index, amount_used, money;
    } *cust;

    int n; // so ho dan

    /************************************************** *****************************/

    void input_data();
    void money_to_pay(long int a,long int *b);
    void max();
    void average();

    /************************************************** *****************************/

    void main()
    {
    int choice;
    do
    {
    clrscr();
    printf("========================================== ========================\n");
    printf(" MENU\n");
    printf("========================================== ========================\n\n");
    printf("1. INPUT INFORMATION\n\n");
    printf("2. FIND MAX\n\n");
    printf("3. AVERAGE\n\n");
    printf("4. EXIT\n\n");
    do
    {
    printf("Please choose one (1-4): ");
    scanf("%d%*c", &choice);
    } while (choice<1 || choice>4);
    switch (choice)
    {
    case 1: input_data();
    break;

    case 2: max();
    break;

    case 3: average();
    break;

    case 4: exit(0);
    }
    } while (1);
    }

    /************************************************** *****************************/

    void input_data()
    {
    n = 0;
    cust = (data*) calloc(1,sizeof(data));
    do
    {
    clrscr();
    cust = (data*) realloc(cust,(n+1)*sizeof(data));
    printf("========================================== ========================\n");
    printf(" INPUT INFORMATION\n");
    printf("========================================== ========================\n\n");
    printf("Input customer number %d (press ENTER to finish): \n\n", n+1);
    printf("NAME: ");
    gets(cust[n].name);
    if (cust[n].name[0] == '\0')
    break;
    printf("\nADDRESS: ");
    gets(cust[n].address);
    printf("\nTELEPHONE NUMBER: ");
    scanf("%ld%*c", &cust[n].tele_num);
    printf("\nNEW INDEX: ");
    scanf("%ld%*c", &cust[n].new_index);
    printf("\nOLD INDEX: ");
    scanf("%ld%*c", &cust[n].old_index);
    cust[n].amount_used = cust[n].new_index - cust[n].old_index;
    money_to_pay(cust[n].amount_used,&cust[n].money);
    n++;
    } while (1);
    }

    /************************************************** *****************************/

    void money_to_pay(long int a,long int *b)
    {
    if (a<=100)
    *b = a*550;
    else if (a<=150)
    *b = 100*550 + (a-100)*1150;
    else if (a<=200)
    *b = 100*550 + 50*1150 +(a-150)*1450;
    else if (a>200)
    *b = 100*550 + 50*1150 + 50*1450 + (a-200)*1850;
    }

    /************************************************** *****************************/

    void max()
    {
    int i, maxi=0;
    long int maxa = cust[0].amount_used;
    for (i=1;i<n;i++)
    if (maxa < cust[i].amount_used)
    maxi = i;
    clrscr();
    printf("========================================== ========================\n");
    printf(" THE MOST USED\n");
    printf("========================================== ========================\n\n");
    printf("NAME: %s\n\n", cust[maxi].name);
    printf("ADDRESS: %s\n\n", cust[maxi].address);
    printf("TELEPHONE NUMBER: %ld\n\n", cust[maxi].tele_num);
    printf("AMOUNT USED: %ld\n\n", cust[maxi].amount_used);
    printf("MONEY TO PAY: %ld\n\n", cust[maxi].money);
    printf("\n\n\npress anykey to continue");
    getch();
    }

    /************************************************** *****************************/

    void average()
    {
    int i;
    long int sum_amount = 0;
    float _average;
    clrscr();
    for (i=0;i<n;i++)
    sum_amount += cust[i].amount_used;
    _average = (float) sum_amount/n;
    printf("\n\n\n\n\n\n\t\t\tTHE AVERAGE AMOUNT OF ELECTRIC USED: %.3f\n\n", _average);
    printf("\n\npress anykey to continue");
    getch();
    }

    /************************************************** *****************************/

  9. Có 1 thành viên cảm ơn Long231298 cho bài viết này:
    luu_nguyen (13-07-2011)

  10. #9
    hoang163's Avatar
    hoang163 vẫn chưa có mặt trong diễn đàn Búa Gỗ
    Tham gia
    May 2009
    Bài
    19
    Cảm ơn
    17
    Điểm
    2/2 bài viết
    VR power
    0

    Default

    làm cái gì mà sai hết cả thế ko chạy được

  11. #10
    Long231298's Avatar
    Long231298 vẫn chưa có mặt trong diễn đàn Búa Gỗ
    Tham gia
    Oct 2007
    Bài
    11
    Cảm ơn
    519
    Điểm: 1/1 bài viết
    VR power
    0

    Default

    mình đã test, chạy tốt mà.
    Bạn xem lại đi.

  12. #11
    thang795's Avatar
    thang795 vẫn chưa có mặt trong diễn đàn Búa Gỗ
    Tham gia
    Sep 2008
    Bài
    20
    Cảm ơn
    9
    Điểm: 2/1 bài viết
    VR power
    0

    Default

    Sai rùi A 2 ơi!7 lỗi!mấy lỗi ở định nghĩa hàm max đó!đổi tên hàm đi Anh!

  13. #12
    Tham gia
    Jul 2008
    Bài
    8
    Cảm ơn
    2
    Điểm
    4/4 bài viết
    VR power
    0

    Default sai roi`

    Trích ktxsv View Post
    bài này em mới chỉ làm được nhập thành công còn cái yêu cầu kia em vẫn chưa làm xong:



    mong các anh chị giúp đỡ.
    cong thuc thi dung nhung ma co cho sai roi` kai`

  14. #13
    ndp1007's Avatar
    ndp1007 vẫn chưa có mặt trong diễn đàn Búa Đá Đôi
    Tham gia
    Feb 2008
    Đến từ
    Contructor Function
    Bài
    113
    Cảm ơn
    44
    Điểm
    26/15 bài viết
    VR power
    0

    Default

    Đây cũng là đề tài mình nộp lấy điểm thực hành môn cấu trúc "dzữ' hồi đầu năm,tiện đây chia sẽ cho huynh đệ 1 phát
    Mình nhìn trong hóa đơn diện nhà,nên chế ra cái khung cũng giống giống
    Code viết sử dụng mảng:
    File:

    file "Dzữ" liệu:
    PHP Code:
    /*                        Foods Industry College  of Ho Chi Minh City
                                        -*-*FICH-*-*-

        CHUONG TRINH QUAN LY DIEN NANG TIEU THU MOT KHU CHUNG CU 5 DAY 20 PHONG/1DAY.5X20=100 PHONG
        SINH VIEN:NGUYEN DUY PHONG        MSSV 3001070090        LOP:07CDTH2        EMAIL:ndp1007@gmail.com        DTDD:0962958640.

    */

    #include "stdio.h"
    #include "conio.h"
    #include "stdlib.h"
    #include "string.h"
    #include"PROCESS.H"
    #include <fstream.h>
    // Cac Ham Ke Khung
    void khung()
    {for(
    int i=0;i<7;i++) printf("+--------");printf("+\n");}
    void khung2() // Khung Cho Menu
    {printf("+------+-------------------------------------------------+\n");}
    void khung_hd()
    {for(
    int i=0;i<5;i++)  printf("+---------");printf("+\n");}
    void khung_tim()
    {
    printf("+-----------------------+---+---+--------+--------+------+------------+\n");
    printf("| Ho Va Ten Khach Hang  |DAY| SP| SO CU  | SO MOI | DNTT | THANH TIEN |\n");
    printf("+-----------------------+---+---+--------+--------+------+------------+\n");
    }
    void khung_sdp()
    {
    printf("*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*\n");}
    //******************
    struct Date{
    int Y1,Y2;
    int M1,M2;
    int D1,D2;
    int ky;
    };
    struct Daychungcu{
        
    char Day;
    };
    //**********************************
    struct Khach_hang{
        
    char Ht[100];
        
    //char Day;
        
    Daychungcu Daycc;
        
    int  Sp;  // So Phong cua khu chung cu
        
    long Sm;  // chi so moi 
        
    long Sc;  // chi so cu cua dong ho dien
        
    long Ttd// Tong Tien Dien Phai Tra
        
    Date Ngay;
    };
    // Ham Input_Khach Hang
    void Input(char s[100],Khach_hang Kh[100],int n)
    {
        
    FILE *fp;
        
    fp=fopen(s,"w+");
        
    fprintf(fp,"+-----------------------+---+---+--------+--------+------+------------+\n");
        
    fprintf(fp,"| Ho Va Ten Khach Hang  |DAY| SP| SO CU  | SO MOI | DNTT | THANH TIEN |\n");
        
    fprintf(fp,"+-----------------------+---+---+--------+--------+------+------------+\n");
        for(
    int i=0;i<n;i++)
        {    
            {
    fprintf(fp,"|%s",Kh[i].Ht);int l=strlen(Kh[i].Ht);
            if(
    l<23) for(int j=0;j<23-l;j++) fprintf(fp," ");}
        
    fprintf(fp,"|%3c|%3d|%8ld|%8ld|%6d|%12ld|\n",Kh[i].Daycc.Day,Kh[i].Sp,Kh[i].Sc,Kh[i].Sm,Kh[i].Sm-Kh[i].Sc,Kh[i].Ttd);
        
    fprintf(fp,"+-----------------------+---+---+--------+--------+------+------------+\n");
        }
        
    fclose(fp);
    }
    void ClrS(char a[30]) // Xoa Khoang Trang(Clear Space)
    {    
        
    int d=strlen(a);
        for(
    int i=0;i<d;i++)
        {    if(
    a[i]==' '
            {    for(
    int j=i;j<d;j++)
                    
    a[j]=a[j+1];
                
    i--;
            }
        }
    }
    // Cac Nhom Ham Input 
    void Input_n(char s[100],int n)
    {    
    FILE *fp;    fp=fopen(s,"w+");    fprintf(fp,"%d",n);    fclose(fp);}
    void Input_Date(char s[100],Date Ng)
    {    
    FILE *fp;    fp=fopen(s,"w+");    fprintf(fp,"%d\n%d\n%d\n%d\n%d\n%d\n%d",Ng.ky,Ng.D1,Ng.M1,Ng.Y1,Ng.D2,Ng.M2,Ng.Y2);    fclose(fp);}
    void Input_Ht(char s[100],Khach_hang Kh[100],int n)
    {    
    FILE *fp;    fp=fopen(s,"w+");    for(int i=0;i<n;i++) fprintf(fp,"%s\n",Kh[i].Ht);fclose(fp);}
    void Input_Day(char s[100],Khach_hang Kh[100],int n)
    {    
    FILE *fp;    fp=fopen(s,"w+");    for(int i=0;i<n;i++)    fprintf(fp,"%c\n",Kh[i].Daycc.Day);    fclose(fp);}
    void Input_Sp(char s[100],Khach_hang Kh[100],int n)
    {    
    FILE *fp;    fp=fopen(s,"w+");    for(int i=0;i<n;i++)    fprintf(fp,"%d\n",Kh[i].Sp);    fclose(fp);}
    void Input_Sc(char s[100],Khach_hang Kh[100],int n)
    {    
    FILE *fp;    fp=fopen(s,"w+");    for(int i=0;i<n;i++)    fprintf(fp,"%ld\n",Kh[i].Sc);    fclose(fp);}
    void Input_Sm(char s[100],Khach_hang Kh[100],int n)
    {    
    FILE *fp;    fp=fopen(s,"w+");    for(int i=0;i<n;i++)     fprintf(fp,"%ld\n",Kh[i].Sm);    fclose(fp);}
    void Input_Ttd(char s[100],Khach_hang Kh[100],int n)
    {    
    FILE *fp;    fp=fopen(s,"w+");    for(int i=0;i<n;i++)    fprintf(fp,"%ld\n",Kh[i].Ttd);    fclose(fp);}
    //Ham Doc Don Gia Dien Tu File
    int read_dg(long dg[])
    {    
    charfile_name "Don_Gia.txt";
        
    ifstream in;    in.open(file_name);
        
    in >> dg[0];    in >> dg[1];    in >> dg[2];    in >> dg[3];    in >> dg[4];    in >> dg[5];
        
    in.close();
        return 
    1;
    }
    // Nhom Ham Doc Du Lieu Tu File
    int read_n(int &n)
    {
    char*file_name="N.txt";ifstream in;in.open(file_name);in >> n;in.close();return 1;}
    int read_Ht(Khach_hang Kh[100],int n)
    {
    char *file_name="Ho_Ten.txt";
        
    ifstream in;
        
    in.open(file_name);
        if (! 
    in)
            return 
    0;
        
    int Kh_i=0;
        while(
    Kh_i<&& !in.eof()){
        
    in >> Kh[Kh_i++].Ht;
        }
        
    Kh_i--;
        
    in.close();
        return 
    1;
    }
    int read_Date(Date &Ng)
    {
    char*file_name="Date.txt";
    ifstream in;
    in.open(file_name);
    in >> Ng.ky;in >> Ng.D1;in >> Ng.M1;in >> Ng.Y1;in >> Ng.D2;in >> Ng.M2;in >> Ng.Y2;
    in.close();
    return 
    1;
    }
    int read_Day(Khach_hang Kh[100],int n)
    {
    charfile_name "Day_Nha.txt";
        
    ifstream in;
        
    in.open(file_name);
        if (! 
    in)
            return 
    0;
        
    int Kh_i=0;
        while(
    Kh_i<&& !in.eof()){
            
    in >> Kh[Kh_i++].Daycc.Day;
        }
        
    Kh_i--;
        
    in.close();
        return 
    1;
    }
    int read_Sp(Khach_hang Kh[100],int n)
    {
    charfile_name "So_Phong.txt";
        
    ifstream in;
        
    in.open(file_name);
        if (! 
    in)
            return 
    0;
        
    int Kh_i=0;
        while(
    Kh_i<&& !in.eof()){
            
    in >> Kh[Kh_i++].Sp;
        }
        
    Kh_i--;
        
    in.close();
        return 
    1;
    }
    int read_Sc(Khach_hang Kh[100],int n)
    {
    charfile_name "Chi_So_Cu.txt";
        
    ifstream in;
        
    in.open(file_name);
        if (! 
    in)
            return 
    0;
        
    int Kh_i=0;
        while(
    Kh_i<&& !in.eof()){
            
    in >> Kh[Kh_i++].Sc;
        }
        
    Kh_i--;
        
    in.close();
        return 
    1;
    }
    int read_Sm(Khach_hang Kh[100],int n)
    {
    charfile_name="Chi_So_Moi.txt";
        
    ifstream in;
        
    in.open(file_name);
        if (! 
    in)
            return 
    0;
        
    int Kh_i=0;
        while(
    Kh_i<&& !in.eof()){
            
    in >> Kh[Kh_i++].Sm;
        }
        
    Kh_i--;
        
    in.close();
        return 
    1;
    }
    int read_Ttd(Khach_hang Kh[100],int n)
    {
    charfile_name="Tong_Tien_Dien.txt";
        
    ifstream in;
        
    in.open(file_name);
        if (! 
    in)
            return 
    0;
        
    int Kh_i=0;
        while(
    Kh_i<&& !in.eof()){
            
    in >> Kh[Kh_i++].Ttd;
        }
        
    Kh_i--;
        
    in.close();
        return 
    1;
    }
    // Ham Thay Doi Don Gia Tren Chuong Trinh
    void Tddgia(long dg[]) 
    {for(
    int i=0;i<6;i++){printf("Hoa Don Muc %d:",i+1);scanf("%ld",&dg[i]);}}
    // Ham Sua Don Gia Dien Neu Can-Luu Thanh File "Don_Gia.txt" Moi
    void Write_dg(char s[100],long dg[])
    {
    FILE *fp;fp=fopen(s,"w+");fprintf(fp,"%ld\n%ld\n%ld\n%ld\n%ld\n%ld",dg[0],dg[1],dg[2],dg[3],dg[4],dg[5]);fclose(fp);}
    /*void Output(char s[100],Khach_hang Kh[100],int &n)
    {
        FILE *fp=fopen(s,"r+");
        n=0;int flag;
        while(flag!=-1)
        {   
            fgets(Kh[n].Ht,17,fp);
        //flag=fscanf(fp,"%3c%3d%3d%8ld%8ld%12ld",&Kh[n].Daycc.Day[],&Kh[n].Sp,&Kh[n].Ky,&Kh[n].Sc,&Kh[n].Sm,Kh[n].Ttd);
            flag=fscanf(fp,"%c%d%ld%ld%ld",&Kh[n].Daycc.Day[n],&Kh[n].Sp,&Kh[n].Sc,&Kh[n].Sm,Kh[n].Ttd);
        fgetc(fp);
        if(flag!=-1)
            n++;
        }
        fclose(fp);
    }
    */
    int Ktd(Khach_hang Kh[100],char Day[5],int i)// kiem tra day nha khu chung cu co ton tai hay khong?
    {
        for(
    int j=0;j<5;j++)
            if (
    Kh[i].Daycc.Day==Day[j])
        return 
    1;
        return 
    0;
    }
    KtNg_1(Date Ng)
    {
    if( 
    Ng.D1>31 ||Ng.D1<=|| Ng.M1>12 || Ng.M1<=||Ng.Y1<=|| Ng.D1==31 &&( Ng.M1==|| Ng.M1==|| Ng.M1==|| Ng.M1==|| Ng.M1==11 ) || Ng.D1>=29 && Ng.M1==&& Ng.Y1 4!=0)
    return 
    0;
    return 
    1;
    }
    KtNg_2(Date Ng)
    {
    if( 
    Ng.D2>31 ||Ng.D2<=|| Ng.M2>12 || Ng.M2<=||Ng.Y2<=|| Ng.D2==31 &&( Ng.M2==|| Ng.M2==|| Ng.M2==|| Ng.M2==|| Ng.M2==11 ) || Ng.D2>=29 && Ng.M2==&& Ng.Y2 4!=0)
    return 
    0;
    return 
    1;
    }
    int TimKH(Khach_hang Kh[100], int nchar hoten[100])
    {
        for(
    int i=0;i<n;i++)
            if(
    strcmp(Kh[i].Ht,hoten)==0)
                return 
    i;
        return -
    1;
    }
    int Tim_Sp(Khach_hang Kh[],int n,int Sp)
    {
        for(
    int i=0;i<n;i++)
            if(
    Kh[i].Sp==Sp)
                return 
    i;
        return -
    1;
    }
    // Ham Xuat Bang Don Gia Dien Theo Dinh Muc
    void xdgia(long dg[])
    {
        
    printf("\tDON GIA DIEN TIEU THU THEO TUNG MUC DO\n");
    khung();
    printf("|MUC TTHU");for(int i=0;i<6;i++) printf("|%8d",i+1);printf("|\n");
    khung();
    printf("|TIEU THU|     100|      50|      50|     100|      50|      50|\n");
    khung();
    printf("|DON GIA |%8ld|%8ld|%8ld|%8ld|%8ld|%8ld|\n",dg[0],dg[1],dg[2],dg[3],dg[4],dg[5]);
    khung();
    printf("|DIEN NANG TIEU THU  DINH MUC 400 Kwh/1 HO   | DON VI TIEN:VND |\n");
    khung();
    }
    //****************************************
    // CAC HAM TINH TIEN DIEN THEO TUNG MUC DO SU DUNG 
    // Muc 1
    long gtien1(long dg[],int td)
    {return 
    td*dg[0];}
    // Muc 2
    long gtien2(long dg[],int td)
    {return 
    100*dg[0]+(td-100)*dg[1];}
    // Muc 3
    long gtien3(long dg[],int td)
    {return 
    100*dg[0]+50*dg[1]+(td-150)*dg[2];}
    // Muc 4
    long gtien4(long dg[],int td)
    {return 
    100*dg[0]+50*dg[1]+50*dg[2]+(td-200)*dg[3];}
    // Muc 5
    long gtien5(long dg[],int td)
    {return 
    100*dg[0]+50*dg[1]+50*dg[2]+100*dg[3]+(td-300)*dg[4];}
    // Muc 6
    long gtien6(long dg[],int td)
    {return 
    100*dg[0]+50*dg[1]+50*dg[2]+100*dg[3]+50*dg[4]+(td-350)*dg[5];}
    //*******************************************
    // Xem Hoa Don Tung Khach Hang
    void hdcnhan(Khach_hang Kh[],long dg[],int stt
    {
    long TD=Kh[stt].Sm-Kh[stt].Sc;
    long GT1=0;long GT2=0;long GT3=0;long GT4=0;long GT5=0;long GT6=0;
    const 
    int PT=2000;
     
    khung_hd();                               
     
    printf("|  SO CU  |  SO MOI | DNANG TT| DON GIA |THANHTIEN|\n");
     
    khung_hd();
     
    printf("|%9ld|%9ld",Kh[stt].Sc,Kh[stt].Sm);
        if (
    TD<=100)
         {
        
    GT1=gtien1(dg,TD);
        
    printf("|%9ld|%9ld|%9ld|\n",TD,dg[0],dg[0]*TD);
        
    khung_hd();
         };
        if (
    TD>100 && TD<=150)
         {
          
    GT2=gtien2(dg,TD);
          
    printf("|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
          
    khung_hd();
          
    printf("|         |         |%9ld|%9ld|%9ld|\n",TD-100,dg[1],(TD-100)*dg[1]);
          
    khung_hd();
     };
      if (
    TD>150 && TD<=200
       {
        
    GT3=gtien3(dg,TD);
          
    printf("|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
          
    khung_hd();
          
    printf("|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
          
    khung_hd();
          
    printf("|         |         |%9ld|%9ld|%9ld|\n",TD-150,dg[2],(TD-150)*dg[2]);
          
    khung_hd();
       }
        if(
    TD>200 && TD<=300)
        {
        
    GT4=gtien4(dg,TD);
          
    printf("|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
          
    khung_hd();
          
    printf("|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
          
    khung_hd();
          
    printf("|         |         |       50|%9ld|%9ld|\n",dg[2],50*dg[2]);
          
    khung_hd();
          
    printf("|         |         |%9ld|%9ld|%9ld|\n",TD-200,dg[3],(TD-200)*dg[3]);
          
    khung_hd();
        }
        if(
    TD>300 && TD<=350)
        {
        
    GT5=gtien5(dg,TD);
          
    printf("|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
          
    khung_hd();
          
    printf("|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
          
    khung_hd();
          
    printf("|         |         |       50|%9ld|%9ld|\n",dg[2],50*dg[2]);
          
    khung_hd();
          
    printf("|         |         |      100|%9ld|%9ld|\n",dg[3],100*dg[3]);
          
    khung_hd();
          
    printf("|         |         |%9ld|%9ld|%9ld|\n",TD-300,dg[4],(TD-300)*dg[4]);
          
    khung_hd();
        }
        if(
    TD>350)
        { 
        
    GT6=gtien6(dg,TD);
          
    printf("|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
          
    khung_hd();
          
    printf("|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
          
    khung_hd();
          
    printf("|         |         |       50|%9ld|%9ld|\n",dg[2],50*dg[2]);
          
    khung_hd();
          
    printf("|         |         |      100|%9ld|%9ld|\n",dg[3],100*dg[3]);
          
    khung_hd();
          
    printf("|         |         |       50|%9ld|%9ld|\n",dg[4],50*dg[4]);
          
    khung_hd();
          
    printf("|         |         |%9ld|%9ld|%9ld|\n",TD-350,dg[5],(TD-350)*dg[5]);
          
    khung_hd();
            }
       
    printf("|    * PHU THU *    |          |            |%9d|\n",PT);
       
    khung_hd();
       
    printf("|   * TONG CONG *   |%5ld Kwh|         |%9ld|\n",TD,GT1+GT2+GT3+GT4+GT5+GT6+PT);
       
    khung_hd();
    }
    // Xuat Hoa Don Cua Khach Hang Ra File Txt
    void Xuat_hdcnhan(char s[100],Khach_hang Kh[],Date Ng,long dg[],int stt
    {
    FILE *fp;
    fp=fopen(s,"w+");
    long TD=Kh[stt].Sm-Kh[stt].Sc;
    long GT1=0;long GT2=0;long GT3=0;long GT4=0;long GT5=0;long GT6=0;
    const 
    int PT=2000;
    fprintf(fp,"Ho & Ten:%s\nDay Nha:%c\nSo Phong:%d\n",Kh[stt].Ht,Kh[stt].Daycc.Day,Kh[stt].Sp);
     
    fprintf(fp,"\t\tHOA DON TIEN DIEN\n");read_Date(Ng);
    fprintf(fp,"Ky 06.Tu Ngay %d/%d/%d Den Ngay %d/%d/%d\n",Ng.D1,Ng.M1,Ng.Y1,Ng.D2,Ng.M2,Ng.Y2);
     {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}                               
     
    fprintf(fp,"|  SO CU  |  SO MOI | DNANG TT| DON GIA |THANHTIEN|\n");
     {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
     
    fprintf(fp,"|%9ld|%9ld",Kh[stt].Sc,Kh[stt].Sm);
        if (
    TD<=100)
         {
        
    GT1=gtien1(dg,TD);
        
    fprintf(fp,"|%9ld|%9ld|%9ld|\n",TD,dg[0],dg[0]*TD);
        {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
         };
        if (
    TD>100 && TD<=150)
         {
          
    GT2=gtien2(dg,TD);
          
    fprintf(fp,"|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |%9ld|%9ld|%9ld|\n",TD-100,dg[1],(TD-100)*dg[1]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
     };
      if (
    TD>150 && TD<=200
       {
        
    GT3=gtien3(dg,TD);
          
    fprintf(fp,"|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |%9ld|%9ld|%9ld|\n",TD-150,dg[2],(TD-150)*dg[2]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
       }
        if(
    TD>200 && TD<=300)
        {
          
    GT4=gtien4(dg,TD);
          
    fprintf(fp,"|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[2],50*dg[2]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |%9ld|%9ld|%9ld|\n",TD-200,dg[3],(TD-200)*dg[3]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
        }
        if(
    TD>300 && TD<=350)
        {
        
    GT5=gtien5(dg,TD);
          
    fprintf(fp,"|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[2],50*dg[2]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |      100|%9ld|%9ld|\n",dg[3],100*dg[3]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |%9ld|%9ld|%9ld|\n",TD-300,dg[4],(TD-300)*dg[4]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
        }
        if(
    TD>350)
        { 
        
    GT6=gtien6(dg,TD);
          
    fprintf(fp,"|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[2],50*dg[2]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |      100|%9ld|%9ld|\n",dg[3],100*dg[3]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[4],50*dg[4]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
          
    fprintf(fp,"|         |         |%9ld|%9ld|%9ld|\n",TD-350,dg[5],(TD-350)*dg[5]);
          {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
        }
       
    fprintf(fp,"|    * PHU THU *    |          |            |%9d|\n",PT);
       {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
       
    fprintf(fp,"|   * TONG CONG *   |%5ld Kwh|         |%9ld|\n",TD,GT1+GT2+GT3+GT4+GT5+GT6+PT);
       {for(
    int i=0;i<5;i++)  fprintf(fp,"+---------");fprintf(fp,"+\n");}
       
    fclose(fp);
    }
    void Nhap_Date(Date &Ng)
    {
    do{
    printf("Nhap So Ky:");char sky[10];fflush(stdin);gets(sky);Ng.ky=atoi(sky);}while(Ng.ky<=0);
       
    printf("Nhap Ngay Thang Dau Ky\n");
    do{
        do{
            
    printf("Ngay:");char ng[10]; fflush(stdin);gets(ng);Ng.D1=atoi(ng);}
        while(
    Ng.D1<=0);
        do{
            
    printf("Thang:");char th[10]; fflush(stdin);gets(th);Ng.M1=atoi(th);}
        while(
    Ng.M1<=0);
        do{
            
    printf("Nam:");char na[10]; fflush(stdin);gets(na);Ng.Y1=atoi(na);}
        while(
    Ng.Y1<=0);
      }
    while(
    KtNg_1(Ng)==0);
        
    printf("Nhap Ngay Thang Cuoi Ky\n");
    do{
        do{
            
    printf("Ngay:");char ng2[10]; fflush(stdin);gets(ng2);Ng.D2=atoi(ng2);}
        while(
    Ng.D2<=0);
        do{
            
    printf("Thang:");char th2[10]; fflush(stdin);gets(th2);Ng.M2=atoi(th2);}
        while(
    Ng.M2<=0);
        do{
            
    printf("Nam:");char na2[10]; fflush(stdin);gets(na2);Ng.Y2=atoi(na2);}
        while(
    Ng.Y2<=0);
      }
    while(
    KtNg_2(Ng)==|| Ng.Y1==Ng.Y2 && Ng.M1>Ng.M2 || Ng.D1==Ng.D2 && Ng.M1==Ng.M2 && Ng.Y1==Ng.Y2);
    Input_Date("Date.txt",Ng);// Dat O Day Vi Cac Bien ng,th,na la bien cuc bo nen ra khoi chuong trinh con se mat gia tri,nen dat o day moi in ra so dung duoc,
    }
    // Nhap Thong Tin Khach Hang
    void NhapmangKH(Khach_hang Kh[100],char Day[5],Date Ng,int n,long dg[],int msp[50][50],int z,int i)


        for(
    i=i<0?0:i;i<n;i++)
        {  
            
    printf("Khach Hang Thu %d:\n",i+1);
            
    fflush(stdin);
            
    printf("Ho & Ten:");gets(Kh[i].Ht);fflush(stdin);
            
    ClrS(Kh[i].Ht);
            do
            {
                
    printf("Chung Cu Co 5 Day:A  C  D  E.\n");
                
    printf("Day Chung Cu:");
                
    scanf("%c",&Kh[i].Daycc.Day);
                
    Kh[i].Daycc.Day=toupper(Kh[i].Daycc.Day);// Khi Nhap La Chu Thuong cung chap nhan va bien thanh hoa
                
    switch(Kh[i].Daycc.Day)
                {
                case 
    'A':z=0;break;
                case 
    'B':z=1;break;
                case 
    'C':z=2;break;
                case 
    'D':z=3;break;
                case 
    'E':z=4;break;
                }
            }
            while(
    Ktd(Kh,Day,i)==0);
            do
            {
                
    printf("So Phong:");char sp[3];fflush(stdin);gets(sp);Kh[i].Sp=atoi(sp);
            }
            while(
    Kh[i].Sp<=0|| msp[z][Kh[i].Sp]==1);
            do{
                do{
                
    printf("Chi So Cu:");char sc[10];fflush(stdin);gets(sc);Kh[i].Sc=atoi(sc);
                  }
                while(
    Kh[i].Sc<=0);
                do{
                
    printf("Chi So Moi:");char sm[10];fflush(stdin);gets(sm);Kh[i].Sm=atoi(sm);
                  }
                while(
    Kh[i].Sm<=0);
              }
            while(
    Kh[i].Sc>Kh[i].Sm);
    // Tinh tien dien cho moi ho
        
    long td=Kh[i].Sm-Kh[i].Sc;
        
    read_dg(dg);
        
    long gt1=0;long gt2=0;long gt3=0;long gt4=0;long gt5=0;long gt6=0;
        if(
    td<=100)                    gt1=gtien1(dg,td);
        if(
    td>100 && td<=150)        gt2=gtien2(dg,td);
        if(
    td>150 && td<=200)        gt3=gtien3(dg,td);
        if(
    td>200 && td<=300)        gt4=gtien4(dg,td);
        if(
    td>300 && td<=350)        gt5=gtien5(dg,td);
        if(
    td>350)                    gt6=gtien6(dg,td);
        
    Kh[i].Ttd=gt1+gt2+gt3+gt4+gt5+gt6;
        
    msp[z][Kh[i].Sp]=1;//hdcnhan(Kh,dg,i);
        
    }// end of FOR
    }// end Nhap Mang

    int max_Ttd(Khach_hang Kh[],int n)
    {
        
    long Max_Ttd=Kh[0].Ttd;
        for(
    int p=0;p<n;p++)
            if(
    Kh[p].Ttd>Max_Ttd)
            
    Max_Ttd=Kh[p].Ttd;
    return 
    Max_Ttd;
    }
    int min_Ttd(Khach_hang Kh[],int n)
    {    
        
    long Min_Ttd=Kh[0].Ttd;
        for(
    int p=0;p<n;p++)
            if(
    Kh[p].Ttd<Min_Ttd)
            
    Min_Ttd=Kh[p].Ttd;
            return 
    Min_Ttd;
    }
    int Count_vdm(Khach_hang Kh[],int n)
    {
    int Count=0;
    for(
    int i=0;i<n;i++)
    if((
    Kh[i].Sm-Kh[i].Sc)>400)
    Count++;
    return 
    Count;
    }
    // Cac Ham Doi Cho-Ho Tro Sap Xep
    void Swap_Ht(Khach_hang Kh[100],int i,int j)
    {
        
    char temp[100];
        
    strcpy(temp,Kh[i].Ht);
        
    strcpy(Kh[i].Ht,Kh[j].Ht);
        
    strcpy(Kh[j].Ht,temp);
    }
    void Swap_Day(Khach_hang Kh[100],int i,int j)
    {
        
    char temp;
        
    temp=Kh[i].Daycc.Day;
        
    Kh[i].Daycc.Day=Kh[j].Daycc.Day;
        
    Kh[j].Daycc.Day=temp;
    }
    void Swap_Sp(Khach_hang Kh[100],int i,int j)
    {
        
    int temp;
        
    temp=Kh[i].Sp;
        
    Kh[i].Sp=Kh[j].Sp;
        
    Kh[j].Sp=temp;
    }
    void Swap_Sc(Khach_hang Kh[100],int i,int j)
    {
        
    long temp;
        
    temp=Kh[i].Sc;
        
    Kh[i].Sc=Kh[j].Sc;
        
    Kh[j].Sc=temp;
    }
    void Swap_Sm(Khach_hang Kh[100],int i,int j)
    {
        
    long temp;
        
    temp=Kh[i].Sm;
        
    Kh[i].Sm=Kh[j].Sm;
        
    Kh[j].Sm=temp;
    }
    void Swap_Ttd(Khach_hang Kh[100],int i,int j)
    {
        
    long temp;
        
    temp=Kh[i].Ttd;
        
    Kh[i].Ttd=Kh[j].Ttd;
        
    Kh[j].Ttd=temp;
    }
    void List_Kh(Khach_hang Kh[100],int t)
    {
    printf("|%s",Kh[t].Ht);if(strlen(Kh[t].Ht)<23) for(int m=0;m<(23-strlen(Kh[t].Ht));m++) printf(" ");
    printf("|%3c|%3d|%8ld|%8ld|%6d|%12ld|\n",Kh[t].Daycc.Day,Kh[t].Sp,Kh[t].Sc,Kh[t].Sm,Kh[t].Sm-Kh[t].Sc,Kh[t].Ttd);
    printf("+-----------------------+---+---+--------+--------+------+------------+\n");
    }
    void Input_all(Khach_hang Kh[100],int n)
    {
    Input_n("N.txt",n);Input_Ht("Ho_Ten.txt",Kh,n);Input_Day("Day_Nha.txt",Kh,n);Input_Sp("So_Phong.txt",Kh,n);Input_Sc("Chi_So_Cu.txt",Kh,n);
    Input_Sm("Chi_So_Moi.txt",Kh,n);Input_Ttd("Tong_Tien_Dien.txt",Kh,n);Input("Du_Lieu_Khach_hang.txt",Kh,n);
    }
    void read_all(Khach_hang Kh[100],Date Ng,int n)
    {
    read_Date(Ng);read_n(n);read_Ht(Kh,n);read_Day(Kh,n);read_Sp(Kh,n);read_Sc(Kh,n);read_Sm(Kh,n);read_Sm(Kh,n);read_Ttd(Kh,n);
    }
    void List_Date(Date Ng)
    {
    printf("Ky:%d.Tu Ngay %d/%d/%d Den Ngay %d/%d/%d\n",Ng.ky,Ng.D1,Ng.M1,Ng.Y1,Ng.D2,Ng.M2,Ng.Y2);
    khung_tim();
    }
    void MENU(intchon,int &n,Khach_hang Kh[100],char Day[5],Date Ng,long dg[],intquit,int msp[50][50],int z,int i)
     {
    printf("\n");
        
    khung2();
        
    printf("| CASE |                  ACTION                         |\n");
        
    khung2();
        
    printf("|   1  | THOAT KHOI MENU                                 |\n");
        
    khung2();
        
    printf("|   2  | XEM & SUA CAC DON GIA                           |\n");
        
    khung2();
        
    printf("|   3  | NHAP THONG TIN KHACH HANG                       |\n");
        
    khung2(); 
        
    printf("|   4  | TIM KHACH HANG THEO DIEU KIEN                   |\n");
        
    khung2();
        
    printf("|   5  | XEM HOA DON TIEN DIEN CUA CA NHAN               |\n");
        
    khung2();
        
    printf("|   6  | THEM KHACH HANG VAO TRONG DANH SACH             |\n");  
        
    khung2();
        
    printf("|   7  | XUAT HOA DON TIEN DIEN CA NHAN RA FILE          |\n");  
        
    khung2();
        
    printf("|   8  | TIM KHACH HANG TIEU THU DIEN VUOT DINH MUC      |\n");
        
    khung2();
        
    printf("|   9  | XEM THONG TIN CUA KH THEO THU TU NHAP BAN DAU   |\n");
        
    khung2();
        
    printf("|   10 | SAP XEP DIEN NANG TIEU THU THEO THU TU TANG DAN |\n");
        
    khung2();
        
    printf("|   11 | KIEM TRA SO PHONG TRO CO KHACH THUE BANG MA TRAN|\n");
        
    khung2();

        do{
            
    printf("CHON:");char select[10]; fflush(stdin) ;gets(select);chon=atoi(select);}
        while(
    chon<=0);
        switch(
    chon)
        {
        case 
    1quit=1;// Thoat Khoi MENU
        
    break;
        case 
    2:read_dg(dg);xdgia(dg);printf("Nhan So 1 De Thay Doi Don Gia Neu Can.Nhan Phim Khac De Tu Choi\n");
            
    int td;scanf("%d",&td);if(td==1){Tddgia(dg);Write_dg("Don_Gia.txt",dg);}//Ham Thay Doi Don Gia-Xuat Ra File
            
    break;
         
    // Xem Don Gia Tu File
            
    break;
        case 
    3:    printf("\t\tNHAP THONG TIN KHACH HANG\n");// Nhap Thong Tin Khach Hang
                
                
    do{
                    
    printf("SO HO THUE PHONG:");char sh[10]; fflush(stdin);gets(sh);n=atoi(sh);}
                
    //scanf("%d",&n);} 
                
    while (n<=0);
                
    Nhap_Date(Ng);
                
    NhapmangKH(Kh,Day,Ng,n,dg,msp,z,i);
                
    Input_all(Kh,n);
            break;     
        case 
    4:{
            
    read_all(Kh,Ng,n);
            
    printf("1.Tim Khach Hang Tieu Thu Dien Cao Nhat\n");
            
    printf("2.Tim Khach Hang Tieu Thu Dien It Nhat\n");
            
    printf("3.Tim Theo Ten Khach Hang\n");
            
    int sl,t;char select[10];
            do{
    printf("Chon:");fflush(stdin);gets(select);sl=atoi(select);}while(sl<=0);printf("\n");
            switch(
    sl)
            {
                case 
    1:{
                    for(
    int z=0;z<n;z++) // Quet tim khach hang
                        
    if(Kh[z].Ttd==max_Ttd(Kh,n)) 
                            
    t=z;
                
    List_Date(Ng);
                
    List_Kh(Kh,t);
                       }
                break;
                case 
    2:{
                    for(
    int z=0;z<n;z++) 
                    if(
    Kh[z].Ttd==min_Ttd(Kh,n))
                         
    t=z;
                
    List_Date(Ng);
                
    List_Kh(Kh,t);
                       }
                break;
                case 
    3:{
                
    char hoten[50];    printf("Nhap Ten Can Tim:");fflush(stdin);gets(hoten);fflush(stdin); ClrS(hoten);
                
    t=TimKH(Kh,n,hoten);
                if(
    t!=-1)  
                {
                
    List_Date(Ng);
                
    List_Kh(Kh,t);
                }
                else 
    printf("Khong Tim Thay Khach Hang\n");
                       } 
    //end of case 3
                
    break;
            } 
    // end of Switch(sl)
               
    }
        break;
        case 
    5:{
                 
    printf("Nhap Ten Cua Khach Hang:");
                 
    char hoten[50] ;fflush(stdin); gets(hoten);fflush(stdin);
                 
    ClrS(hoten); int t=TimKH(Kh,n,hoten);
                 if(
    t!=-1)
                    {
                
    printf("\nHo Va Ten:");printf("%s\n",hoten);
                
    printf("Day Nha  :%c",Kh[t].Daycc.Day);
                
    printf("\nSo Phong :%d\n",Kh[t].Sp);
                
    printf("\t\tHOA DON TIEN DIEN\n\n");read_Date(Ng);
                
    printf("Ky:%d.Tu Ngay %d/%d/%d Den Ngay %d/%d/%d\n\n",Ng.ky,Ng.D1,Ng.M1,Ng.Y1,Ng.D2,Ng.M2,Ng.Y2);
                
    hdcnhan(Kh,dg,t);
                    }
                 else 
    printf("Khong Tim Thay Khach Hang\n");
                }
        break;
        case 
    6:{
            
    int skh;
            do{    
    printf("Nhap so Khach hang muon chen:");char Skh[10];fflush(stdin);gets(Skh);skh=atoi(Skh);}
            while(
    skh<=0);
            
    i=n
            
    n=n+skh;
            
    NhapmangKH(Kh,Day,Ng,n,dg,msp,z,i);
            
    Input_all(Kh,n);
               }
        break;
        case 
    7:{
            
    char hoten[50];int t;
            
    printf("Nhap Ten Khach Hang:");    fflush(stdin);gets(hoten);fflush(stdin);ClrS(hoten);t=TimKH(Kh,n,hoten);
            if(
    t!=-1)
            {
    char *file_name=strcat(hoten,".txt");Xuat_hdcnhan(file_name,Kh,Ng,dg,t);printf("Da Xuat File Thanh Cong.Ten File:%s\n",file_name);}
            else 
    printf("Khach Hang Khong Ton Tai\n");
               }
        break;
        case 
    8:{
            
    int vdm=Count_vdm(Kh,n);
            if(
    vdm==0
            
    printf("Khong Co Khach Hang Vuot Dinh Muc\n");
            else
            
    printf("Co %d Khach Hang Vuot Dinh Muc.Dien Nang Tieu Thu Vuot Qua 400 Kwh\n",Count_vdm(Kh,n));
            
    List_Date(Ng);
            for(
    int t=0;t<n;t++) // Can tim hieu tai sao t<vdm ko duoc ma phai la n moi duoc
                
    if((Kh[t].Sm-Kh[t].Sc)>400
                    
    List_Kh(Kh,t);
              }
        break;
        case 
    9:{
            
    List_Date(Ng);
            for(
    int t=0;t<n;t++)
            
    List_Kh(Kh,t);
               }
        break;
        case 
    10:{
            
    int i,j;// Nho Uu tien doc du lieu nao truoc de cac du lieu sau co nhan fduoc gia tri
            
    printf("\tDanh Sach Khach Hang Tieu Thu Dien Nang Theo Thu Tu Tang Dan \n");
            
    List_Date(Ng);
            for(
    i=0;i<n;i++){
                for(
    j=i;j<n;j++)
                  if(
    Kh[i].Sm-Kh[i].Sc>Kh[j].Sm-Kh[j].Sc)
                    {
    Swap_Day(Kh,i,j);Swap_Sp(Kh,i,j);Swap_Sc(Kh,i,j);Swap_Sm(Kh,i,j);Swap_Ttd(Kh,i,j);Swap_Ht(Kh,i,j);}
                    
    List_Kh(Kh,i);}
                }
        break;
        case 
    11:{
            
    int y;int a=65;int b=88;int d;
            
    printf("\tChung Cu Co 5 Day Nha.Moi Day Co 20 Phong.\n\tCot La So Day-*-Dong La So Phong.\n\tCac O Co Khach Thue Duoc Danh Dau X\n");
                for(
    int t=0;t<n;t++)
                {
                    switch(
    Kh[t].Daycc.Day)
                    {
                    case 
    'A':y=0;break;        case 'B':y=1;break;
                    case 
    'C':y=2;break;        case 'D':y=3;break;
                    case 
    'E':y=4;break;
                    }
                    
    msp[y][Kh[t].Sp]=1;
                }
            
    khung_sdp();
            
    printf("|  | 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15|16|17|18|19|20|\n");
            
    khung_sdp();
            for(
    int x=0;x<5;x++){
                
    printf("|%2c|",a);
                for(
    int j=1;j<21;j++)
                    
    printf("%2c|",d=msp[x][j]>0?b:msp[x][j]);
                
    printf("\n");
                
    khung_sdp();
                
    a++;
                                }
                }
        break;
        } 
    // end of Switch MENU
        
    if(quit==0){
        
    printf("Press any key to continue your working....");    getch();
        
    MENU(chon,n,Kh,Day,Ng,dg,quit,msp,z,i);}
     }
    //end of MENU
    void main()
    {
        
    Khach_hang Kh[100];    Date Ng;
        
    char Day[5]={'A','B','C','D','E'};
        
    int n,chon,z,i;    int quit=0;    int msp[50][50];long dg[5];//{550,1110,1470,1600,1720,2000};
        
    for(int x=0;x<5;x++)
            for(
    int j=0;j<21;j++)
                
    msp[x][j]=0;
        
    read_Date(Ng);read_n(n);read_Ht(Kh,n);read_Day(Kh,n);read_Sp(Kh,n);read_Sc(Kh,n);read_Sm(Kh,n);read_Sm(Kh,n);read_Ttd(Kh,n);
        if(
    quit==0)
        
    MENU(chon,n,Kh,Day,Ng,dg,quit,msp,z,i);
        
    getch();

    Code viết sử dụng Danh Sách Liên Kết:
    File :Nguyên bộ báo cáo đề tài

    PHP Code:
    #include "stdio.h"
    #include "conio.h"
    #include "stdlib.h"
    #include "string.h"
    #include"PROCESS.H"
    #include <fstream.h>

    struct Date{
        
    int Y1,Y2// Nam
        
    int M1,M2// Thang
        
    int D1,D2// Ngay 
        
    int SKy;   // So Ky 
    };
    //Khai Bao Cac Struct-Cau Truc Du Lieu Lien Ket Doi*****************************

    struct Khach_hang
    {
        
    char Ht[100];// Ho Ten Khach Hang
        
    char Day;     // Ten Day Phong Co 5 Day A,B,C,D,E
        
    int  Sp;     // So Phong cua khu chung cu
        
    long Sm;     // chi so moi 
        
    long Sc;     // chi so cu cua dong ho dien
        
    long Ttd;     // Tong Tien Dien Phai Tra
    };

    // Tao DNode
    typedef struct tagDNode
    {
        
    Khach_hang Kh;
        
    struct tagDNode *pNext;
        
    struct tagDNode *pPrev;
    }
    DNode;

    // Tao Danh Sach Lien Ket
    typedef struct DList
    {
        
    tagDNode *pHead;
        
    tagDNode *pTail;
    }
    DList;

    // Ham Tao DNode
    DNodeCreateDNode(Khach_hang &Kh,int n)
    {
        
    DNode *p;
        
    p=new DNode;
        if(
    p==NULL) return NULL;
        
    p->Kh=Kh;
        
    p->pNext=p->pPrev=NULL;
    return 
    p;
    }

    // Ham Tao DSLK Doi
    void CreateDList(DList &l,int n)
    {
        
    Khach_hang Kh;
        
    DNode *p;
        
    l.pHead=l.pTail=NULL;
        
    // Doan Code Doc Du Lieu Khach Hang Tu File "Khach_hang.txt"
          
    ifstream in
          
    char *file_name="Khach_hang.txt";
           
    in.open(file_name);
        for(
    int i=0;i<n;i++)
        {
            
    in >> Kh.Ht;
            
    in >> Kh.Day;
            
    in >> Kh.Sp;
            
    in >> Kh.Sc;
            
    in >> Kh.Sm;
        
    // Ket Thuc Lay Du Lieu lan Thu i
        
    p=CreateDNode(Kh,n);
        if(
    p==NULL) return;
        if(
    l.pHead==NULL)
            
    l.pHead=l.pTail=p;
        else
            {
                
    l.pTail->pNext=p;
                
    p->pPrev=l.pTail;
                
    l.pTail=p;
            }
        } 
    // end for

    }

    // CAC NHOM HAM KE KHUNG**********************************************************
    void Khung_dg()
    {
        for(
    int i=0;i<7;i++) 
            
    printf("+--------");
            
    printf("+\n");
    }
    void Khung_Menu()
    {
        
    printf("+------+-------------------------------------------------+\n");
    }

    void Khung_Hoadon()
    {
        for(
    int i=0;i<5;i++)  
            
    printf("+---------");
            
    printf("+\n");
    }
    void Khung_Xuat_File_Hd(char Ten_file[15],FILEfp)
    {
        for(
    short int i=0;i<5;i++)
            
    fprintf(fp,"+---------");
            
    fprintf(fp,"+\n");
    }
    void Khung_Tieude()
    {
    printf("\n+-----------------------+---+---+--------+--------+------+------------+\n");
    printf("| Ho Va Ten Khach Hang  |DAY| SP| SO CU  | SO MOI | DNTT | THANH TIEN |\n");
    printf("+-----------------------+---+---+--------+--------+------+------------+\n");
    }
    void Khung_sdp()
    {
        
    printf("*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*\n");
    }

    //**********Nhom Ham Doc Du Lieu Tu File********************

    // Ham Doc So Khach Hang Co Trong Danh Sach
    void Doc_SoKh(int &n)
    {
        
    char *file_n="So_Kh.txt";
            
    ifstream in;
            
    in.open(file_n);
        
    in>>n;
    }
    // Ham Doc Don Gia Tu File "Don_Gia.txt"
    int Doc_dg(long dg[])
    {    
        
    charfile_dg="Don_Gia.txt";
        
    ifstream in;
        
    in.open(file_dg);
        for(
    short int i=0;i<6;i++)
        
    in >> dg[i];
        
    in.close();
        return 
    1;
    }
    short int Doc_Date(Date &Ng
    {
        
    charFile_Date="Date.txt";
        
    ifstream in;
        
    in.open(File_Date);
        
    in >> Ng.SKy;
        
    in >> Ng.D1;
        
    in >> Ng.M1;
        
    in >> Ng.Y1;
         
    in >> Ng.D2;
        
    in >> Ng.M2;
        
    in >> Ng.Y2;
        
    in.close();
        return 
    1;
    }

    // Ham Xem Cac Muc Don Gia Tuy Theo Muc Do Su Dung
    void Xem_dg(long dg[])
    {
        
    printf("\n\t    DON GIA DIEN TIEU THU THEO TUNG MUC DO\n");
        
    Khung_dg();
            
    printf("|MUC TTHU");for(int i=0;i<6;i++) printf("|%8d",i+1);printf("|\n");
        
    Khung_dg();
            
    printf("|TIEU THU|     100|      50|      50|     100|      50|      50|\n");
        
    Khung_dg();
            
    printf("|DON GIA |%8ld|%8ld|%8ld|%8ld|%8ld|%8ld|\n",dg[0],dg[1],dg[2],dg[3],dg[4],dg[5]);
        
    Khung_dg();
            
    printf("|DIEN NANG TIEU THU  DINH MUC 400 Kwh/1 HO   | DON VI TIEN:VND |\n");
        
    Khung_dg();
    }
    // Ham Thay Doi Don Gia Cap Nhat Vao File "Don_Gia.TXT"
    void Thaydoi_dg(long dg[]) 
    {
        for(
    short int i=0;i<6;i++)
        {
            
    printf("Hoa Don Muc %d:",i+1);
            
    scanf("%ld",&dg[i]);
        }
    }
    void Xuat_dg(char Ten_File[15],long dg[])
    {
        
    FILEfp;
        
    fp=fopen(Ten_File,"w+");
        for(
    short int i=0;i<6;i++)
            
    fprintf(fp,"%ld\n",dg[i]);
        
    fclose(fp);
    }
    // Nhom Ham Ho Tro Tim Kiem O CASE 3
    DNodeMax_Td(DList l)
    {
        
    DNodep;
        
    int Max=l.pHead->Kh.Sm-l.pHead->Kh.Sc;
        for(
    p=l.pHead->pNext;p!=NULL;p=p->pNext)
            if(
    p->Kh.Sm-p->Kh.Sc>Max)
                return 
    p;
        return 
    NULL;
    }

    DNodeMin_Td(DList l)
    {
        
    DNodep;
        
    int Min=l.pTail->Kh.Sm-l.pTail->Kh.Sc;
        for(
    p=l.pTail->pPrev;p!=NULL;p=p->pPrev)
            if(
    p->Kh.Sm-p->Kh.Sc<Min)
                return 
    p;
        return 
    NULL;
    }
    DNodeTimKh(DList l,char Ten_Kh[30])
    {
        for(
    DNode*p=l.pHead ;p!=NULL;p=p->pNext)
            if(
    strcmp(p->Kh.Ht,Ten_Kh)==0)
                return 
    p;
            return 
    NULL;
    }

    void Swap(DNode *&p,DNode *&q)
    {
        
    Khach_hang Temp;
        
    Temp=p->Kh;
        
    p->Kh=q->Kh;
        
    q->Kh=Temp;
    }
    // CAC HAM TINH TIEN DIEN THEO TUNG MUC DO SU DUNG 
    // Muc 1
    long gtien1(long dg[],int td)
        {return 
    td*dg[0];}
    // Muc 2
    long gtien2(long dg[],int td)
        {return 
    100*dg[0]+(td-100)*dg[1];}
    // Muc 3
    long gtien3(long dg[],int td)
        {return 
    100*dg[0]+50*dg[1]+(td-150)*dg[2];}
    // Muc 4
        
    long gtien4(long dg[],int td)
        {return 
    100*dg[0]+50*dg[1]+50*dg[2]+(td-200)*dg[3];}
    // Muc 5
    long gtien5(long dg[],int td)
        {return 
    100*dg[0]+50*dg[1]+50*dg[2]+100*dg[3]+(td-300)*dg[4];}
    // Muc 6
    long gtien6(long dg[],int td)
        {return 
    100*dg[0]+50*dg[1]+50*dg[2]+100*dg[3]+50*dg[4]+(td-350)*dg[5];}

    // Ham Tim & Tinh Gia Tri Tien Theo Tung Muc Do Su Dung Dien
    long Ttien(long dg[],DNodep)
    {
        
    long td;//  Dien Nang Tieu Dung
        
    td=p->Kh.Sm-p->Kh.Sc;
        if(
    td<=100)
            return 
    gtien1(dg,td);
        if(
    td>100 && td<=150)
            return 
    gtien2(dg,td);
        if(
    td>150 && td<=200)
            return 
    gtien3(dg,td);
        if(
    td>250 &&td<=300)
            return 
    gtien4(dg,td);
        if(
    td>300 && td<=350)
            return 
    gtien5(dg,td);
        if(
    td>350)
            return 
    gtien6(dg,td);
    }
    void View_Kh(DList l,DNodep,long dg[])
    {
    printf("|%s",p->Kh.Ht);if(strlen(p->Kh.Ht)<23) for(int m=0;m<(23-strlen(p->Kh.Ht));m++) printf(" ");
    printf("|%3c|%3d|%8ld|%8ld|%6d|%12ld|\n",p->Kh.Day,p->Kh.Sp,p->Kh.Sc,p->Kh.Sm,p->Kh.Sm-p->Kh.Sc,Ttien(dg,p));
    printf("+-----------------------+---+---+--------+--------+------+------------+\n");
    }
    // Ham Xem Hoa Don Ca Nhan
    void Xem_Hoadon(DList l,Date Ng,long dg[],DNodep
    {
        
    //DNode *p;
        
    long TD=p->Kh.Sm-p->Kh.Sc;long GT1=0;long GT2=0;long GT3=0;long GT4=0;long GT5=0;long GT6=0;
        const 
    int Phuthu=2000;
            
    printf("                HOA DON TIEN DIEN\n");
            
    printf(" \nKy %d.Tu Ngay %d/%d/%d Den Ngay %d/%d/%d\n",Ng.SKy,Ng.D1,Ng.M1,Ng.Y1,Ng.D2,Ng.M2,Ng.Y2);
            
    printf(" Ho Va Ten: ");printf("%s",p->Kh.Ht);
            
    printf("   Day Nha :%c",p->Kh.Day);
            
    printf("   So Phong :%d\n\n",p->Kh.Sp);
                

            
    Khung_Hoadon();                               
                
    printf("|  SO CU  |  SO MOI | DNANG TT| DON GIA |THANHTIEN|\n");
            
    Khung_Hoadon();
                
    printf("|%9ld|%9ld",p->Kh.Sc,p->Kh.Sm);
        if (
    TD<=100)
        {
            
    GT1=gtien1(dg,TD);
            
    printf("|%9ld|%9ld|%9ld|\n",TD,dg[0],dg[0]*TD);
            
    Khung_Hoadon();
        }
        if (
    TD>100 && TD<=150)
        {
            
    GT2=gtien2(dg,TD);
                
    printf("|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
            
    Khung_Hoadon();
                
    printf("|         |         |%9ld|%9ld|%9ld|\n",TD-100,dg[1],(TD-100)*dg[1]);
            
    Khung_Hoadon();
        }
        if (
    TD>150 && TD<=200
        {
            
    GT3=gtien3(dg,TD);
                
    printf("|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
            
    Khung_Hoadon();
                
    printf("|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
            
    Khung_Hoadon();
                
    printf("|         |         |%9ld|%9ld|%9ld|\n",TD-150,dg[2],(TD-150)*dg[2]);
            
    Khung_Hoadon();
        }
        if(
    TD>200 && TD<=300)
        {
            
    GT4=gtien4(dg,TD);
                
    printf("|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
            
    Khung_Hoadon();
                
    printf("|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
            
    Khung_Hoadon();
                
    printf("|         |         |       50|%9ld|%9ld|\n",dg[2],50*dg[2]);
            
    Khung_Hoadon();
                
    printf("|         |         |%9ld|%9ld|%9ld|\n",TD-200,dg[3],(TD-200)*dg[3]);
            
    Khung_Hoadon();
        }
        if(
    TD>300 && TD<=350)
        {
            
    GT5=gtien5(dg,TD);
                
    printf("|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
            
    Khung_Hoadon();
                
    printf("|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
            
    Khung_Hoadon();
                
    printf("|         |         |       50|%9ld|%9ld|\n",dg[2],50*dg[2]);
            
    Khung_Hoadon();
                
    printf("|         |         |      100|%9ld|%9ld|\n",dg[3],100*dg[3]);
            
    Khung_Hoadon();
                
    printf("|         |         |%9ld|%9ld|%9ld|\n",TD-300,dg[4],(TD-300)*dg[4]);
            
    Khung_Hoadon();
        }
        if(
    TD>350)
        { 
            
    GT6=gtien6(dg,TD);
                
    printf("|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
            
    Khung_Hoadon();
                
    printf("|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
            
    Khung_Hoadon();
                
    printf("|         |         |       50|%9ld|%9ld|\n",dg[2],50*dg[2]);
            
    Khung_Hoadon();
                
    printf("|         |         |      100|%9ld|%9ld|\n",dg[3],100*dg[3]);
            
    Khung_Hoadon();
                
    printf("|         |         |       50|%9ld|%9ld|\n",dg[4],50*dg[4]);
            
    Khung_Hoadon();
                
    printf("|         |         |%9ld|%9ld|%9ld|\n",TD-350,dg[5],(TD-350)*dg[5]);
            
    Khung_Hoadon();
        }
                
    printf("|    * PHU THU *    |          |            |%9d|\n",Phuthu);
            
    Khung_Hoadon();
                
    printf("|   * TONG CONG *   |%5ld Kwh|         |%9ld|\n",TD,GT1+GT2+GT3+GT4+GT5+GT6+Phuthu);
            
    Khung_Hoadon();
    }

    //Ham Xuat Hoa Don Vao File "Ten_Khach_hang_Hoa_Don_So_Ky.txt"
    void Xuat_Hoadon(char Ten_File[15],DList l,Date Ng,long dg[],DNodep
    {
        
    FILE *fp;
        
    fp=fopen(Ten_File,"w+");
        
    long TD=p->Kh.Sm-p->Kh.Sc;
        
    long GT1=0;long GT2=0;long GT3=0;long GT4=0;long GT5=0;long GT6=0;
        const 
    int Phuthu=2000;

            
    fprintf(fp,"                HOA DON TIEN DIEN\n");
            
    fprintf(fp,"\n Ky %d.Tu Ngay %d/%d/%d Den Ngay %d/%d/%d\n",Ng.SKy,Ng.D1,Ng.M1,Ng.Y1,Ng.D2,Ng.M2,Ng.Y2);
            
    fprintf(fp," Ho Va Ten: ");printf("%s",p->Kh.Ht);
            
    fprintf(fp,"   Day Nha :%c",p->Kh.Day);
            
    fprintf(fp,"   So Phong :%d\n\n",p->Kh.Sp);

            
            
    Khung_Xuat_File_Hd(Ten_File,fp);                               
                
    fprintf(fp,"|  SO CU  |  SO MOI | DNANG TT| DON GIA |THANHTIEN|\n");
            
    Khung_Xuat_File_Hd(Ten_File,fp);
            
    fprintf(fp,"|%9ld|%9ld",p->Kh.Sc,p->Kh.Sm);
        if (
    TD<=100)
         {
            
    GT1=gtien1(dg,TD);
                
    fprintf(fp,"|%9ld|%9ld|%9ld|\n",TD,dg[0],dg[0]*TD);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
         }
        if (
    TD>100 && TD<=150)
        {
            
    GT2=gtien2(dg,TD);
                
    fprintf(fp,"|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |%9ld|%9ld|%9ld|\n",TD-100,dg[1],(TD-100)*dg[1]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
        }
      if (
    TD>150 && TD<=200
       {
            
    GT3=gtien3(dg,TD);
                
    fprintf(fp,"|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |%9ld|%9ld|%9ld|\n",TD-150,dg[2],(TD-150)*dg[2]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
        }
        if(
    TD>200 && TD<=300)
        {
          
    GT4=gtien4(dg,TD);
                
    fprintf(fp,"|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[2],50*dg[2]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |%9ld|%9ld|%9ld|\n",TD-200,dg[3],(TD-200)*dg[3]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
        }
        if(
    TD>300 && TD<=350)
        {
            
    GT5=gtien5(dg,TD);
                
    fprintf(fp,"|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[2],50*dg[2]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |      100|%9ld|%9ld|\n",dg[3],100*dg[3]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |%9ld|%9ld|%9ld|\n",TD-300,dg[4],(TD-300)*dg[4]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
        }
        if(
    TD>350)
        { 
            
    GT6=gtien6(dg,TD);
                
    fprintf(fp,"|      100|%9ld|%9ld|\n",dg[0],dg[0]*100);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[1],50*dg[1]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[2],50*dg[2]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |      100|%9ld|%9ld|\n",dg[3],100*dg[3]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |       50|%9ld|%9ld|\n",dg[4],50*dg[4]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|         |         |%9ld|%9ld|%9ld|\n",TD-350,dg[5],(TD-350)*dg[5]);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
        }

                
    fprintf(fp,"|    * PHU THU *    |          |            |%9d|\n",Phuthu);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
                
    fprintf(fp,"|   * TONG CONG *   |%5ld Kwh|         |%9ld|\n",TD,GT1+GT2+GT3+GT4+GT5+GT6+Phuthu);
            
    Khung_Xuat_File_Hd(Ten_File,fp);
       
    fclose(fp);
    }

    // Xoa Khoang Trang(Clear Space)
    void ClrS(char a[30])
    {    
        
    int d=strlen(a);
        for(
    int i=0;i<d;i++)
        {    if(
    a[i]==' '
            {    for(
    int j=i;j<d;j++)
                    
    a[j]=a[j+1];
                
    i--;
            }
        }
    }

    void Nhap_Ht(char Hoten[])
    {    
        
    printf("\nNhap Ten Can Tim:");
        
    fflush(stdin);gets(Hoten);fflush(stdin); 
        
    ClrS(Hoten);
    }
    // Hoan Vi 2 Bien THuc Kieu Du Iieu Khach Hang

    void Check_Sp(DList l,short int msp[5][21])
    {
        
    short int y;
        for(
    DNodeq=l.pHead;q!=NULL;q=q->pNext)
            {
            switch(
    q->Kh.Day)
                {
                    case 
    'A':y=0;break;
                    case 
    'B':y=1;break;
                    case 
    'C':y=2;break;
                    case 
    'D':y=3;break;
                    case 
    'E':y=4;break;
                }
        
    msp[y][q->Kh.Sp]=1;
            }
    }
    void Create_Sdp(short int msp[5][21])
    {
        for(
    short int i=0;i<5;i++)
            for(
    short int j=0;j<21;j++)
                    
    msp[i][j]=0;
    }

    void Tkiem_Lke(DList l,long dg[])
    {
        
    DNodeq;
            
    printf("\n1.Tim Khach Hang Tieu Thu Dien Cao Nhat\n");
            
    printf("2.Tim Khach Hang Tieu Thu Dien It Nhat\n");
            
    printf("3.Tim Theo Ten Khach Hang\n");
            
    printf("4.Liet Ke Cac Khach Hang Tieu Thu Dien Vuot Dinh Muc (DNTT>400)\nChon:");
                    
                switch(
    getch())
                    {
                    
                     case 
    '1':
                         {
                             
    Khung_Tieude();
                             
    q=Max_Td(l);
                             
    View_Kh(l,q,dg);
                         }
                         break;

                     case 
    '2':
                         {
                             
    Khung_Tieude();
                             
    q=Min_Td(l);
                             
    View_Kh(l,q,dg);
                         }
                         break;

                     case 
    '3':
                         {    
                             
                             
    char Hoten[30];
                             
    Nhap_Ht(Hoten);
                             
    q=TimKh(l,Hoten);
                             
                             if(
    q!=NULL)
                             {
                                 
    Khung_Tieude();
                                 
    View_Kh(l,q,dg);
                             }
                             else 
                             
    printf("Khach Hang Khong Ton Tai\n");
                         }
                         break;

                     case 
    '4':
                         {
                             
    Khung_Tieude();
                             for(
    q=l.pHead;q!=NULL;q=q->pNext)
                                if(
    q->Kh.Sm-q->Kh.Sc>400)
                                    
    View_Kh(l,q,dg);
                         }
                    } 
    // end of switch con

    }
    void Table(DList l,long dg[])
    {
        
    Khung_Tieude();
            for(
    DNodeq=l.pHead;q!=NULL;q=q->pNext)
                
    View_Kh(l,q,dg);
    }
    void Matran(DList l,short int msp[5][21])
    {
        
    short int y,d;short int a=65;
        
    printf("\t\nChung Cu Co 5 Day Nha.Moi Day Co 20 Phong\nCac O Co Khach Thue Duoc Danh Dau X\n");
                
            
    Khung_sdp();
            
    printf("|  | 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15|16|17|18|19|20|\n");
            
    Khung_sdp();
            for(
    int x=0;x<5;x++)
                {
                    
    printf("|%2c|",a); // Ke Cot Day Phong Tu A->E
                    
    for(int j=1;j<21;j++)
                        
    printf("%2c|",d=msp[x][j]>0?'X':' ');// Neu O Nao Co Khach Thue Thi Check X,Neu Khong Thi Danh Dau Khoang Trang
                    
    printf("\n");
                    
    Khung_sdp();
                        
    a++;
                }
    }

    void Sapxep(DList l,long dg[])
    {

        
    Khung_Tieude();
        for(
    DNode*p=l.pHead;p!=NULL;p=p->pNext)
        {
            for(
    DNodeq=p;q!=l.pTail;q=q->pNext)
                if((
    p->Kh.Sm-p->Kh.Sc)>(q->Kh.Sm-q->Kh.Sc))
                        
    Swap(p,q);
        
    View_Kh(l,p,dg);
        }
    }

    // Ham Menu 
    void MENU(DList l,Date Ng,long dg[],short int msp[5][21],short int &Stop)
     {
            
    printf("\n");
        
    Khung_Menu();
            
    printf("| CHON |                  CONG VIEC                      |\n");
        
    Khung_Menu();
            
    printf("|   1  | THOAT KHOI MENU                                 |\n");
        
    Khung_Menu();
            
    printf("|   2  | XEM & SUA CAC DON GIA                           |\n");
        
    Khung_Menu();
            
    printf("|   3  | TIM KHACH HANG THEO DIEU KIEN                   |\n");
        
    Khung_Menu();
            
    printf("|   4  | XEM BANG THONG KE CUA TAT CA KHACH HANG         |\n");
        
    Khung_Menu();
            
    printf("|   5  | THEM & XOA KHACH HANG VAO TRONG DANH SACH       |\n");  
        
    Khung_Menu();
            
    printf("|   6  | XEM & XUAT HOA DON TIEN DIEN CUA KHACH HANG     |\n");
        
    Khung_Menu();
            
    printf("|   7  | SAP XEP THONG TIN KH THEO DIEN NANG TIEU THU    |\n");
        
    Khung_Menu();
            
    printf("|   8  | THONG KE PHONG TRO CO KHACH THUE BANG MA TRAN   |\n");
        
    Khung_Menu();
        
    printf("\nChon:");
        switch(
    getch())
        {
            
    DNodeq;

        case 
    '1':// Thoat Menu
                
    Stop=1
                break;

            case 
    '2':    // Xem & Thay Doi Don Gia
                
    {
                    
    Xem_dg(dg);
                    
    printf("Nhan So 1 De Thay Doi Don Gia Neu Can.Nhan Phim Khac De Tu Choi\n");
                    
    short int td;
                    
    scanf("%d",&td);
                    if(
    td==1)    
                    {
                        
    Thaydoi_dg(dg);
                        
    Xuat_dg("Don_Gia.txt",dg);
                    }
                }
                break;

            case 
    '3':// Tim Kiem & Liet Ke Khach Hang
                
    Tkiem_Lke(l,dg);
                break;

            case 
    '4':    // Xem Bang Thong Ke Thong Tin Cua Tat Ca Khach Hang
                
    Table(l,dg);
                break;

                                
    //    case '5':    // Them & Xoa Khach Hang             break;

            
    case '6':    // Xem & Xuat Hoa Don Ra File "txt"
                
    {
                    
    printf("\n1.Xem Hoa Don Tien Dien\n");
                    
    printf("2.Xuat Hoa Don Tien Dien Ra File\nChon:");

                    
    char Hoten[30];
                        switch(
    getch())
                        {
                        case 
    '1':
                            {
                                
    printf("\n1.Xem Tat Ca\n2.Xem Mot Ca Nhan\n");
                                switch(
    getch())
                                {
                                case 
    '1':
                                    for(
    q=l.pHead;q!=NULL;q=q->pNext)
                                        {
                                            
    Xem_Hoadon(l,Ng,dg,q);
                                            
    printf("Xem Tiep Tuc...\n"); getch();
                                        }
                                    break;
                                case 
    '2':
                                    {
                                        
    Nhap_Ht(Hoten);
                                        
    q=TimKh(l,Hoten);
                                        if(
    q!=NULL)
                                        
    Xem_Hoadon(l,Ng,dg,q);
                                        else
                                        
    printf("Khach Hang Khong Ton Tai\n");
                                    }    
    // END of case 2 of Case 1 of CASE 6
                                
    }        // end of Swith of Case 6.1        
                            
    }        // END of Case 1 of CASE 6
                            
    break;
                        case 
    '2':
                            {
                                
                                
    printf("\n1.Xuat Tat Ca\n2.Xuat Mot Ca Nhan\n");
                                switch(
    getch())
                                {
                                case 
    '1':
                                    for(
    q=l.pHead;q!=NULL;q=q->pNext)
                                        {
                                            
    char *Name=strcat(q->Kh.Ht,"_Hoa_Don.txt");
                                            
    Xuat_Hoadon(Name,l,Ng,dg,q);
                                            
    printf("File %s Da Xuat Thanh Cong\n",Name);
                                        }
                                case 
    '2':
                                    {
                                        
    Nhap_Ht(Hoten);
                                        
    q=TimKh(l,Hoten);
                                        if(
    q!=NULL)
                                            {
                                                
    char *Name=strcat(q->Kh.Ht,"_Hoa_Don.txt");
                                                
    Xuat_Hoadon(Name,l,Ng,dg,q);
                                                
    printf("File %s Da Xuat Thanh Cong\n",Name);
                                            }
                                        else
                                        
    printf("Khach Hang Khong Ton Tai\n");
                                    }    
    // END of case 2 of Case 2 of CASE 6 OR ( CASE 6.2.2)
                                 
    }        // end of Switch 6.2
                            
    }            // END of Case 2 of CASE 6 OR ( CASE 6.2)
                        
    }                //end of Swith of CASE 6
                
    }                        // END of CASE 6                    
                
    break;

            case 
    '7':    // Sap Xep Thong Tin Khach Hang Theo Dien Nang Tieu Thu
                
    Sapxep(l,dg);            
                break;
        case 
    '8':    // Thong Ke So Phong Tro Co Khach Thue Bang Ma Tran
                
    Matran(l,msp);
                break;
        
        } 
    // END of SWITCH
        
        
    if(Stop==0// Bien dieu khien de dung Ham MENU
        
    {
        
    printf("Press any key to continue your working...\n");
        
    getch();
        
    MENU(l,Ng,dg,msp,Stop);
        }

    // END of NENU
    void main()
    {
        
    short int msp[5][21];
        
    DList l;
        
    DNodep;    
        
    Date Ng;// Ngay thang nam    
        
    long dg[6];    
        
    short int Stop=0;
        
    int n;
        
    Doc_SoKh(n);    Doc_dg(dg);
        
    CreateDList(l,n);
        
    Create_Sdp(msp);    Check_Sp(l,msp);    Doc_Date(Ng);

        if(
    Stop==0)    
        
    MENU(l,Ng,dg,msp,Stop);
        
    getch();

    Bạn nào có nâng cấp lên một cái project "bự bự' chút ,pm cho mình với nha,mình tham gia với
    Code tương đối ,nhưng cách tổ chức "dzữ" liệu chưa hợp lý...
    Mong các bạn chia sẽ để mình hoàn thiện hơn...
    Yahoo : duyphong_nguyen2005
    Gmail : ndp1007
    Thay đổi nội dung bởi ndp1007; 13-05-2009 lúc 22:08.
    Còn trời đất nhưng không còn ta mãi
    Nên buâng khuâng ta tiết cả đất trời..!
    ...từ XuDi Hidden Content
    ndp1007 is perfect

  15. Có 1 thành viên cảm ơn ndp1007 cho bài viết này:
    luu_nguyen (13-07-2011)

 

 

Quyền sử dụng

  • Bạn không thể gửi chủ đề mới
  • Bạn không thể gửi trả lời
  • Bạn không thể gửi file đính kèm
  • Bạn không thể tự sửa bài viết của mình
  •