当前位置:   article > 正文

信息查询系统源码

查询系统源码

基于本地的个人信息查询系统源码

基于C语言的个人信息查询系统源码,使用contact.txt存储,本地不存在则会自动创建。

  1. 问题描述
    人们在日常生活中经常需要查找某个人或某个单位的电话号码,本实验将实现一个简单的个人电话号码查询系统,根据用户输入的信息(例如姓名等)进行快速查询。
  2. 基本要求
    ⑴ 在外存上,用文件保存电话号码信息;
    ⑵ 在内存中,设计数据结构存储电话号码信息;
    ⑶ 提供查询功能:根据姓名实现快速查询;
    ⑷ 提供其他维护功能:例如插入、删除、修改等。
  3. 设计思想
    由于需要管理的电话号码信息较多,而且要在程序运行结束后仍然保存电话号码信息,所以电话号码信息采用文件的形式存放到外存中。在系统运行时,需要将电话号码信息从文件调入内存来进行查找等操作,为了接收文件中的内容,要有一个数据结构与之对应,可以设计如下结构类型的数组来接收数据:
    const int max = 10;
    struct TeleNumber
    {
    char name[10]; //姓名,最多4个汉字
    char phoneNumber[10]; //固定电话号码,最多9位
    char mobileNumber[12]; //移动电话号码,最多11位
    char email[20]; //电子邮箱,最多19个字符
    } Tele[max];
    为了实现对电话号码的快速查询,可以将上述结构数组排序,以便应用折半查找,但是,在数组中实现插入和删除操作的代价较高。如果记录需频繁进行插入或删除操作,可以考虑采用二叉排序树组织电话号码信息,则查找和维护都能获得较高的时间性能。更复杂地,需要考虑该二叉排序树是否平衡,如何使之达到平衡。
1. #include <stdio.h>
2. #include <string.h>
3. #include <stdlib.h>
4.
5. #define NAME_MAX 20
6. #define MAIL_MAX 30
7. #define MAX 1000
8. #define DEFAULT_sz 3
9. struct PeoInfo{
10. char name[NAME_MAX];
11. long long phone;
12. long long tel;
13. char mail[MAIL_MAX];
14. };
15. struct Contact{
16. struct PeoInfo* data;
17. int sz;//记录通讯录中当前有效元素的个数
18. int capacity;//通讯录当前最大的容量
19. };
20. void menu(){//功能列表
21. puts("1.add 2.del 3.search 4.modify 0.exi
t");
22. }
23. void Checkcapacity(struct Contact* pc){//核查通讯录容量
24. if (pc->sz == pc->capacity){
25. struct PeoInfo* ptr = (st
ruct PeoInfo*)realloc(pc->data, (pc->capacity + 2)*sizeof(s
truct PeoInfo));//扩容
26. if (ptr != NULL){
27. pc->data =
ptr;
28. pc->capacity
+= 2;
29.
30. printf("增容
成功\n");
31. }
32. else{
33. perror("通讯
录增容失败");
34. exit(1);
35. }
36. }
37. }
38. void LoadContact(struct Contact* pc){//加载文件信息到通讯
录
39. FILE* pf = fopen("contact.txt", "rb");//
打开文件
40. if (NULL == pf) {
41. perror("LoadContact::fopen");
//打印出错误信息
42. return;
43. }
44. struct PeoInfo temp = { 0 };
45. while (fread(&temp, sizeof(struct PeoInfo)
, 1, pf)){
46. Checkcapacity(pc);//容量核查
47. pc->data[pc->sz] = temp;
48. pc->sz++;
49. }
50. fclose(pf);//关闭文件
51. pf = NULL;
52. }
53. void InitContact(struct Contact* pc){//初始化通讯录
54. pc->sz = 0;
55. pc->data = (struct PeoInfo*)malloc(3 * s
izeof(struct PeoInfo));
56. pc->capacity = DEFAULT_sz;
57. LoadContact(pc);//加载文件信息到通讯录中
58. }
59. void AddContact(struct Contact* pc){//增加联系人
60. Checkcapacity(pc);
61. puts("请输入名字:>");
62. scanf("%s", pc->data[pc->sz].name);
63. puts("请输入电话:>");
64. scanf("%lld", &pc->data[pc->sz].phone);
65. puts("请输入固定电话:>");
66. scanf("%lld", &pc->data[pc->sz].tel);
67. puts("请输入邮箱:>");
68. scanf("%s", pc->data[pc->sz].mail);
69. pc->sz++;
70. puts("增加成功\n");
71. }
72. int FindContactByName(const struct Contact* pc,char name
[]){
73. for (int i = 0; i < pc->sz; i++)
{
74. if (strcmp(pc->data[i].name,
name) == 0) {
75. return i;
76. }
77. }
78. return -1;
79. }
80. void DelContact(struct Contact* pc){//删除指定联系人
81. if (pc->sz == 0){
82. printf("通讯录为空,无法删除
\n");
83. return;
84. }
85. char name[NAME_MAX] = {0};
86. printf("请输入要删除人的名字:>");
87. scanf("%s", name);
88. int pos = FindContactByName(pc, name);//
查找
89. if (pos == -1){
90. printf("指定的联系人不存在
\n");
91. }
92. else{//删除
93. int j = 0;
94. for ( j = pos; j < pc-
>sz - 1; j++){//把要删除元素的所有后面的元素往前移动 1
95. pc->data[j]
= pc->data[j + 1];
96. }
97. pc->sz--;
98. printf("删除成功\n");
99. }
100. }
101. void SearchContact(const struct Contact* pc){//查找指定联
系人
102. char name[NAME_MAX] = { 0 };
103. printf("输入要查找人的名字:>");
104. scanf("%s", name);
105. int pos = FindContactByName(pc, name);
106. if (-1 == pos){
107. printf("查无此人\n");
108. }
109. else{
110. printf("%15s\t%15s\t%15s\t%15
s\n\n","name","phone","tel","mail");
111. printf("%15s\t%15lld\t%15lld\
t%15s\n", pc->data[pos].name, pc->data[pos].phone, pc->data[
pos].tel, pc->data[pos].mail);
112. }
113. }
114. void ModifyContact(struct Contact* pc){//修改指定联系人
115. char name[NAME_MAX] = { 0 };
116. printf("输入要修改人的名字:>");
117. scanf("%s", name);
118. int pos = FindContactByName(pc, name);
119. if (-1 == pos) {
120. printf("要修改的人不存在\n");
121. }
122. else{
123. puts("请输入新的名字:>");
124. scanf("%s", pc->data[pos].na
me);
125. puts("请输入电话:>");
126. scanf("%lld", &pc->data[pos]
.phone);
127. puts("请输入固定电话:>");
128. scanf("%lld", &pc->data[pos]
.tel);
129. puts("请输入邮箱:>");
130. scanf("%s", pc->data[pos].ma
il);
131. }
132. }
133. void SaveContact(struct Contact* pc){//保存信息到通讯录中
134. FILE* pf = fopen("contact.txt", "wb");//
以二进制写
135. if (pf == NULL){
136. perror("SaveContact::fopen");
137. return;
138. }
139. for (int i = 0; i < pc->sz; i++){
140. fwrite(pc->data + i, sizeo
f(struct PeoInfo), 1, pf);
141. }
142. fclose(pf);
143. pf = NULL;
144. }
145. void DestroyContact(struct Contact* pc){//释放信息
146. free(pc->data);
147. pc->data = NULL;
148. pc->capacity = 0;
149. pc->sz = 0;
150. }
151. enum Option{
152. EXIT,
153. ADD,
154. DEL,
155. SEARCH,
156. MODIFY
157. };
158. int main(){//主函数部分
159. int input = 0;
160. struct Contact contact;//初始化通讯录
161. InitContact(&contact);
162. do{
163. menu();//显示目录
164. scanf("%d", &input);
165. switch (input) {
166. case ADD:
167. AddContact(&c
ontact);break;
168. case DEL:
169. DelContact(&c
ontact);break;
170. case SEARCH:
171. SearchContact
(&contact);break;
172. case MODIFY:
173. ModifyContact
(&contact);break;
174. case EXIT:
175. SaveContact(&
contact); //保存信息
176. DestroyContac
t(&contact); //释放信息
177. printf("退出
通讯录\n");
178. break;
179. default:
180. printf("选择
错误\n");
181. break;
182. }
183. } while (input);
184. return 0;
185. }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223



基于服务端的个人信息查询系统源码

使用python直接运行源码即可。.xlsx表格需要与python文件放在同一个文件夹下面。
运行命令:

python3 *.py
  • 1

后台运行命令(linux):

nohup python3 *.py >> nohup.out 2>&1 &
  • 1
import flask
import pandas as pd
from flask import request
app = flask.Flask(__name__)

@app.route("/search", methods=["GET", "POST"])//查询页面search
def search_info():
    df = pd.read_excel("search.xlsx")
    medal_data = pd.DataFrame()
    country_name = request.form.get("country_name", "")
    if country_name:
        medal_data = df.query(f"姓名 == '{country_name}'")
    return f"""
        <html><body style="text-align:center">
        <h3>查询面试结果</h3>
        <form action="/search" method="post">
            姓名:<input type="text" name="country_name" value="{country_name}">
            <input type="submit" name="submit" value="查询">
        </form>
        <center> %s </center>
        </body></html>
    """ % medal_data.to_html(index=False)
    
@app.route("/result", methods=["GET", "POST"])//查询页面为result
def query_info():
    df = pd.read_excel("result.xlsx")
    medal_data = pd.DataFrame()
    name_name = request.form.get("name_name", "")
    if name_name:
        medal_data = df.query(f"姓名 == '{name_name}'")
    return f"""
        <html><body style="text-align:center">
        <h3>查询推送等级与推送时间</h3>
        <form action="/result" method="post">
            姓名:<input type="text" name="name_name" value="{name_name}">
            <input type="submit" name="submit" value="查询">
        </form>
        <center> %s </center>
        </body></html>
    """ % medal_data.to_html(index=False)
app.run(host="0.0.0.0", port=9999)//访问端口
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

可以使用nginx做反向代理。如,改代码运行于B服务器,则可以使用已接入备案的A服务器配置反向代理隐藏服务器真实地址。
反相代理配置:
1.需要将范围页面改为/,否则无法显示返回信息。

<form action="/" method="post">
  • 1

2.反向代理:

server {
    listen 80;
    server_name search.your-domain.com;
    
    location / {
        proxy_pass http://ip_address:port/search;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
server {
    listen 80;
    server_name result.your-domain.com;
    
    location / {
        proxy_pass http://ip_address:port/result;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

【腾讯云】多款云产品1折起,买云服务器送免费机器,最长免费续3个月
【腾讯云】爆款云服务器限时体验20元起,更多上云必备产品低至1元
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得
【腾讯云】ElasticSearch新用户特惠,快速实现日志分析、应用搜索,首购低至4折
【腾讯云】腾讯云图,像PPT一样简单的数据可视化工具。5元搞定数据可视化,模板丰富,拖拖拽拽就能做出好看的可视化大屏

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/759666?site
推荐阅读
相关标签
  

闽ICP备14008679号