一. 题目需求
1.合理使用链表,文件(合理使用链表,如在插入,删除时使用合理,其它场合未必合理)。
2.新住户信息的添加(户主的姓名,性别,身份证号,俩系电话,楼号,单元号,房号,平方米数,每平方米物业的价格,应缴物业费及备注信息)
3.修改住户信息的功能。
4.删除住户信息的功能。
5.物业费的生成。
6.缴费功能。根据用户缴纳的金额,修改“应缴纳物业费”。
7.统计功能。分为楼层和欠费额
8.用菜单进行管理
9.只有正确输入用户名密码才能使用此系统。
10.所有内容能够保存到文件中。下次进入系统是从文件中读取原有信息。
二.项目设计
大概的划分为了三个板块:登录界面的实现,住户功能的实现,小区物业管理员页面的实现,根据输入不同的账号密码,会登录进入不同用户的页面。
需要实现的功能函数如下:
1.菜单显示
2.登录系统
3.不同用户的页面跳转
4.新用户注册
5.添加修改删除个人信息
6.物业费统计
7.自动生成每月物业费
8.查询个人信息
9.查询当月物业费,物业费缴费
10.光标的移动
11.文件数据的读取,删除,增添
代码展示如下:
//管理员的账号密码在代码中已经定义好,如需更换,请直接在代码中更换
//用Dev-C++编译运行
//版权:CUIT-智科201-JJ
//请勿直接成为CV工程师
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
struct node{
long long account;//账号
char key[100];//密码
char name[200];//名字
char sex[100];//性别
long long Id_card;//身份证
long long tel_number;//电话号码
long long building_number;//楼号
long long room_number;//房号
long long unit_number;//单元号
double square_meter;//平方米数
double square_meter_money;//每平方米价格
double property_cost;//应缴物业费
struct node *next;
};
typedef struct node *Person;
//菜单函数
void menu_main();//(完成)(调试完成)
void menu_property();//(完成) (调试完成)
void menu_owners();//(完成) (调试完成)
void menu_registration();//(完成) (调试完成)
void menu_add_information();//(完成) (调试完成)
void menu_cost();//物业费查询菜单(完成)(调试完成)
//登录页面函数
int input_number(long long *p);//登录页面账号输入(完成) (调试完成)
int input_password(long long *p,char *q);//登录页面密码输入 (完成) (调试完成)
int login(long long *p,char *q);//登录系统 (完成) (调试完成)
//进入不同用户类型页面
int property(Person *L);//进入物业管理页面(完成) (调试完成)
int owners(Person *L,long long *p,char *q);//进入业主页面(完成) (调试完成)
//物业管理模块功能函数
int registration();//新用户注册 (完成) (调试完成)
int add_information();//添加个人信息函数(完成) (调试完成)
void modify_information();//修改个人信息函数(完成) (调试完成)
void delete_information();//删除用户信息(完成) (调试完成)
void statistic(Person *L);//统计功能(完成)(调试完成)
void total_people(Person *L);//所有未缴费的人 (完成)(调试完成)
void sort_people(Person *L);//已经排好顺序的还未缴费的人(完成) (调试完成)
void time_money(Person *L);//生成物业费 (完成)(调试完成)
//住户及租户模块功能函数
void information(Person *L,long long *p);//查询个人信息函数(完成)(调试完成)
void give_money(Person *L,long long *p);//物业费查询缴费函数(完成) (调试完成)
void print_number();//显示物业电话号码 (完成)(调试完成)
//辅助函数
void gotoposition(int x,int y);//光标位置的挪动 (调试完成)
void get(Person *L);//从文件中得到数据到链表中 (调试完成)
void free_infor(Person *L); //释放链表要的数据空间 (调试完成)
void swap(Person *newp,Person *newq);//进行链表数据的交换(完成)(调试完成)
int main(){
system("color 3e");//控制终端颜色
Person L=NULL,newp;
get(&L);//读取文件中的数据
int ch;
long long number1;
char password1[30]={""};
char *q=password1;//存储输入的密码
long long *p=&number1;//存储输入的账号
while(1){
menu_main();
gotoposition(27,10);
scanf("%d",&ch);
if(ch==1)property(&L);//进入物业管理页面
else if(ch==2)owners(&L,p,q);//进入业主页面
else if(ch==3){
gotoposition(1,14);
printf("欢迎下次使用!\n");
free_infor(&L);//释放调用的链表的空间
return 0;//退出系统
}
}
system("pause");
}
//主菜单页面
void menu_main(){
system("cls");
printf("‖****************************************************‖\n");
printf("‖ 欢迎进入JJ小区物业费管理系统! ‖\n");
printf("‖****************************************************‖\n");
printf("‖ ‖\n");
printf("‖ 1.物业管理页面 ‖\n");
printf("‖ ‖\n");
printf("‖ 2.业主页面 ‖\n");
printf("‖ ‖\n");
printf("‖ 3.退出系统 ‖\n");
printf("‖ ‖\n");
printf("‖ 请输入选择序号: ‖\n");
printf("‖ ‖\n");
printf("‖****************************************************‖\n");
}
//物业管理页面
void menu_property(){
system("cls");
printf("‖****************************************************‖\n");
printf("‖ 物业管理页面 ‖\n");
printf("‖****************************************************‖\n");
printf("‖ ‖\n");
printf("‖ 1.住户信息修改 ‖\n");
printf("‖ ‖\n");
printf("‖ 2.物业费查询 ‖\n");
printf("‖ ‖\n");
printf("‖ 3.新住户注册 ‖\n");
printf("‖ ‖\n");
printf("‖ 4.生成物业费 ‖\n");
printf("‖ ‖\n");
printf("‖ 5.删除住户信息 ‖\n");
printf("‖ ‖\n");
printf("‖ 6.退出当前账号 ‖\n");
printf("‖ ‖\n");
printf("‖ 请输入选择序号: ‖\n");
printf("‖ ‖\n");
printf("‖****************************************************‖\n");
}
void menu_owners(){
system("cls");
printf("‖****************************************************‖\n");
printf("‖ 业主页面 ‖\n");
printf("‖****************************************************‖\n");
printf("‖ ‖\n");
printf("‖ 1.缴费功能 ‖\n");
printf("‖ ‖\n");
printf("‖ 2.住户信息查看 ‖\n");
printf("‖ ‖\n");
printf("‖ 3.退出当前账号 ‖\n");
printf("‖ ‖\n");
printf("‖ 请输入选择序号: ‖\n");
printf("‖ ‖\n");
printf("‖****************************************************‖\n");
gotoposition(37,11);
print_number(); //打印物业电话号码
}
void menu_registration(){
system("cls");
printf("‖****************************************************‖\n");
printf("‖ 欢迎注册JJ小区物业费管理系统登录账号 ‖\n");
printf("‖****************************************************‖\n");
printf("‖ 请将以下内容全部填写完成: ‖\n");
printf("‖ ‖\n");
printf("‖ 1.登录账号: 2.登录密码: ‖\n");
printf("‖ ‖\n");
printf("‖ 3.住户姓名: 4.性别: ‖\n");
printf("‖ ‖\n");
printf("‖ 5.身份证号: 6.联系电话: ‖\n");
printf("‖ ‖\n");
printf("‖ 7.楼号: 8.单元号: ‖\n");
printf("‖ ‖\n");
printf("‖ 9.房号: 10.平方米数: ‖\n");
printf("‖ ‖\n");
printf("‖ 11.每平方米物业价格: ‖\n");
printf("‖ ‖\n");
printf("‖****************************************************‖\n");
}
void menu_modify_information(){
system("cls");
printf("‖****************************************************‖\n");
printf("‖ 请输入需要修改信息的序号: ‖\n");
printf("‖ ‖\n");
printf("‖ 1.密码 2.住户姓名 ‖\n");
printf("‖ ‖\n");
printf("‖ 3.性别 4.身份证号 ‖\n");
printf("‖ ‖\n");
printf("‖ 5.联系电话 6.楼号 ‖\n");
printf("‖ ‖\n");
printf("‖ 7.单元号 8.房号 ‖\n");
printf("‖ ‖\n");
printf("‖ 9.平方米数 10.每平方米物业价格 ‖\n");
printf("‖ ‖\n");
printf("‖ 请在此处输入: ‖\n");
printf("‖ ‖\n");
printf("‖****************************************************‖\n");
}
void menu_cost(){
system("cls");
printf("‖**********************************************************‖\n");
printf("‖ 1.查看所有物业费未缴人员 ‖\n");
printf("‖ ‖\n");
printf("‖ 2.按照物业费欠费由高到低查看 ‖\n");
printf("‖ ‖\n");
printf("‖ 3.返回上级页面 ‖\n");
printf("‖ ‖\n");
printf("‖ 请输入选择的序号: ‖\n");
printf("‖ ‖\n");
printf("‖**********************************************************‖\n");
}
//此时进入物业管理页面账号密码的输入,并进行判断
//如果账号密码判断正确,则进入下一个函数模块
//否则重新返回开始页面
//p,q是为了存储输入进去的账号密码
int property(Person *L){
system("cls");
printf("‖***************************************‖\n");
printf("‖ 账号: ‖\n");
printf("‖ ‖\n");
printf("‖ 密码: ‖\n");
printf("‖ ‖\n");
printf("‖***************************************‖\n");
int judgelogin=0;
long long s=1290924026;//管理员账号
char s1[30]={"13990334628abc"};//管理员密码
long long x=0;
char x1[30];
gotoposition(10,1);
scanf("%lld",&x);
gotoposition(10,3);
scanf("%s",x1);
if(s==x&&strcmp(s1,x1)==0){
judgelogin=1;
}
if(judgelogin==0){
return FALSE;
}
else{
while(1){
menu_property();
int ch=0;
gotoposition(27,16);
scanf("%d",&ch);
if(ch==1)modify_information();//修改住户信息
else if(ch==2)statistic(L);//统计物业费
else if(ch==3)registration();//注册新用户
else if(ch==4)time_money(L);//生虫物业费
else if(ch==5)delete_information();
else if(ch==6)return FALSE;//返回上一个页面
}
}
}
//此时进入户主页面账号密码的输入,并进行判断
//如果账号密码判断正确,则进入下一个函数模块
//否则重新返回开始页面
int owners(Person *L,long long *p,char *q){
int judgelogin=0;
judgelogin=login(p,q);
if(judgelogin==0){
return FALSE;
}
else{
while(1){
menu_owners();
int ch;
gotoposition(27,10);
scanf("%d",&ch);
if(ch==1)give_money(L,p); //缴费
else if(ch==2)information(L,p);//个人信息查看
else if(ch==3)return FALSE;
}
}
}
//登录页面输入的账号,与账号.txt文档里面的账号一一对应,查看是否有相同的账号,有,则返回TRUE,反之则返回FALSE
//若返回FALSE,说明了这个账号并不合法,不存在于数据库中
//p用于存放账号
int input_number(long long *p){
char s2[20];
long long s=0,s1=0;
scanf("%lld",&s);
*p=s;//将输入的数据保存下来
FILE *fp;
fp=fopen("D:\\工程实践1\\账号密码.txt","r");
if(fp==NULL){
printf("open is error!\n");
exit(0);
}
while(fscanf(fp,"%lld %s",&s1,s2)==2){
if(s==s1){
fclose(fp);
return TRUE;
}
}
fclose(fp);
return FALSE;
}
//登录页面输入的密码,与密码.txt里面的密码一一比较,如果有相同的则返回TRUE,否则返回FALSE
//返回FALSE,则说明该密码错误,即不合法
//q用于存放密码
int input_password(long long *p,char *q){
char s[20],s2[20];
long long s1=0;
scanf("%s",s);
strcpy(q,s);//讲输入的数据保存下来
FILE *fp;
fp=fopen("D:\\工程实践1\\账号密码.txt","r");
if(fp==NULL){
printf("open is error!\n");
exit(0);
}
while(fscanf(fp,"%lld %s",&s1,s2)==2){
if(strcmp(s,s2)==0&&s1==(*p)){
fclose(fp);
return TRUE;
}
}
fclose(fp);
return FALSE;
}
//此函数是账号密码输入函数,显示账号密码输入界面,输入并判断账号密码的正确性
//如果输入正确,则返回TRUE,否则返回FALSE
int login(long long *p,char *q){
int x1=0,x2=0;
int judge=0;
system("cls");
printf("‖***************************************‖\n");
printf("‖ 账号: ‖\n");
printf("‖ ‖\n");
printf("‖ 密码: ‖\n");
printf("‖ ‖\n");
printf("‖***************************************‖\n");
gotoposition(10,1);//光标挪动到账号后面
x1=input_number(p);
gotoposition(10,3);//光标挪动到密码后面
x2=input_password(p,q);
if(x1==1&&x2==1)judge=1;
if(judge==1){
gotoposition(24,4);
printf("登录成功!\n");
return TRUE;
}
else{
gotoposition(24,4);
printf("账号密码输入错误!\n");
return FALSE;
}
}
//注册账号入口 ,里面调用的注册菜单函数和信息添加函数
int registration(){
menu_registration();
add_information();
return 0;
}
//进行信息添加 ,在输入添加信息的同时,对文件的里面的数据进行改变
int add_information(){
char s1[20]={""},s2[20]={""},s3[2]={""};
long long s,s6,s7,s8;
long long s4,s5;
double s9=0,s10=0;
long long x;
char x1[ 20]={"123"};
gotoposition(15,5);
scanf("%lld",&s);//先输入一个账号,进行判断确定该账号不重复以后才继续输入
FILE *fp,*fp1,*fp2,*fp3;
fp3=fopen("D:\\工程实践1\\账号密码.txt","r");
//判断文件是否打开成功
if(fp3==NULL){
system("cls");
printf("open is error!");
getchar();
exit(0);
}
//对文件中的数据进行读取,判断该账号是否存在
while(fscanf(fp3,"%lld %s",&x,x1)==2){
if(s==x){
system("cls");
printf("该账号已经存在!\n");
return 0;
}
}
fclose(fp3);
//打开需要修改数据的文件
fp=fopen("D:\\工程实践1\\小区物业.txt","a+");
fp1=fopen("D:\\工程实践1\\账号密码.txt","a+");
fp2=fopen("D:\\工程实践1\\小区物业费.txt","a+");
gotoposition(42,5);
scanf("%s",s1);//添加密码
gotoposition(15,7);
scanf("%s",s2);//添加姓名
gotoposition(37,7);
scanf("%s",s3);//添加性别
gotoposition(15,9);
scanf("%lld",&s4);//添加身份证
gotoposition(41,9);
scanf("%lld",&s5);//添加电话
gotoposition(11,11);
scanf("%lld",&s6);//添加楼号
gotoposition(40,11);
scanf("%lld",&s7);//添加单元号
gotoposition(11,13);
scanf("%lld",&s8);//添加房号
gotoposition(42,13);
scanf("%lf",&s9);//添加平方米数
gotoposition(26,15);
scanf("%lf",&s10);//添加每平方米价格
//将数据存放到文件中去
fprintf(fp,"%lld %s %s %s %lld %lld %lld %lld %lld %.3lf %.3lf\n",s,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10);
fprintf(fp1,"%lld %s\n",s,s1);
fprintf(fp2,"%lld %s %.3lf\n",s,s1,s9*s10);
fclose(fp);
fclose(fp1);
fclose(fp2);
return 0;
}
//对用谷信息的修改,修改的同时会对文件中的数据进行修改
//同时调用了修改菜单的函数
void modify_information(){
menu_modify_information();
int ch;
gotoposition(18,13);
scanf("%d",&ch);
system("cls");
printf("‖***************************************‖\n");
printf("‖ 请输入账号: ‖\n");
printf("‖ ‖\n");
printf("‖ 请输入密码: ‖\n");
printf("‖ ‖\n");
printf("‖ 请输入新的信息: ‖\n");
printf("‖ ‖\n");
printf("‖***************************************‖\n");
char s1[20]={""},s2[20]={""};
long long s;
long long num1;
double num;
gotoposition(16,1);
scanf("%lld",&s);//输入账号
gotoposition(16,3);
scanf("%s",s1);//输入密码
gotoposition(20,5);
if(ch==1||ch==2||ch==3){
scanf("%s",s2);
}
else if(ch==9||ch==10){
scanf("%lf",&num);
}
else{
scanf("%lld",&num1);
}
FILE *fp1,*fp2;
char x1[30],x2[30],x3[20];
long long x,x6,x7,x8;
long long x4,x5;
double x9,x10;
int res=0;
if(ch==1){
fp1=fopen("D:\\工程实践1\\账号密码.txt","r");
fp2=fopen("D:\\工程实践1\\1.txt","w");
while(fscanf(fp1,"%lld %s",&x,x1)==2){
if(x==s&&strcmp(s1,x1)==0){
fprintf(fp2,"%lld %s\n",x,s2);
}
else{
fprintf(fp2,"%lld %s\n",x,x1);
}
}
fclose(fp1);
fclose(fp2);
//删出文件
remove("D:\\工程实践1\\账号密码.txt");
//文件的重命名
res=rename("D:\\工程实践1\\1.txt","D:\\工程实践1\\账号密码.txt");
gotoposition(4,9);
if(res==0)printf("修改成功!\n");
}
fp1=fopen("D:\\工程实践1\\小区物业费.txt","r");
fp2=fopen("D:\\工程实践1\\1.txt","w");
while(fscanf(fp1,"%lld %s %lf",&x,x1,&x9)==3){
if(x==s&&strcmp(s1,x1)==0){
fprintf(fp2,"%lld %s %.3lf\n",x,s2,x9);
}
else{
fprintf(fp2,"%lld %s %.3lf\n",x,x1,x9);
}
}
fclose(fp1);
fclose(fp2);
remove("D:\\工程实践1\\小区物业费.txt");
res=rename("D:\\工程实践1\\1.txt","D:\\工程实践1\\小区物业费.txt");
gotoposition(4,9);
if(res==0)printf("修改成功!\n");
fp1=fopen("D:\\工程实践1\\小区物业.txt","r");
fp2=fopen("D:\\工程实践1\\1.txt","w");
//文件数据的存放,查找修改的数据在文件中的位置,在此之前的数据存放到新的文件中去;
//然后将新的数据存放到新的文件对应的位置
while(fscanf(fp1,"%lld %s %s %s %lld %lld %lld %lld %lld %lf %lf",&x,x1,x2,x3,&x4,&x5,&x6,&x7,&x8,&x9,&x10)==11){
if(s==x&&strcmp(s1,x1)==0){
int n;
n=ch;
int count=0;
while(count<n){
if(count==0)fprintf(fp2,"%lld",x);
else if(count==1)fprintf(fp2," %s",x1);
else if(count==2)fprintf(fp2," %s",x2);
else if(count==3)fprintf(fp2," %s",x3);
else if(count==4)fprintf(fp2," %lld",x4);
else if(count==5)fprintf(fp2," %lld",x5);
else if(count==6)fprintf(fp2," %lld",x6);
else if(count==7)fprintf(fp2," %lld",x7);
else if(count==8)fprintf(fp2," %lld",x8);
else if(count==9)fprintf(fp2," %.3lf",x9);
count++;
}
if(count!=10)fprintf(fp2," %s",s2);
else fprintf(fp2," %s\n",s2);
count++;
//将原文件剩余的数据存放到新的文件中去
while(count<=10){
if(count==1)fprintf(fp2," %s",x1);
else if(count==2)fprintf(fp2," %s",x2);
else if(count==3)fprintf(fp2," %s",x3);
else if(count==4)fprintf(fp2," %lld",x4);
else if(count==5)fprintf(fp2," %lld",x5);
else if(count==6)fprintf(fp2," %lld",x6);
else if(count==7)fprintf(fp2," %lld",x7);
else if(count==8)fprintf(fp2," %lld",x8);
else if(count==9)fprintf(fp2," %.3lf",x9);
else if(count==10)fprintf(fp2," %.3lf\n",x10);
count++;
}
}
else{
fprintf(fp2,"%lld %s %s %s %lld %lld %lld %lld %lld %.3lf %.3lf\n",x,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10);
}
}
fclose(fp1);
fclose(fp2);
//删除原文件
remove("D:\\工程实践1\\小区物业.txt");
//将新文件改名为原文件
res=rename("D:\\工程实践1\\1.txt","D:\\工程实践1\\小区物业.txt");
gotoposition(4,9);
if(res==0)printf("修改成功!\n");
}
//文件信息的删除,直接输入账号,直接删除该账号在系统中的所有信息,对应的文件中的信息同时也全部删除;
void delete_information(){
system("cls");
printf("‖**********************************************************‖\n");
printf("‖ ‖\n");
printf("‖ 输入需要删除用户的账号: ‖\n");
printf("‖ ‖\n");
printf("‖**********************************************************‖\n");
gotoposition(27,2);
char x1[30],x2[30],x3[30];
long long x,x6,x7,x8;
long long x4,x5;
int s;
double x9,x10;
double num;
scanf("%lld",&s);
FILE *fp1,*fp2;
fp1=fopen("D:\\工程实践1\\小区物业.txt","r");
fp2=fopen("D:\\工程实践1\\1.txt","w");
//找到该账号以后直接跳过此次对文件的输入,这样数据就不会在新的文件中存在
while(fscanf(fp1,"%lld %s %s %s %lld %lld %lld %lld %lld %lf %lf",&x,x1,x2,x3,&x4,&x5,&x6,&x7,&x8,&x9,&x10)==11){
if(s==x){
;
}
else{
fprintf(fp2,"%lld %s %s %s %lld %lld %lld %lld %lld %.3lf %.3lf\n",x,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10);
}
}
fclose(fp1);
fclose(fp2);
remove("D:\\工程实践1\\小区物业.txt");
rename("D:\\工程实践1\\1.txt","D:\\工程实践1\\小区物业.txt");
fp1=fopen("D:\\工程实践1\\小区物业费.txt","r");
fp2=fopen("D:\\工程实践1\\1.txt","w");
while(fscanf(fp1,"%lld %s %lf",&x,x1,&num)==3){
if(s==x){
;
}
else{
fprintf(fp2,"%lld %s %.3lf\n",x,x1,num);
}
}
fclose(fp1);
fclose(fp2);
remove("D:\\工程实践1\\小区物业费.txt");
rename("D:\\工程实践1\\1.txt","D:\\工程实践1\\小区物业费.txt");
fp1=fopen("D:\\工程实践1\\账号密码.txt","r");
fp2=fopen("D:\\工程实践1\\1.txt","w");
while(fscanf(fp1,"%lld %s",&x,x1)==2){
if(s==x){
;
}
else{
fprintf(fp2,"%lld %s\n",x,x1);
}
}
fclose(fp1);
fclose(fp2);
remove("D:\\工程实践1\\账号密码.txt");
rename("D:\\工程实践1\\1.txt","D:\\工程实践1\\账号密码.txt");
}
//查看用户的信息,将现有链表的空间释放,在重新从文件中读取数据,便于得到最新的数据
void information(Person *L,long long *p){
free_infor(L);//释放空间
get(L);//重新读取数据
Person newp;
newp=*L;
while(newp){
if(newp->account==(*p)){
//找到了此用户
system("cls");
printf("‖**********************************************************‖\n");
printf("‖ ×××用户信息: ‖\n");
printf("‖ ‖\n");
printf("‖ 1.姓名: 2.性别: ‖\n");
printf("‖ ‖\n");
printf("‖ 3.身份证号: ‖\n");
printf("‖ ‖\n");
printf("‖ 4.联系电话: ‖\n");
printf("‖ ‖\n");
printf("‖ 5.楼号: 6.单元号: ‖\n");
printf("‖ ‖\n");
printf("‖ 7.房号: 8.平方米数: ‖\n");
printf("‖ ‖\n");
printf("‖ 9.每平方米物业价格: ‖\n");
printf("‖ ‖\n");
printf("‖ 10.未缴物业费: ‖\n");
printf("‖ ‖\n");
printf("‖**********************************************************‖\n");
gotoposition(12,3);
printf("%s",newp->name);
gotoposition(40,3);
printf("%s",newp->sex);
gotoposition(15,5);
printf("%lld",newp->Id_card);
gotoposition(15,7);
printf("%lld",newp->tel_number);
gotoposition(12,9);
printf("%lld",newp->building_number);
gotoposition(42,9);
printf("%lld",newp->unit_number);
gotoposition(12,11);
printf("%lld",newp->room_number);
gotoposition(43,11);
printf("%.3lf",newp->square_meter);
gotoposition(23,13);
printf("%.3lf",newp->square_meter_money);
gotoposition(18,15);
printf("%.3lf",newp->property_cost);
break;
}
newp=newp->next;
}
gotoposition(0,19);
printf("输入1返回上一界面\n");
int ch=0;
while(ch!=1){
scanf("%d",&ch);
}
}
//物业费缴费,同时也要先释放链表空间,在重新读入新的数据进去,更新数据
void give_money(Person *L,long long *p){
free_infor(L);
get(L);
system("cls");
printf("‖**********************************************************‖\n");
printf("‖ 当前未缴物业费: ‖\n");
printf("‖ ‖\n");
printf("‖ 1.缴费 2.退出 ‖\n");
printf("‖ ‖\n");
printf("‖ 输入选择序号: ‖\n");
printf("‖ ‖\n");
printf("‖**********************************************************‖\n");
Person newp;
newp=*L;
//找到对应的账号,便于操作
while(newp){
if(newp->account==(*p)){
gotoposition(22,1);
printf("%.3lf",newp->property_cost);
break;
}
newp=newp->next;
}
int ch=0;
while(ch!=1&&ch!=2){
gotoposition(20,5);
scanf("%d",&ch);
}
if(ch==2)return;
if(ch==1){
system("cls");
printf("‖**********************************************************‖\n");
printf("‖ ‖\n");
printf("‖ 请输入缴费金额: ‖\n");
printf("‖ ‖\n");
printf("‖ ‖\n");
printf("‖ ‖\n");
printf("‖ ‖\n");
printf("‖**********************************************************‖\n");
}
gotoposition(20,2);
double money=0,cost=0;
scanf("%lf",&money);
gotoposition(4,5);
newp->property_cost-=money;
printf("缴费成功!当前物业费欠额:%.3lf",newp->property_cost);
FILE *fp1,*fp2;
fp1=fopen("D:\\工程实践1\\小区物业费.txt","r");
fp2=fopen("D:\\工程实践1\\1.txt","w");
long long x;
char x1[20];
double x2=0;
//找到文件中该账号的位置,然后对物业费进行修改
while(fscanf(fp1,"%lld %s %lf",&x,x1,&x2)==3){
if(x==newp->account){
fprintf(fp2,"%lld %s",x,x1);
fprintf(fp2," %.3lf\n",newp->property_cost);
}
else{
fprintf(fp2,"%lld %s %.3lf\n",x,x1,x2);
}
}
fclose(fp1);
fclose(fp2);
remove("D:\\工程实践1\\小区物业费.txt");
rename("D:\\工程实践1\\1.txt","D:\\工程实践1\\小区物业费.txt");
}
//物业费生成函数,调用函数后,直接对每个账号对应生成这个月的物业费
void time_money(Person *L){
free_infor(L);
get(L);
Person newp;
newp=*L;
long long s1;
char s2[20]={""};
double x;
FILE *fp1,*fp2;
char name1[50]={"D:\\工程实践1\\小区物业费.txt"};
char name2[50]={"D:\\工程实践1\\1.txt"};
fp1=fopen(name1,"r");
fp2=fopen(name2,"w");
while(fscanf(fp1,"%lld %s %lf",&s1,s2,&x)==3){
if(newp->account==s1){
newp->property_cost+=newp->square_meter*newp->square_meter_money;
fprintf(fp2,"%lld %s %.3lf\n",s1,s2,newp->property_cost);
newp=newp->next;
}
}
fclose(fp1);
fclose(fp2);
remove(name1);
rename(name2,name1);
}
//统计物业费函数,调用了两种不同统计方法的函数,一种是排序输出,一种是按楼层输出
void statistic(Person *L){
while(1){
menu_cost();
gotoposition(25,7);
int ch;
scanf("%d",&ch);
if(ch==1)total_people(L); //按楼层输出
else if(ch==2)sort_people(L);//排序输出
else if(ch==3)return;
}
}
void total_people(Person *L){
free_infor(L);
get(L);
Person newp,newq;
newp=*L;
int i,j;
int count=0;
//统计结点的数量
while(newp->next!=NULL){
count++;
newp=newp->next;
}
newp=*L;
//直接将楼层进行排序,从小到大,相当于在按楼层分类
for(i=0;i<count-1;i++){
newp=*L;
for(j=0;j<count-i;j++){
if(newp->building_number>newp->next->building_number){
swap(&newp,&(newp->next));
}
newp=newp->next;
}
}
newp=*L;
system("cls");
printf("******************************************************************************************\n");
printf("楼层 姓名 电话 物业费欠额 备注信息(单元号,房号)\n");
while(newp){
if(newp->property_cost>0){
printf("%-2lld %-8s %-12lld %-11.3lf %-3lld %-3lld\n",newp->building_number,newp->name,newp->tel_number,newp->property_cost,newp->unit_number,newp->room_number);
}
newp=newp->next;
}
printf("*******************************************************************************************\n");
printf("输入1返回上一界面\n");
int ch=0;
while(ch!=1){
scanf("%d",&ch);
}
}
//排序输出,调用了辅助函数swap进行数据的交换
void sort_people(Person *L){
free_infor(L);
get(L);
Person newp,newq;
newp=*L;
int count=0;
int i,j;
//统计结点的数量
while(newp->next!=NULL){
count++;
newp=newp->next;
}
newp=*L;
//采用冒泡排序的算法对物业费进行统计,并进行数据的交换
for(i=0;i<count-1;i++){
newp=*L;
for(j=0;j<count-i;j++){
if(newp->property_cost<newp->next->property_cost){
swap(&newp,&(newp->next));
}
newp=newp->next;
}
}
newp=*L;
system("cls");
//输出排好序以后的数据
printf("******************************************************************************************\n");
printf("姓名 电话 物业费欠额 备注信息(楼号,单元号,房号)\n");
while(newp){
if(newp->property_cost>0){
printf("%-8s %-12lld %-11.3lf %-3lld %-3lld %-3lld\n",newp->name,newp->tel_number,newp->property_cost,newp->building_number,newp->unit_number,newp->room_number);
}
newp=newp->next;
}
printf("*******************************************************************************************\n");
printf("输入1返回上一界面\n");
int ch=0;
while(ch!=1){
scanf("%d",&ch);
}
}
//辅助函数,对数据进行交换
void swap(Person *newp,Person *newq){
Person tmp;
tmp=(Person)malloc(sizeof(struct node));
tmp->account=(*newp)->account;
(*newp)->account=(*newq)->account;
(*newq)->account=tmp->account;
strcpy(tmp->key,(*newp)->key);
strcpy((*newp)->key,(*newq)->key);
strcpy((*newq)->key,tmp->key);
strcpy(tmp->name,(*newp)->name);
strcpy((*newp)->name,(*newq)->name);
strcpy((*newq)->name,tmp->name);
strcpy(tmp->sex,(*newp)->sex);
strcpy((*newp)->sex,(*newq)->sex);
strcpy((*newq)->sex,tmp->sex);
tmp->Id_card=(*newp)->Id_card;
(*newp)->Id_card=(*newq)->Id_card;
(*newq)->Id_card=tmp->Id_card;
tmp->tel_number=(*newp)->tel_number;
(*newp)->tel_number=(*newq)->tel_number;
(*newq)->tel_number=tmp->tel_number;
tmp->building_number=(*newp)->building_number;
(*newp)->building_number=(*newq)->building_number;
(*newq)->building_number=tmp->building_number;
tmp->unit_number=(*newp)->unit_number;
(*newp)->unit_number=(*newq)->unit_number;
(*newq)->unit_number=tmp->unit_number;
tmp->room_number=(*newp)->room_number;
(*newp)->room_number=(*newq)->room_number;
(*newq)->room_number=tmp->room_number;
tmp->square_meter=(*newp)->square_meter;
(*newp)->square_meter=(*newq)->square_meter;
(*newq)->square_meter=tmp->square_meter;
tmp->square_meter_money=(*newp)->square_meter_money;
(*newp)->square_meter_money=(*newq)->square_meter_money;
(*newq)->square_meter_money=tmp->square_meter_money;
tmp->property_cost=(*newp)->property_cost;
(*newp)->property_cost=(*newq)->property_cost;
(*newq)->property_cost=tmp->property_cost;
free(tmp);
}
void print_number(){
printf("70088208820");
}
//光标移动函数
void gotoposition(int x,int y){
COORD position;
HANDLE screen=GetStdHandle(STD_OUTPUT_HANDLE);
position.X=x,position.Y=y;
SetConsoleCursorPosition(screen, position);
}
//读取数据函数,从文件中读取数据
void get(Person *L){
Person newp,head=NULL,newq,tmp;
newp=(Person)malloc(sizeof(struct node));
newp->next=NULL;
FILE *fp1,*fp2;
long long s;
char s1[20]={""};
double x11;
fp1=fopen("D:\\工程实践1\\小区物业.txt","r");
fp2=fopen("D:\\工程实践1\\小区物业费.txt","r");
if(fp1==NULL){
fp1=fopen("D:\\工程实践1\\小区物业.txt","w");
}
if(fp2==NULL){
fp2=fopen("D:\\工程实践1\\小区物业费.txt","w");
}
while(fscanf(fp1,"%lld %s %s %s %lld %lld %lld %lld %lld %lf %lf",&newp->account,newp->key,newp->name,newp->sex,&newp->Id_card,&newp->tel_number,&newp->building_number,&newp->unit_number,&newp->room_number,&newp->square_meter,&newp->square_meter_money)==11){
if(head==NULL){
head=newp;
}
else{
newq->next=newp;
}
newq=newp;
newq->next=NULL;
newp=(Person)malloc(sizeof(struct node));
}
newp=head;
while(fscanf(fp2,"%lld %s %lf",&s,s1,&x11)==3){
newp->property_cost=x11;
newp=newp->next;
}
newp=head;
*L=head;
fclose(fp1);
fclose(fp2);
}
//链表空间释放函数
void free_infor(Person *L){
Person newp,newq;
newp=*L;
newq=newp;
while(newp){
newq=newp;
newp=newp->next;
free(newq);
}
}