简单的小区物业费管理系统-C语言实现

e7ad6be945f14856b71b4c9d54d57960.jpg

f282a39372eb4a0fbb25a89bb780f85b.jpg 

4f17b5ccda834cfca4f351e1ab7add01.jpg 

2ca45871e4a2489ea4f79c010f01d5b9.jpg 

b024aa16377641d3b4870e36c1917395.jpg 

 //读取住户信息

int readResidentInformation()

{

    int n=0;

    FILE *fp;

    int i;

    if((fp=fopen("住户信息.txt","r"))!=NULL)//判断文件是否打开

    {

        fscanf(fp,"%d\n",&n);

        if(n == 0)

        {

            // printf("当前住户数量为0,请添加住户信息\n");

        }else

        {

            char title[200];

            fscanf(fp,"%[^\n]",title);//读取一行

            for(i=0;i<n;i++)

            {

                fscanf(fp,"%s %s %s %s %d %d %f\n",

                       Resident[i].name,Resident[i].gender,

                       Resident[i].idCard,Resident[i].phone,&Resident[i].buildingNo,

                       &Resident[i].roomNo,&Resident[i].propertyFee);

            }

        }

    }

    fclose(fp);

    return n;

}

//存储住户信息

void saveResidentInformation(int n)

{

    FILE *fp;

    int i;

    fp=fopen("住户信息.txt","w");

    {

        fprintf(fp,"%d\n",n);

        fprintf(fp,"%-4s %-3s %-25s %-13s %-4s %-5s %-7s\n","姓名","性别","身份证号",

                "联系电话","楼号","房间号","物业费");

        for(i=0;i<n;i++)

            fprintf(fp,"%s %s %s %s %d %d %f\n",

                   Resident[i].name,Resident[i].gender,

                   Resident[i].idCard,Resident[i].phone,Resident[i].buildingNo,

                   Resident[i].roomNo,Resident[i].propertyFee);

    }

    fclose(fp);

}

 

//退出页面

void quitPage()

{

    printf("\n\n 『谢谢使用小区物业管理系统』\n\n\n\n\n");

    exit(0);

}

 

//修改住户信息

void modifyResident()

{

    int residentNum = readResidentInformation();

    printf("\n 【修改住户信息】\n\n");

    int buildingNum,roomNum;

    printf("请输入要修改住户的楼号:");

    scanf("%d",&buildingNum);

    printf("请输入要修改住户的房间号:");

    scanf("%d",&roomNum);

    int num = -1;

    for(int i=0;i<residentNum;i++)

    {

        if((Resident[i].buildingNo == buildingNum)&&(Resident[i].roomNo == roomNum))

        {

            num = i;

            break;

        }

    }

    if(num < 0)

        printf("未找到该房间号的住户信息,无法修改!\n");

    else

    {

        printf("请输入新的姓名(原姓名: %s):",Resident[num].name);

        scanf("%s",Resident[num].name);

        printf("请输入新的性别(原性别: %s): ",Resident[num].gender);

        scanf("%s", Resident[num].gender);

        printf("请输入新的身份证号(原身份证号: %s): ", Resident[num].idCard);

        scanf("%s", Resident[num].idCard);

        printf("请输入新的联系电话(原联系电话: %s): ", Resident[num].phone);

        scanf("%s", Resident[num].phone);

        printf("请输入新的物业费(原物业费: %.2f): ", Resident[num].propertyFee);

        scanf("%f", &Resident[num].propertyFee);

        saveResidentInformation(residentNum);

        printf("\n\n修改住户信息成功\n");

    }

    printf("\n\n是否要继续操作?1.是 2.否\n");

    int newChoice;

    scanf("%d",&newChoice);

    if(newChoice == 1)

        managementPage();

    else

        quitPage();

}

//删除住户

void deleteResident()

{

    int residentNum = readResidentInformation();

    int paymentRecordCount = readPaymentRecord();

    printf("\n 【删除住户】\n\n");

    int buildingNum,roomNum;

    printf("请输入要删除住户的楼号:");

    scanf("%d",&buildingNum);

    printf("请输入要删除住户的房间号:");

    scanf("%d",&roomNum);

    //删除住户信息

    int num = -1;

    int i=0;

    while(i<residentNum)

    {

        if((Resident[i].buildingNo == buildingNum)&&(Resident[i].roomNo == roomNum))

        {

            for(int j=i;j<residentNum-1;j++)

                Resident[j] = Resident[j+1];

            i--;

            residentNum--;

            num = 1;

        }

        i++;

    }

    if(num < 0)

        printf("未找到该房间号的住户信息,无法删除!\n\n");

    else

    {

        saveResidentInformation(residentNum);

        printf("\n删除住户信息成功\n");

    }

    //删除住户缴费记录

    int found = -1;

    int m = 0;

    while(m<paymentRecordCount)

    {

        if((PaymentRecord[m].residentBuildingNo == buildingNum)&&(PaymentRecord[m].residentRoomNo == roomNum))

        {

            for(int n=m;n<paymentRecordCount-1;n++)

                PaymentRecord[n] = PaymentRecord[n+1];

            m--;

            paymentRecordCount--;

            found = 1;

        }

        m++;

    }

    if(found < 0)

        printf("未找到该房间号的缴费记录,无法删除!\n\n");

    else

    {

        savePaymentRecord(paymentRecordCount);

        printf("\n删除住户缴费记录成功\n");

    }

    printf("\n\n是否要继续操作?1.是 2.否\n");

    int newChoice;

    scanf("%d",&newChoice);

    if(newChoice == 1)

        managementPage();

    else

        quitPage();

}

 

//查询住户

void searchResident()

{

    int residentNum = readResidentInformation();

    printf("\n 【查询住户】\n\n");

    int buildingNum,roomNum;

    printf("请输入要查询住户的楼号:");

    scanf("%d",&buildingNum);

    printf("请输入要查询住户的房间号:");

    scanf("%d",&roomNum);

    int num = -1;

    for(int i=0;i<residentNum;i++)

    {

        if((Resident[i].buildingNo == buildingNum)&&(Resident[i].roomNo == roomNum))

        {

            num = i;

            break;

        }

    }

    if(num < 0)

        printf("未找到该房间号的住户信息!\n");

    else

    {

        printf("\n 【住户信息】\n\n");

        printf("姓名: %s\n", Resident[num].name);

        printf("性别: %s\n", Resident[num].gender);

        printf("身份证号: %s\n", Resident[num].idCard);

        printf("联系电话: %s\n", Resident[num].phone);

        printf("楼号: %d\n", Resident[num].buildingNo);

        printf("房间号: %d\n", Resident[num].roomNo);

        printf("物业费: %.2f\n", Resident[num].propertyFee);

    }

    printf("\n\n是否要继续操作?1.是 2.否\n");

    int newChoice;

    scanf("%d",&newChoice);

    if(newChoice == 1)

        managementPage();

    else

        quitPage();

}

//添加缴费记录

void addPaymentRecord()

{

    int paymentRecordCount = readPaymentRecord();

    int residentNum = readResidentInformation();

    if(paymentRecordCount > MAX_PAYMENT_RECORDS)

    {

        printf("缴费记录数量已满,无法添加!\n");

    }else

    {

        printf("\n 【添加缴费记录】\n\n");

        int buildingNum,roomNum;

        printf("请输入要添加缴费记录住户的楼号:");

        scanf("%d",&buildingNum);

        printf("请输入要添加缴费记录住户的房间号:");

        scanf("%d",&roomNum);

        int num = -1;

        for(int i=0;i<residentNum;i++)

        {

            if((Resident[i].buildingNo == buildingNum)&&(Resident[i].roomNo == roomNum))

            {

                num = i;

                break;

            }

        }

        if(num < 0)

            printf("未找到该房间号的住户信息,无法添加缴费记录!\n");

        else

        {

            printf("请输入缴费金额:");

            scanf("%f",&PaymentRecord[paymentRecordCount].paymentAmount);

            printf("请输入缴费日期(格式: yyyy-MM-dd): ");

            scanf("%s",PaymentRecord[paymentRecordCount].paymentDate);

            PaymentRecord[paymentRecordCount].residentBuildingNo = buildingNum;

            PaymentRecord[paymentRecordCount].residentRoomNo = roomNum;

            paymentRecordCount++;

            savePaymentRecord(paymentRecordCount);

            printf("添加缴费记录成功\n");

        }

    }

    printf("\n\n是否要继续操作?1.是 2.否\n");

    int newChoice;

    scanf("%d",&newChoice);

    if(newChoice == 1)

        managementPage();

    else

        quitPage();

}

 

//读取缴费记录

int readPaymentRecord()

{

    int n=0;

    FILE *fp;

    int i;

    if((fp=fopen("缴费记录.txt","r"))!=NULL)//判断文件是否打开

    {

        fscanf(fp,"%d\n",&n);

        if(n == 0)

        {

            // printf("当前缴费记录为0,请添加缴费记录\n");

        }else

        {

            char title[200];

            fscanf(fp,"%[^\n]",title);//读取一行

            for(i=0;i<n;i++)

            {

                fscanf(fp,"%d %d %f %s\n",

                       &PaymentRecord[i].residentBuildingNo,&PaymentRecord[i].residentRoomNo,

                       &PaymentRecord[i].paymentAmount,PaymentRecord[i].paymentDate);

            }

        }

    }

    fclose(fp);

    return n;

}

//存储缴费记录

void savePaymentRecord(int n)

{

    FILE *fp;

    int i;

    fp=fopen("缴费记录.txt","w");

    {

        fprintf(fp,"%d\n",n);

        fprintf(fp,"%-4s %-5s %-7s %-7s\n","楼号","房间号","缴费金额","缴费日期");

        for(i=0;i<n;i++)

            fprintf(fp,"%d %d %.2f %s\n",

                    PaymentRecord[i].residentBuildingNo,PaymentRecord[i].residentRoomNo,

                    PaymentRecord[i].paymentAmount,PaymentRecord[i].paymentDate);

    }

    fclose(fp);

}

 

//查询缴费记录

void searchPaymentRecord()

{

    printf("\n 【查询缴费记录】\n\n");

    int buildingNum,roomNum;

    printf("请输入要查询缴费记录住户的楼号:");

    scanf("%d",&buildingNum);

    printf("请输入要查询缴费记录住户的房间号:");

    scanf("%d",&roomNum);

    printf("\n\n");

    int residentNum = readResidentInformation();

    int paymentRecordCount = readPaymentRecord();

    int num = -1;

    for(int i=0;i<residentNum;i++)

    {

        if((Resident[i].buildingNo == buildingNum)&&(Resident[i].roomNo == roomNum))

        {

            num = i;

            break;

        }

    }

    if(num < 0)

    {

        printf("未找到该住户信息!\n");

    }

    else

    {

        int found = -1;

        for(int i=0;i<paymentRecordCount;i++)

        {

            if((PaymentRecord[i].residentBuildingNo == buildingNum)&&(PaymentRecord[i].residentRoomNo == roomNum))

            {

                printf("住户楼号:%d ",PaymentRecord[i].residentBuildingNo);

                printf("住户房间号:%d ",PaymentRecord[i].residentRoomNo);

                printf("缴费金额:%.2f ",PaymentRecord[i].paymentAmount);

                printf("缴费日期:%s\n",PaymentRecord[i].paymentDate);

                found = 1;

            }

        }

        if(found < 0)

            printf("未找到该住户的缴费记录!\n");

    }

    printf("\n\n是否要继续操作?1.是 2.否\n");

    int newChoice;

    scanf("%d",&newChoice);

    if(newChoice == 1)

        managementPage();

    else

        quitPage();

}

//查询欠费

void checkArrears()

{

    system("cls");

    int found = 0;

    int residentNum = readResidentInformation();

    int paymentRecordCount = readPaymentRecord();

    for(int i=0;i<residentNum;i++)

    {

        float paidAmount = 0;

        for(int j=0;j<paymentRecordCount;j++)

        {

            if((PaymentRecord[j].residentBuildingNo == Resident[i].buildingNo)&&(PaymentRecord[j].residentRoomNo == Resident[i].roomNo))

            {

                paidAmount += PaymentRecord[j].paymentAmount;

            }

        }

        if(paidAmount < Resident[i].propertyFee)

        {

            printf("楼号:%d 房间号:%d 住户%s欠费金额%.2f\n",Resident[i].buildingNo,Resident[i].roomNo,

                   Resident[i].name,Resident[i].propertyFee-paidAmount);

            found = 1;

        }

    }

    if(!found)

        printf("没有住户欠费!\n");

    printf("\n\n是否要继续操作?1.是 2.否\n");

    int newChoice;

    scanf("%d",&newChoice);

    if(newChoice == 1)

        managementPage();

    else

        quitPage();

}

下边是调试用的txt文件:

住户信息.txt

316e3b338262421ca1bf85059e57f8dd.jpg

 缴费记录.txt

2a04b0733c2e4166bdeb312390746ddd.jpg

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值