c语言学习知识物业管理单位管理方案计划系统.doc
-#include<stdio.h>#include<stdlib.h>#include<string.h>#ifdef _GNUC_#include<unistd.h>#include<curses.h>#define clear clear#define Sleep(x) usleep(x#000)#endif#ifdef _MSC_VER#include<windows.h>#include<conio.h>#define clear system("cls")#endif#define TRUE 1#define FAUSE 0typedef struct perchar name20;int sex;char IDcard19;char phone12;int build_num;int unit_num;int house_num;float area;float area_price;float charge;char remarks200;struct per *next;PERSON;void zhuce ();int login ();PERSON *Getdata (FILE *fp); void add_person ();void del (PERSON *L);void change (PERSON *L);void sort_All (PERSON *L);void pay (PERSON *L);void sort_B_num (PERSON *L);void menu_1 ();void menu_2 ();int main ()int check,a;printf("t* Welcome !*");printf("ntt1.注册");printf("ntt2.登录");printf("ntt0.退出");printf("nt-请输入-: ");scanf("%d",&a);clear;switch(a)case 0:printf("tt-感谢使用本系统!-");Sleep(2000);exit(0);case 1:zhuce();clear;check = login();while (check = FAUSE)printf("n用户名或密码错误。");Sleep(2000);clear;check = login();clear;menu_1();break;case 2:check = login();while (check = FAUSE)printf ("n用户名或密码错误。");Sleep(2000);clear;check = login();clear;menu_1();break;return 0;void menu_1 ()FILE *fp;int a;PERSON *head = NULL;printf("tt*欢迎使用*");printf("ntt1.用户添加");printf("ntt2.用户修改");printf("ntt3.用户删除");printf("ntt4.用户费用信息查看");printf("ntt5.用户缴费");printf("ntt0.退出");printf("nt-请输入-: ");scanf("%d",&a);clear;switch(a)case 0:printf("-感谢使用!-");Sleep(3000);exit(0);case 1:add_person();menu_1();break;case 2:fp = fopen("data.dat","r");head = Getdata(fp);printf("%s",head->name);if (head = NULL)printf("没有任何数据");Sleep(3000);exit(1);elsechange(head);menu_1();break;case 3:if(fp = fopen("data.dat","rb") = NULL)printf("没有任何数据");exit(1);elsehead = Getdata(fp);del(head);menu_1();break;case 4:menu_2();break;case 5:fp = fopen("data.dat","rb");head = Getdata(fp);if (head = NULL)printf("没有任何数据");Sleep(3000);exit(1);elsepay(head);menu_1();break;void menu_2 ()FILE *fp;int a;PERSON *head = NULL;printf("tt*用户信息查看*");printf("ntt1.按楼号查看用户物业费情况");printf("ntt2.按费用信息查看用户物业费情况");printf("ntt0.退出");printf("nt-请输入-:");scanf("%d",&a);clear;switch(a)case 0:printf("感谢使用");Sleep(3000);exit(0);case 1:fp = fopen("data.dat","rb");head = Getdata(fp);if (head = NULL)printf("没有任何数据");Sleep(3000);exit(1);elsesort_B_num(head);menu_2();break;case 2:fp = fopen("data.dat","rb"); head = Getdata(fp); if (head = NULL) printf("没有任何数据"); Sleep(3000); exit(1); elseprintf("tt-所有用户物业费情况-n");sort_All(head);menu_2();break;void zhuce ()FILE *fp;char ad50,key050,key150;char ch;int i,j;printf("tt*用户注册*");printf("nt-请输入用户名: ");scanf("%s",ad);while (1)i = 0;j = 0;printf("nt-请输入密码: ");/initscr();/noecho();while (ch = getch() != r)if (ch = 8)printf("b ");putchar(b);if (i > 0)i-;elseputchar(*);/fflush(stdout);key0i+ = ch;/endwin();key0i = 0;printf("nt-请再次输入密码: ");/initscr();/noecho();while (ch = getch() != r ) if (ch = 8) printf("b "); putchar(b); if (j > 0) j-; else putchar(*); key1j+ = ch; /endwin();key1j = 0;if (strcmp(key0,key1) != 0)clear;printf("%d",strcmp(key0,key1);printf("t-两次输入密码不符,请重新输入-");Sleep(2000);clear;elseprintf("n-用户 %s 注册成功!-",ad);Sleep(3000);fp = fopen("admin.txt","a");fprintf(fp,"%sn",ad);fclose(fp);fp = fopen("key.txt","a");fprintf(fp,"%sn",key0);fclose(fp);break;int login ()FILE *fp1,*fp2;char ad50,key50;char ch_150,ch_250,ch_0;int i = 0,check = 0;printf("tt*用户登录*");printf("ntt-用户名- ");scanf("%s",ad);printf("ntt-密码- ");/initscr();while (ch_0 = getch() != r)if (ch_0 = 8)printf("b ");putchar(b);if (i > 0)i-;elseputchar(*);keyi+ = ch_0;keyi = 0;/endwin();fp1 = fopen("admin.txt","r");fp2 = fopen("key.txt","r");while (!feof(fp1)fscanf(fp1,"%s",ch_1);fscanf(fp2,"%s",ch_2);/printf("%s",ch_1);/printf("%s",ch_2);if (strcmp(ad,ch_1) = 0)if (strcmp(key,ch_2) = 0)check = TRUE;break;fclose(fp1);fclose(fp2);return check;PERSON *Getdata (FILE *fp)PERSON *head = NULL;PERSON *p1,*p2;p1 = (PERSON*)malloc(sizeof(struct per);while (fread(p1,sizeof(struct per),1,fp) = 1)/printf("%s",p1->name);if (head = NULL)head = p2 = p1;elsep2 -> next = p1;p2 = p1;p1 = p1 -> next;p1 = (PERSON*)malloc(sizeof(struct per);p2 -> next = NULL;free(p1);return head;void save (PERSON *head)FILE *fp;PERSON *p;fp = fopen("data.dat","wb+");p = head;while (p != NULL)fwrite(p,sizeof(struct per),1,fp);p = p -> next;fclose(fp);void add_person ()PERSON *p1,*p2;PERSON *head = NULL;int n;printf("ntt*用户添加*");while (1)p1 = (PERSON*)malloc(sizeof(struct per);printf("nn请输入用户信息: 姓名 性别(0.女性;1.男性) 身份证 联系方式 楼号 单元号 房号 平米数 每平米价格 备注nn");scanf("%s",(*p1).name);scanf("%d",&(*p1).sex);scanf("%s",(*p1).IDcard);scanf("%s",(*p1).phone);scanf("%d",&(*p1).build_num);scanf("%d",&(*p1).unit_num);scanf("%d",&(*p1).house_num);scanf("%f",&(*p1).area);scanf("%f",&(*p1).area_price);scanf("%s",(*p1).remarks);(*p1).charge = (*p1).area * (*p1).area_price * (-1);if (head = NULL)head = p2 = p1;elsep2 ->next = p1;p2 = p1;printf("nt-用户添加成功!-");printf("n是否继续添加(1.是;0.否)");scanf("%d",&n);if (n = 0)break;p1 = p1 -> next;p2 -> next = NULL;save(head);void del (PERSON *L)PERSON *head,*p1,*p2;PERSON *p;char name20,ID19;int k = 0;int n;p = (PERSON*)malloc(sizeof(struct per);p -> next = head = L;while (1)p1 = p;printf("请输入所要删除的用户姓名及身份证号n- ");scanf("%s %s",name,ID);while (p1 -> next != NULL)if (strcmp(name,p1->next->name) = 0 && strcmp(ID,p1->next->IDcard) = 0)p2 = p1 -> next;p1 -> next = p2 -> next;free(p2);k = 1;break;p1 = p1 -> next;head = p -> next;if (k = 0)printf("nt-没有相关用户!-");elseprintf("nt删除用户- %s -成功!",name);printf("n是否继续删除(1.是;0否)");scanf("%d",&n);if (n = 0)break;save(head);void change (PERSON *L)char name20,ID19;PERSON *p;int n,k = 0;while (1)p = L;printf("-请输入所需修改用户的姓名及身份证-n-");scanf("%s",name);scanf("%s",ID);while (p -> next != NULL)if (strcmp(p -> name,name) = 0 && strcmp(p -> IDcard,ID) = 0)k = 1;break;p = p -> next;if (k = 0)printf("没有查找到该用户,是否重新输入(1.是;0.否)n-");scanf("%d",&n);if (n != 1)break;elseclear;printf("t-请输入用户 - %s - 修改后信息-",p -> name);printf("姓名 性别 身份证 联系方式 楼号 单元号 房号 平米数 每平米价格 备注");scanf("%s",(*p).name); scanf("%d",&(*p).sex); scanf("%s",(*p).IDcard); scanf("%s",(*p).phone); scanf("%d",&(*p).build_num); scanf("%d",&(*p).unit_num); scanf("%d",&(*p).house_num); scanf("%f",&(*p).area); scanf("%f",&(*p).area_price); scanf("%s",(*p).remarks); (*p).charge = (*p).area * (*p).area_price;printf("修改用户成功n是否继续修改(1.是;0.否)");scanf("%d",&n);if (n != 1)break;save(L);void pay (PERSON *L)char name20,ID19;PERSON *head,*p;int n,k = 0;float money;head = L;while (1)printf("-请输入所需缴费的用户及身份证-n-");scanf("%s %s",name,ID);p = head;while (p -> next != NULL)if (strcmp(p -> name,name) = 0 && strcmp(p -> IDcard,ID) = 0) k = 1; break; p = p -> next;if (k = 0) printf("没有查找到该用户,是否重新输入(1.是;0.否)n-"); scanf("%d",&n); if (n != 1) break; elseprintf("请输入缴费金额:n-");scanf("%f",&money);p -> charge += money;printf("是否继续缴费(1.是;0.否)");scanf("%d",&n);if (n != 1)break;save(head);void sort_All (PERSON *L)PERSON *p;PERSON s20,a;int n = 0;int i,j;p = L;while (p -> next != NULL)strcpy(sn.name,p -> name);sn.sex = p -> sex;strcpy(sn.IDcard,p -> IDcard);strcpy(sn.phone,p -> phone);sn.build_num = p -> build_num;sn.unit_num = p -> unit_num;sn.house_num = p -> house_num;sn.area = p -> area;sn.area_price = p -> area_price;sn.charge = p -> charge;strcpy(sn.remarks,p -> remarks);n+;p = p -> next;for (i = 0; i < n; i+)for (j = i+1; j < n; j+)if (si.charge > sj.charge)strcpy(a.name,sj. name); a.sex = sj. sex; strcpy(a.IDcard,sj. IDcard); strcpy(a.phone,sj.phone); a.build_num = sj.build_num; a.unit_num = sj. unit_num; a.house_num = sj. house_num; a.area = sj. area; a.area_price = sj.area_price; a.charge = sj. charge; strcpy(a.remarks,sj.remarks); strcpy(sj.name,si.name); sn.sex = si.sex; strcpy(sj.IDcard,si.IDcard); strcpy(sj.phone,si.phone); sj.build_num = si.build_num; sj.unit_num = si.unit_num; sj.house_num = si.house_num; sj.area = si.area; sj.area_price = si.area_price; sj.charge = si.charge; strcpy(sn.remarks,si.remarks);strcpy(si.name,a.name); si.sex = a.sex; strcpy(si.IDcard,a.IDcard); strcpy(si.phone,a.phone); si.build_num = a.build_num; si.unit_num = a.unit_num; si.house_num = a.house_num; si.area = a.area; si.area_price = a.area_price; si.charge = a.charge; strcpy(sn.remarks,a.remarks);printf("姓名 性别 身份证 联系电话 楼号 单元号 房号 平米数 每平米价格 费用情况 备注");for (i = 0; i < n; i+)printf("%s %d %s %s %d %d %d %.2f %.2f %.2f %sn",si.name,si.sex,si.IDcard,si.phone,si.build_num,si.unit_num,si.area,si.area_price,si.charge,si.remarks);void sort_B_num (PERSON *L)PERSON a10,b10;PERSON *p;int i=0,j=0,n;p = L;while (p -> next != NULL)if (p -> build_num = 1 && p -> charge < 0)strcpy(ai.name,p -> name); ai.sex = p -> sex; strcpy(ai.IDcard,p -> IDcard); strcpy(ai.phone,p -> phone); ai.build_num = p -> build_num; ai.unit_num = p -> unit_num; ai.house_num = p -> house_num; ai.area = p -> area; ai.area_price = p -> area_price; ai.charge = p -> charge; strcpy(ai.remarks,p -> remarks);i+;if (p -> build_num = 2 && p -> charge < 0) strcpy(bj.name,p -> name); bj.sex = p -> sex; strcpy(bj.IDcard,p -> IDcard); strcpy(bj.phone,p -> phone); bj.build_num = p -> build_num; bj.unit_num = p -> unit_num; bj.house_num = p -> house_num; bj.area = p -> area; bj.area_price = p -> area_price; bj.charge = p -> charge; strcpy(bj.remarks,p -> remarks);j+;p = p -> next;printf("楼号-1-的欠费用户信息n");printf("姓名 性别 身份证 联系电话 楼号 单元号 房号 平米数 每平米价格 费用情况 备注");for (n = 0; n < i; n+)printf("%s %d %s %s %d %d %d %.2f %.2f %.2f %sn",ai.name,ai.sex,ai.IDcard,ai.phone,ai.build_num,ai.unit_num,ai.area,ai.area_price,ai.charge,ai.remarks);printf("楼号-2-的欠费用户信息n");printf("姓名 性别 身份证 联系电话 楼号 单元号 房号 平米数 每平米价格 费用情况 备注");for (n = 0; n < j; n+) printf("%s %d %s %s %d %d %d %.2f %.2f %.2f %sn",bj.name,bj.sex,bj.IDcard,bj.phone,bj.build_num,bj.unit_num,bj.area,bj.area_price,bj.charge,bj.remarks);