要求以租房管理業務為背景,設計並實現一個“租房資訊管理系統”軟體,使用該系統可以方便查詢每一個房屋資訊,租客資訊,租房登記資訊等。
阿新 • • 發佈:2022-03-20
- 要求:
(1)房屋資訊包括:地址、房產證號、戶型、面積、裝修等級、月租金等。
(2)租客資訊包括:身份證號、姓名、工作單位、工齡、聯絡方式、租房補貼等。
(3)租房登記資訊包括:租客、房屋、入住時間、租房合同號、備註等。
(4)完成以下的操作:房屋資訊和租客資訊的新增、修改、瀏覽、刪除和查詢及租房、退房;租房資訊瀏覽與查詢。
- 來源:期末課設!
- main函式
#include<stdio.h> #include<string.h> #include "house.h" #include "rental.h" #include "tenant.h" //相應的標頭檔案 int n; int k; int l; int u = 0; //定義四個全域性變數,分別是n, k, l, u。 int main() { int certain = 1; int num; if(u <= 1) { printf(" ************************************\n"); printf(" * 租房資訊管理系統 *\n"); printf(" ************************************\n"); printf("\n"); printf("歡迎來到“租房資訊管理系統”請選擇您所需要的服務:\n"); printf("輸入每項服務所對應的數字即可!\n"); u++; }//使用全域性變數u迫使以上資訊只顯示一次。 while(certain) { printf("\n"); printf("您現在所進入的是一級選單!\n"); printf("1.房屋資訊\n"); printf("2.租客資訊\n"); printf("3.租房登記\n"); printf("4.退出系統\n"); printf("\n"); scanf("%d", &num); switch(num) { case 1: house_information(); break; case 2: tenant_information(); break; case 3: rental_registration_information(); break; case 4: { printf("\n"); printf("您選擇的是4<退出系統>\n"); printf("非常感謝您的使用,歡迎下次使用!"); certain = 0; return 0; } break; } } return 0; }
- house.h檔案
#ifndef HOUSE_H_INCLUDED #define HOUSE_H_INCLUDED void house_information();//房屋資訊 void add_house_information();//新增房屋資訊 void change_house_information();//修改房屋資訊 void delete_house_information();//刪除房屋資訊 void show_house_information();//顯示房屋資訊 void find_house_information();//查詢房屋資訊 void rental_registration_information();//租房登記資訊 struct ren_out{ int no_housing; //房產證號 char address[100]; //地址 int area; //面積 float month_price; //月租金 char type_house[10]; //房屋戶型 char grade_decoration[10]; //房屋裝修等級 char if_outhouse[10]; //是否出租房屋 }a[10];//房屋資訊 #endif // HOUSE_H_INCLUDED
- house.c檔案
#include <stdio.h> #include <string.h> #include "house.h" extern int n; //全域性變數n void house_information()//房屋資訊選單 { int certain = 1; int f; while(certain) { printf("\n"); printf("您現在進入的是二級選單<房屋資訊>\n"); printf("1.新增房屋資訊 2.修改房屋資訊\n"); printf("3.刪除房屋資訊 4.顯示房屋資訊\n"); printf("5.查詢房屋資訊 6.返回上一介面\n"); printf("7.已找到合適的租客,想要與他籤合同!\n"); printf("\n"); scanf("%d", &f); switch(f) { case 1: add_house_information(); break; case 2: change_house_information(); break; case 3: delete_house_information(); break; case 4: show_house_information(); break; case 5: find_house_information(); break; case 6: { certain = 0; } break; case 7: rental_registration_information(); break; } } } void add_house_information()//新增房屋資訊 { int i; int certain = 1; char c; printf("\n"); printf("您現在進入的是三級選單<新增房屋資訊>\n"); printf("現在我們開始錄入資料\n"); printf("\n"); while(certain) { for(i = n; i < 10; i++) { printf("請輸入您想錄入的房產證號:"); scanf("%d", &a[i].no_housing); printf("請輸入房屋地址:"); scanf("%s", a[i].address); printf("請輸入房屋的面積:"); scanf("%d", &a[i].area); printf("請輸入房屋的月租金:"); scanf("%f", &a[i].month_price); printf("請輸入房屋的戶型:"); scanf("%s", a[i].type_house); printf("請輸入房屋的裝修等級:"); scanf("%s", a[i].grade_decoration); printf("請問您的房屋現在是否出租?(用是和不是表示)"); scanf("%s", a[i].if_outhouse); n++; printf("請問是否繼續錄入?(用Y和N表示)"); scanf("%s", &c); if(c == 'Y') { certain = 1; } else if(c == 'N') { certain = 0; printf("\n恭喜!輸入完成!\n"); break; } } } } void change_house_information()//修改房屋資訊 { int i, z; char x[20], h[20], g[20], o[20]; printf("\n"); printf("您現在進入的是三級選單<修改房屋資訊>\n"); printf("現在我們來修改房屋資訊\n\n"); printf("請輸入您想修改的房屋的房產證號:"); scanf("%d", &z); if(n <= 0) { printf("抱歉!您沒有輸入住房資訊,無法進行修改!\n"); return; } else { for(i = 0; i < n; i++) { if(z == a[i].no_housing) { printf("請輸入你想錄入的房產證號:"); scanf("%d", &a[i].no_housing); printf("請輸入房屋地址:"); scanf("%s",x); strcpy(a[i].address, x); printf("請輸入房屋的面積:"); scanf("%d", &a[i].area); printf("請輸入房屋的月租金:"); scanf("%f", &a[i].month_price); printf("請輸入房屋的戶型:"); scanf("%s", h); strcpy(a[i].type_house, h); printf("請輸入房屋的裝修等級:"); scanf("%s", g); strcpy(a[i].grade_decoration, g); printf("請問您的房屋現在是否出租?(用是和不是表示)"); scanf("%s", o); strcpy(a[i].if_outhouse, o); } else { printf("抱歉!沒有找到您要修改的房屋資訊\n"); } } } } void delete_house_information()//刪除房屋資訊 { int i, s; int j; printf("\n"); printf("您現在進入的是三級選單<刪除房屋資訊>\n"); printf("現在我們來刪除房屋資訊\n\n"); if(n) { for(i = 0; i < n; i++) { printf("請輸入您想刪除的房產證號:"); scanf("%d", &s); if(s == a[i].no_housing) { printf("已經成功刪除\n"); for(j = i; j < n; j++) { a[j] = a[j+1]; n--; } break; } else { printf("抱歉!沒有該房屋的具體資訊\n"); } } } else { printf("抱歉,您沒有輸入內容!\n"); } } void show_house_information()//顯示房屋資訊 { int i; printf("\n"); printf("您現在進入的是三級選單<顯示房屋資訊>\n"); printf("現在所有的房屋資訊有:\n\n"); printf("房產證號 房屋地址 房屋面積 房屋月租金 房屋戶型 房屋裝修等級 房屋是否出租\n"); printf("---------------------------------------------------------------------\n"); printf("123 河北省 230 3300 樓房 二等 是\n"); printf("456 河南省 120 1000 樓房 二等 否\n"); printf("178 河北省 500 8000 別墅 一等 是\n"); for(i = 0; i < n; i++) { printf("%d %s %d %.0f %s %s %s\n",a[i].no_housing,a[i].address,a[i].area,a[i].month_price, a[i].type_house, a[i].grade_decoration, a[i].if_outhouse); } return; } void find_house_information()//查詢房屋資訊 { int g, i; printf("\n"); printf("您現在進入的是三級選單<查詢房屋資訊>\n"); printf("現在我們開始查詢房屋資訊\n\n"); printf("請輸入您想檢視的房產證號:"); scanf("%d", &g); printf("您輸入的是:%d,查詢該房屋資訊如下:\n", g); for(i = 0; i < n; i++) { if(g == a[i].no_housing) { printf("房產證號 房屋地址 房屋面積 房屋月租金 房屋戶型 房屋裝修等級 房屋是否出租\n"); printf("---------------------------------------------------------------------\n"); printf("%d %s %d %.0f %s %s %s\n",a[i].no_housing,a[i].address,a[i].area,a[i].month_price,a[i].type_house, a[i].grade_decoration, a[i].if_outhouse); return; } } printf("沒有查到房屋的相關資訊") ; }
- tenant.h檔案
#ifndef TENANT_H_INCLUDED #define TENANT_H_INCLUDED void tenant_information();//租客資訊 void add_tenant_information();//新增租客資訊 void change_tenant_information();//修改租客資訊 void delete_tenant_information();//刪除租客資訊 void show_tenant_information();//顯示租客資訊 void find_tenant_information();//查詢租客資訊 void rental_registration_information();//租房登記資訊 struct rent{ long int id; //身份證號 char name[10]; //姓名 char work_place[100]; //工作單位 int work_time; //工齡 int telephone; //聯絡方式 float money_rent; //租房補貼 char if_check_out[10]; //是否退房 }b[10]; //租客資訊 #endif // TENANT_H_INCLUDED
- tenant.c檔案
#include <stdio.h> #include <string.h> #include "tenant.h" extern int k; extern int n; void tenant_information()//租客資訊選單 { int z; int certain = 1; while(certain) { printf("\n"); printf("您現在進入的是二級選單<租客資訊>\n"); printf("1.新增租客資訊 2.修改租客資訊\n"); printf("3.刪除租客資訊 4.顯示租客資訊\n"); printf("5.查詢租客資訊 6.返回上一介面\n"); printf("7.已找到合適的房屋,想要與房屋主人籤合同!\n"); printf("\n"); scanf("%d", &z); switch(z) { case 1: add_tenant_information(); break; case 2: change_tenant_information(); break; case 3: delete_tenant_information(); break; case 4: show_tenant_information(); break; case 5: find_tenant_information(); break; case 6: { certain = 0; } break; case 7: rental_registration_information(); break; } } } void add_tenant_information()//新增租客資訊 { int i; int certain = 1; char c; printf("\n"); printf("您現在進入的是三級選單<新增租客資訊>\n"); printf("現在我們來錄入資料\n"); printf("\n"); while(certain) { for(i = k; i < 10; i++) { printf("請輸入租客身份證號(9位數):"); scanf("%ld", &b[i].id); printf("請輸入租客姓名:"); scanf("%s", b[i].name); printf("請輸入租客的工作單位:"); scanf("%s", b[i].work_place); printf("請輸入租客工齡:"); scanf("%d", &b[i].work_time); printf("請輸入租客聯絡方式(7位數):"); scanf("%d", &b[i].telephone); printf("請輸入租客的租房補貼:"); scanf("%f", &b[i].money_rent); printf("請問租客現在是否要求退房?(用是和不是表示)"); scanf("%s", b[i].if_check_out); k++; printf("是否繼續錄入?(用Y和N表示)"); scanf("%s", &c); if(c == 'Y') { certain = 1; } else if(c == 'N') { certain = 0; printf("恭喜!輸入完成!\n"); break; } } } } void change_tenant_information()//修改租客資訊 { int i; long int z; char x[20], c[20], t[20]; printf("\n"); printf("您現在進入的是三級選單<修改租客資訊>\n"); printf("現在我們來修改租客資訊\n\n"); printf("請輸入您想修改的租客的身份證號:\n"); scanf("%ld", &z); if(k <= 0) { printf("抱歉!您沒有輸入租客資訊,無法進行修改!\n"); return; } else { for(i = 0; i < k; i++) { if(z == b[i].id) { printf("請輸入你想錄入的租客身份證號(11位數):\n"); scanf("%ld", &b[i].id); printf("請輸入租客姓名:\n"); scanf("%s", x); strcpy(b[i].name,x); printf("請輸入租客的工作單位:\n"); scanf("%s", c); strcpy(b[i].work_place,c); printf("請輸入租客工齡:\n"); scanf("%d", &b[i].work_time); printf("請輸入租客聯絡方式(7位數):\n"); scanf("%d", &b[i].telephone); printf("請輸入租客的租房補貼:\n"); scanf("%f", &b[i].money_rent); printf("請問租客現在是否要求退房?(用是和不是表示)"); scanf("%s", t); strcpy(b[i].if_check_out, t); } else { printf("沒有找到您要修改的房屋資訊\n"); } } } } void delete_tenant_information()//刪除租客資訊 { int i; int j; long int s; printf("\n"); printf("您現在進入的是三級選單<刪除租客資訊>\n"); printf("現在我們來刪除租客資訊\n\n"); if(k) { for(i = 0; i < k; i++) { printf("請輸入您想刪除的租客的身份證號:"); scanf("%ld", &s); if(s == b[i].id) { printf("\n"); printf("已經成功刪除\n"); for(j = i ; j < n; j++) { b[j] = b[j+1]; k--; } break; } else { printf("沒有該租客的具體資訊\n"); } } } else { printf("抱歉,您沒有輸入內容!\n"); } } void show_tenant_information()//顯示租客資訊 { int i; printf("\n"); printf("您現在進入的是三級選單<顯示租客資訊>\n"); printf("現在所有的租客資訊有:\n\n"); printf("租客身份證號 租客姓名 租客工作單位 租客工齡 聯絡方式 租房補貼 租客是否退房\n"); printf("--------------------------------------------------------------------\n"); printf("130120303 李曉娜 石家莊地鐵站 12 2834899 890 是\n"); printf("130120300 王明 新樂飯店 2 1648433 500 否\n"); printf("134894858 賈理 道路檢測 34 2546687 1000 否\n"); for(i = 0; i < k; i++) { printf("%ld %s %s %d %d %.0f %s\t\n", b[i].id, b[i].name, b[i].work_place, b[i].work_time, b[i].telephone, b[i].money_rent, b[i].if_check_out); } return; } void find_tenant_information()//查詢租客資訊 { int i; long int g; printf("\n"); printf("您現在進入的是三級選單<查詢租客資訊>\n"); printf("現在我們開始查詢租客資訊\n\n"); printf("請輸入租客的身份證號:\n"); scanf("%ld", &g); for(i = 0; i < k; i++) { if(g == b[i].id) { printf("租客身份證號 租客姓名 租客工作單位 租客工齡 聯絡方式 租房補貼 租客是否退房\n"); printf("--------------------------------------------------------------------\n"); printf("%ld %s %s %d %d %.0f %s\n",b[i].id,b[i].name,b[i].work_place,b[i].work_time,b[i].telephone, b[i].money_rent, b[i].if_check_out); return; } } printf("抱歉!沒有查到租客的資訊\n") ; }
- rental.h檔案
#ifndef RENTAL_H_INCLUDED #define RENTAL_H_INCLUDED void rental_registration_information();//租房登記資訊 void add_rental_registration_information();//新增租房登記資訊 void show_rental_registration_information();//顯示租房登記資訊 void find_rental_registration_information();//查詢租房登記資訊 //租房登記資訊包括:租客、房屋、入住時間、租房合同號、備註等。 struct renting_house{ char name[10];//租客姓名 int no_housing;//房產證號 char check_in_time[20];//入住時間 int contract_number;//租房合同號 char remark[20];//備註 }r[10];//租房登記資訊 #endif // RENTAL_H_INCLUDED
- rental.c檔案
#include <stdio.h> #include <string.h> #include "rental.h" extern int l; //(3)租房登記資訊包括:租客、房屋、入住時間、租房合同號、備註等。 void rental_registration_information()//租房登記資訊 int r; int certain=1; while(certain) { printf("\n"); printf("您現在進入的是二級選單<租房登記>\n"); printf("1.查詢租房登記資訊 2.顯示租房登記資訊\n"); printf("3.新增租房登記資訊 4.返回上一級頁面\n"); printf("\n"); scanf("%d",&r); switch(r) { case 1: find_rental_registration_information(); break; case 2: show_rental_registration_information(); break; case 3: add_rental_registration_information(); break; case 4: { certain = 0; } break; } } } void find_rental_registration_information()//查詢租房登記資訊 { int g, i; printf("\n"); printf("現在我們進入的是三級選單<查詢租房登記資訊>\n"); printf("現在我們來查詢租房登記資訊\n\n"); printf("請輸入您想檢視的房產證號:\n"); scanf("%d", &g); printf("\n"); for(i = 0; i < l; i++) { if(g == r[i].no_housing) { printf("房屋編號\n"); printf("%d\n", r[i].no_housing); return; } } printf("抱歉!沒有查詢到該房屋的相關資訊\n"); } void show_rental_registration_information()//顯示租房登記資訊 { int i; printf("\n"); printf("您現在進入的是三級選單<顯示租房登記資訊>\n"); printf("現在所有的租房登記資訊有:\n\n"); printf("租客姓名 租客所租房子的房產證號 租客入住時間 租房合同號 備註\n"); printf("--------------------------------------------------------------------\n"); printf("林軒 123456789 2013.4.2 645132 無\t\n"); printf("陳沐陽 654987123 2015.2 123465 無\t\n"); for(i = 0; i < l; i++) { printf("%s %d %s %d %s\n", r[i].name, r[i].no_housing, r[i].check_in_time, r[i].contract_number, r[i].remark); } printf("\n"); return; } void add_rental_registration_information()//新增租房登記資訊 { int i; int certain = 1; char c; printf("\n"); printf("您現在進入的是三級選單<新增租房登記資訊>"); printf("\n"); printf("現在我們開始錄入資料\n"); printf("\n"); while(certain) { for(i = l; i < 10; i++) { printf("請輸入租客姓名:"); scanf("%s", r[i].name); printf("請輸入租客所租房子的房產證號:"); scanf("%d", &r[i].no_housing); printf("請輸入租客入住時間:"); scanf("%s", r[i].check_in_time); printf("請輸入租客所籤的租房合同號:"); scanf("%d", &r[i].contract_number); printf("請輸入需要輸入的備註;"); scanf("%s", r[i].remark); l++; printf("是否繼續錄入?(用Y和N表示)"); scanf("%s", &c); if(c == 'Y') { certain = 1; } else if(c == 'N') { certain = 0; printf("恭喜!輸入完成!\n"); break; } } } }