c语言物业管理系统

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#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 0
typedef struct per
{
char name[20];
int sex;
char IDcard[19];
char phone[12];
int build_num;
int unit_num;
int house_num;
float area;
float area_price;
float charge;
char remarks[200];
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("\n\t\t1.注册");
printf("\n\t\t2.登录");
printf("\n\t\t0.退出");
printf("\n\t--请输入--: ");
scanf("%d",&a);
clear;
switch(a)
{
case 0:
{
printf("\t\t--感谢使用本系统!--");
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("\t\t*************************欢迎使用***************************");
printf("\n\t\t1.用户添加");
printf("\n\t\t2.用户修改");
printf("\n\t\t3.用户删除");
printf("\n\t\t4.用户费用信息查看");
printf("\n\t\t5.用户缴费");
printf("\n\t\t0.退出");
printf("\n\t--请输入--: ");
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);
}
else
{
change(head);
menu_1();
}
break;
}
case 3:
{
if((fp = fopen("data.dat","rb")) == NULL) {
printf("没有任何数据");
exit(1);
}
else
{
head = 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);
}
else
{
pay(head);
menu_1();
}
break;
}
}
}
void menu_2 ()
{
FILE *fp;
int a;
PERSON *head = NULL;
printf("\t\t*******用户信息查看**********");
printf("\n\t\t1.按楼号查看用户物业费情况");
printf("\n\t\t2.按费用信息查看用户物业费情况");
printf("\n\t\t0.退出");
printf("\n\t--请输入--:");
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);
}
else
{
sort_B_num(head);
menu_2();
}
break;
}
case 2:
{
fp = fopen("data.dat","rb");
head = Getdata(fp);
if (head == NULL)
{
printf("没有任何数据"); Sleep(3000);
exit(1);
}
else
{
printf("\t\t--所有用户物业费情况--\n");
sort_All(head);
menu_2();
}
break;
}
}
}
void zhuce ()
{
FILE *fp;
char ad[50],key0[50],key1[50];
char ch;
int i,j;
printf("\t\t************用户注册*********");
printf("\n\t--请输入用户名: ");
scanf("%s",ad);
while (1)
{
i = 0;
j = 0;
printf("\n\t--请输入密码: ");
// initscr();
// noecho();
while ((ch = getch()) != '\r')
{
if (ch == 8)
{
printf("\b ");
putchar('\b');
if (i > 0)
i--;
}
else
{
putchar('*');
// fflush(stdout);
key0[i++] = ch;
}
}
// endwin();
key0[i] = '\0';
printf("\n\t--请再次输入密码: ");
// initscr();
// noecho();
while ((ch = getch()) != '\r' )
{
if (ch == 8)
{
printf("\b ");
putchar('\b');
if (j > 0)
j--;
}
else
{
putchar('*');
key1[j++] = ch;
}
}
// endwin();
key1[j] = '\0';
if (strcmp(key0,key1) != 0)
{
clear;
printf("%d",strcmp(key0,key1));
printf("\t--两次输入密码不符,请重新输入--");
Sleep(2000);
clear;
}
else
{
printf("\n--用户 %s 注册成功!--",ad);
Sleep(3000);
fp = fopen("admin.txt","a");
fprintf(fp,"%s\n",ad);
fclose(fp);
fp = fopen("key.txt","a");
fprintf(fp,"%s\n",key0);
fclose(fp);
break;
}
}
}
int login ()
{
FILE *fp1,*fp2;
char ad[50],key[50];
char ch_1[50],ch_2[50],ch_0;
int i = 0,check = 0;
printf("\t\t*******************用户登录*********************");
printf("\n\t\t--[用户名]-- ");
scanf("%s",ad);
printf("\n\t\t--[密码]-- ");
// initscr();
while ((ch_0 = getch()) != '\r')
{
if (ch_0 == 8)
{
printf("\b ");
putchar('\b');
if (i > 0)
i--;
}
else
{
putchar('*');
key[i++] = ch_0;
}
}
key[i] = '\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;
}
else
{
p2 -> 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("\n\t\t************用户添加**********");
while (1)
{
p1 = (PERSON*)malloc(sizeof(struct per));
printf("\n\n请输入用户信息: 姓名性别(0.女性;1.男性) 身份证联系方式楼号单元号房号平米数每平米价格备注\n\n");
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;
else
{
p2 ->next = p1;
p2 = p1;
}
printf("\n\t--用户添加成功!--");
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 name[20],ID[19];
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("\n\t--没有相关用户!--");
else
{
printf("\n\t删除用户- %s -成功!",name);
printf("\n是否继续删除(1.是;0否)");
scanf("%d",&n);
if (n == 0)
break;
}
}
save(head);
}
void change (PERSON *L)
{
char name[20],ID[19];
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;
}
else
{
clear;
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 name[20],ID[19];
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;
}
else
{
printf("请输入缴费金额:\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 s[20],a;
int n = 0;
int i,j;
p = L;
while (p -> next != NULL)
{
strcpy(s[n].name,p -> name);
s[n].sex = p -> sex;
strcpy(s[n].IDcard,p -> IDcard);
strcpy(s[n].phone,p -> phone);
s[n].build_num = p -> build_num;
s[n].unit_num = p -> unit_num;
s[n].house_num = p -> house_num;
s[n].area = p -> area;
s[n].area_price = p -> area_price;
s[n].charge = p -> charge;
strcpy(s[n].remarks,p -> remarks);
n++;
p = p -> next;
}
for (i = 0; i < n; i++)
{
for (j = i+1; j < n; j++)
{
if (s[i].charge > s[j].charge)
{
strcpy(,s[j]. name);
a.sex = s[j]. sex;
strcpy(a.IDcard,s[j]. IDcard);
strcpy(a.phone,s[j].phone);
a.build_num = s[j].build_num;
a.unit_num = s[j]. unit_num;
a.house_num = s[j]. house_num;
a.area = s[j]. area;
a.area_price = s[j].area_price;
a.charge = s[j]. charge;
strcpy(a.remarks,s[j].remarks);
strcpy(s[j].name,s[i].name);
s[n].sex = s[i].sex;
strcpy(s[j].IDcard,s[i].IDcard); strcpy(s[j].phone,s[i].phone);
s[j].build_num = s[i].build_num; s[j].unit_num = s[i].unit_num;
s[j].house_num = s[i].house_num; s[j].area = s[i].area;
s[j].area_price = s[i].area_price; s[j].charge = s[i].charge;
strcpy(s[n].remarks,s[i].remarks);
strcpy(s[i].name,);
s[i].sex = a.sex;
strcpy(s[i].IDcard,a.IDcard);
strcpy(s[i].phone,a.phone);
s[i].build_num = a.build_num;
s[i].unit_num = a.unit_num;
s[i].house_num = a.house_num;
s[i].area = a.area;
s[i].area_price = a.area_price;
s[i].charge = a.charge;
strcpy(s[n].remarks,a.remarks);
}
}
}
printf("姓名性别身份证联系电话楼号单元号房号平米数每平米价格费用情况备注");
for (i = 0; i < n; i++)
printf("%s %d %s %s %d %d %d %.2f %.2f %.2f %s\n",s[i].name,s[i].sex,s[i].I Dcard,s[i].phone,s[i].build_num,s[i].unit_num,s[i].area,s[i].area_price,s[i].ch arge,s[i].remarks);
}
void sort_B_num (PERSON *L)
{
PERSON a[10],b[10];
PERSON *p;
int i=0,j=0,n;
p = L;
while (p -> next != NULL)
{
if (p -> build_num == 1 && p -> charge < 0)
{
strcpy(a[i].name,p -> name);
a[i].sex = p -> sex;
strcpy(a[i].IDcard,p -> IDcard);
strcpy(a[i].phone,p -> phone);
a[i].build_num = p -> build_num;
a[i].unit_num = p -> unit_num;
a[i].house_num = p -> house_num;
a[i].area = p -> area;
a[i].area_price = p -> area_price;
a[i].charge = p -> charge;
strcpy(a[i].remarks,p -> remarks);
i++;
}
if (p -> build_num == 2 && p -> charge < 0)
{
strcpy(b[j].name,p -> name);
b[j].sex = p -> sex;
strcpy(b[j].IDcard,p -> IDcard);
strcpy(b[j].phone,p -> phone);
b[j].build_num = p -> build_num;
b[j].unit_num = p -> unit_num;
b[j].house_num = p -> house_num;
b[j].area = p -> area;
b[j].area_price = p -> area_price;
b[j].charge = p -> charge;
strcpy(b[j].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 %s\n",a[i].name,a[i].sex,a[i].I Dcard,a[i].phone,a[i].build_num,a[i].unit_num,a[i].area,a[i].area_price,a[i].ch arge,a[i].remarks);
printf("楼号--[2]--的欠费用户信息\n");
printf("姓名性别身份证联系电话楼号单元号房号平米数每平米价格费用情况备注");
for (n = 0; n < j; n++)
printf("%s %d %s %s %d %d %d %.2f %.2f %.2f %s\n",b[j].name,b[j].sex,b[j].IDcar d,b[j].phone,b[j].build_num,b[j].unit_num,b[j].area,b[j].area_price,b[j].charge ,b[j].remarks);
}。

相关文档
最新文档