图书管理系统
分类:
IT文章
•
2022-05-17 11:12:17
实现图书的入库,查询,更新,读者的借阅和还书的图书管理系统
1 #include <iostream>
2 #include <cstring>
3 #include<cstdio>
4 #include<windows.h>
5 #include "xiaa.h"
6 using namespace std;
7 char displayMenu()
8 {
9 cout<<"==========================================="<<endl;
10 cout<<" 欢迎来到山商图书管理系统 "<<endl;
11 cout<<"==========================================="<<endl;
12 cout<<" 1.添加图书 2.修改图书 "<<endl;
13 cout<<" 3.查询图书 4.显示所有图书 "<<endl;
14 cout<<" 5.借书 6.还书 "<<endl;
15 cout<<" 0.退出 "<<endl;
16 cout<<"==========================================="<<endl;
17 cout<<"请在(0-6)内选择您的操作: "<<endl;
18 char m;
19 cin>>m;
20 return m;
21 }
22 int main()
23 {
24 Login a;
25 string UserName;
26 a.UserMenu();
27 BookManage List(100);
28 int choice=1,num=3,pos;
29 while(true)
30 {
31 choice=displayMenu();
32 switch(choice)
33 {
34 case '0':
35 {
36 return 0;
37 }
38 case '1':
39 {
40 List.add_book();
41 break;
42 }
43 case '2':
44 {
45 List.reviseBook();
46 break;
47 }
48 case '3':
49 {
50 List.search_book();
51 break;
52 }
53 case '4':
54 {
55 List.OutputAll();
56 break;
57 }
58 case '5':
59 {
60 List.borrow_book();
61 break;
62 }
63 case '6':
64 {
65 List.giveBook();
66 break;
67 }
68 default :
69 {
70 cout<<"您输入的信息有误,请重新输入!"<<endl;
71 }
72 }
73 cout<<"请按任意键继续..."<<endl;
74 char ch=getchar();
75 if(ch=='
')
76 getchar();
77 system("cls");
78 }
79 return 0;
80 }
Main
1 #ifndef XIAA_H_INCLUDED
2 #define XIAA_H_INCLUDED
3 #include<iostream>
4 #include<cstring>
5 #include<map>
6 #include<cstdio>
7 #include<list>
8 #include<vector>
9 using namespace std;
10 typedef struct node
11 {
12 string bookName;//书名
13 string bookPublisher;//出版社名
14 int year;//借阅年份
15 int month;
16 int day;
17 }Node;
18 class book
19 {
20 public:
21 book();//构造函数
22 ~book();//析构函数
23 void input(string *&);//输入图书信息
24 void set_port(string *&);
25 void add(string*);//添加图书
26 void show_book();//显示特定的图书
27 string getbook_name();//返回图书姓名
28 string getbook_aulthor();//返回图书作者
29 string getbook_publisher();//返回图书出版社
30 int getbook_val();//返回图书价格
31 int getbook_amount();//返回图书总数
32 int getbook_sumBorrow();//返回图书借阅人数
33 void set_portBorrow(string,string);//类外访问借阅人信息的端口
34 void reviseBname(string);//修改书名
35 void reviseBaul(string);//修改作者
36 void reviseBpub(string);//修改出版社
37 void reviseBval(int);//修改单价
38 void reviseBamount(int );//修改该图书数量
39 void reviseBsurplus(int );//修改图书剩余量
40 private:
41 string book_author;//作者
42 string book_name;//书名
43 string book_publisher;//出版商
44 int book_val;//价格
45 int sumBorrow;//借阅数量
46 int sum;//该图书总数
47 };
48 class User
49 {
50 public:
51 User();
52 ~User();
53 string getUserName();//返回用户(读者)姓名
54 int judge_date(int,string,string);//判断是否违约交罚款
55 int find_Man(string);//判断这个人是否借书并返回借书的序号
56 bool cal_date(int,int,int,int);//计算还书天数
57 void BorrowBook(string,string,string);//借书
58 private:
59 string UserName;//读者姓名
60 int sum;//读者借书总数
61 map<string,int>mp;
62 vector<Node>opp;
63 };
64 class BookManage
65 {
66 public:
67 BookManage(int up=100);//缺省构造函数
68 ~BookManage();//析构函数
69 void add_book();//添加一个图书
70 void OutputAll();//显示所有图书
71 void revise(int );//修改图书
72 void show_book(int );//显示图书
73 void saveFile();//将图书信息存储到文件
74 void readFile();//从文件中读取
75 bool judge(string,string,string);//判断图书系统中是否有要添加的图书
76 void search_book();//查询图书
77 char search_Menu();//查询菜单
78 void search_bname();//书名查询
79 void search_bpub();//出版商查询
80 void search_baul();//作者查询
81 void search_bval();//价格区间查询
82 void borrow_book();//借书
83 void update(string);//更新
84 void updateIndex(string,string);
85 void Index(string);//添加索引
86 bool judgeBook(string);//判读图书是否存在
87 int borrow_Menu(string &,int );//借书图书选择菜单
88 void reviseBook();//修改图书
89 char reviseMenu();//修改菜单
90 int reviseChooseMenu(string &);//修改选择菜单
91 void outputIndex();//索引目录
92 void giveBook();//还书
93 bool judgeInput(int,int,int);//输入字符判断是否有效
94 void Delete(int );//删除图书
95 private :
96 list<book>pCe;
97 list<User>user;
98 int Count;//图书种类数
99 int maxCount;//图书系统种类容量
100 map<string,int>IpndeX;//图书索引
101 };
102 class Login
103 {
104 public:
105 Login();//构造函数
106 ~Login();//析构函数
107 void readFile(string*&,string*&,int&);//从数据库中读取所有用户信息
108 void saveFile(string,string,ostream &out=cout);//存储用户
109 bool judgeStatus(string,string);//判断身份
110 char MainMenu();//界面菜单
111 void UserMenu();//用户菜单
112 };
113 #endif // XIAA_H_INCLUDED
xia.h
1 #include "xiaa.h"
2 #include<iostream>
3 #include<cstring>
4 #include<time.h>
5 #include<map>
6 #include<windows.h>
7 #include<cstdlib>
8 #include<sstream>
9 #include<conio.h>
10 #include<map>
11 #include<cstdio>
12 #include<fstream>
13 #include<istream>
14 const int return_date=23;
15 using namespace std;
16 list<book>::iterator it;
17 list<User>::iterator re;
18 map<string,int>::iterator iter;
19 book::book()
20 {
21 sumBorrow=0;
22 }
23 book::~book()
24 {
25
26 }
27 void book::set_port(string *&b)
28 {
29 b[0]=getbook_name();
30 b[1]=getbook_aulthor();
31 b[2]=getbook_publisher();
32 }
33 string book::getbook_name()
34 {
35 return this->book_name;
36 }
37 string book::getbook_aulthor()
38 {
39 return this->book_author;
40 }
41 string book::getbook_publisher()
42 {
43 return this->book_publisher;
44 }
45 int book::getbook_val()
46 {
47 return this->book_val;
48 }
49 int book::getbook_sumBorrow()
50 {
51 return this->sumBorrow;
52 }
53 int book::getbook_amount()
54 {
55 return this->sum;
56 }
57 void book::reviseBsurplus(int flag)
58 {
59 if(flag)
60 this->sumBorrow++;
61 else
62 this->sumBorrow--;
63 }
64 void User::BorrowBook(string uName,string bname,string bpub)
65 {
66 SYSTEMTIME st= {0};
67 GetLocalTime(&st);
68 this->UserName=uName;
69 this->sum++;
70 Node t;
71 t.bookName=bname;
72 t.bookPublisher=bpub;
73 t.year=st.wYear;
74 t.month=st.wMonth;
75 t.day=st.wDay;
76 opp.push_back(t);
77 }
78 bool BookManage::judge(string bName,string Aul,string bPub)
79 {
80 list<book>::iterator it;
81 for(it=pCe.begin(); it!=pCe.end(); it++)
82 {
83 int cnt=0;
84 string *b;
85 b=new string[5];
86 (*it).set_port(b);
87 if(b[0]==bName&&b[1]==Aul&&b[2]==bPub)
88 return false;
89 }
90 return true;
91 }
92 void book::input(string *&bk)
93 {
94
95 cout<<"请输入书名: ";
96 cin>>bk[0];
97 cout<<"作者:";
98 cin>>bk[1];
99 cout<<"出版社:";
100 cin>>bk[2];
101 cout<<"价值:";
102 cin>>bk[3];
103 cout<<"数量:";
104 cin>>bk[4];
105 }
106 void book::show_book()
107 {
108 cout<<"==========================="<<endl;
109 cout<<"书名: "<<this->book_name<<endl;
110 cout<<"作者: "<<this->book_author<<endl;
111 cout<<"出版社: "<<this->book_publisher<<endl;
112 cout<<"价值: "<<this->book_val<<endl;
113 cout<<"已借阅: "<<this->sumBorrow<<"人次"<<endl;
114 cout<<"共有: "<<this->sum<<"本"<<endl;
115 cout<<"==========================="<<endl;
116 cout<<endl;
117 cout<<endl;
118 }
119 void book::add(string *b)
120 {
121 book_name=b[0];
122 this->book_author=b[1];
123 this->book_publisher=b[2];
124 this->book_val=std::atoi(b[3].c_str());
125 this->sum=std::atoi(b[4].c_str());
126 }
127 bool User::cal_date(int year,int mon,int day,int pos)
128 {
129 int dis[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
130 if((year-opp[pos].year)>2)
131 return true;
132 int cnt=0,temp=0;
133 temp=opp[pos].day;
134 if((year-opp[pos].year)==1)
135 {
136 for(int i=opp[pos].month; i<=12; i++)
137 {
138 if((opp[pos].year%400==0||(opp[pos].year%4==0&&opp[pos].year%100!=0))&&i==2)
139 cnt+=29;
140 else
141 cnt+=dis[i];
142 }
143 for(int i=1; i<mon; i++)
144 {
145 if((opp[pos].year%400==0||(opp[pos].year%4==0&&opp[pos].year%100!=0))&&i==2)
146 cnt+=29;
147 else
148 cnt+=dis[i];
149 }
150 cnt=cnt-temp+day;
151 }
152 else
153 {
154 temp=opp[pos].day;
155 for(int i=opp[pos].month; i<mon; i++)
156 {
157 if((opp[pos].year%400==0||(opp[pos].year%4==0&&opp[pos].year%100!=0))&&i==2)
158 cnt+=29;
159 else
160 cnt+=dis[i];
161 }
162 if(opp[pos].month==mon)
163 cnt=day-opp[pos].day;
164 else
165 cnt=cnt-temp+day;
166 }
167 if(cnt>return_date)
168 return false;
169 return true;
170 }
171 int User::judge_date(int pos,string bName,string bpub)
172 {
173 int flag=0,i;
174 vector<Node>::iterator temp;
175 for(int i=0; i<sum; i++)
176 {
177 if(opp[i].bookName==bName&&opp[i].bookPublisher==bpub)
178 {
179 flag=1;
180 pos=i;
181 break;
182 }
183 }
184 if(!flag)
185 {
186 cout<<"对不起,您并未借此书或者该书您已还!"<<endl;
187 return 0;
188 }
189 int year,mon,day;
190 cout<<"请输入还书日期: "<<endl;
191 cout<<"月份: ";
192 cin>>year;
193 cout<<"年份:";
194 cin>>mon;
195 cout<<"日子:";
196 cin>>day;
197 if(cal_date(year,mon,day,pos)==false)
198 {
199 cout<<"按照规定,逾期还书应交罚款30元"<<endl;
200 }
201 else
202 {
203 cout<<"恭喜您在合理的期限还书,棒棒的!"<<endl;
204 }
205 for(temp=opp.begin(),i=0; temp!=opp.end(); temp++,i++)
206 {
207 if(pos==i)
208 {
209 opp.erase(temp);
210 break;
211 }
212 }
213 return 1;
214 }
215 bool BookManage::judgeInput(int from,int to,int tar)
216 {
217 if((tar)>=from&&(tar)<=to)
218 return true;
219 return false;
220 }
221 void BookManage::add_book()
222 {
223 int num,i;
224 cout<<"请输入您要添加图书的数量:"<<endl;
225 cin>>num;
226 string *bk;
227 bk=new string[5];
228 int cnt=Count;
229 book t;
230 pCe.push_back(t);
231 for(i=0; i<num; i++)
232 {
233 it=pCe.end();
234 it--;
235 (*it).input(bk);
236 cout<<(*it).getbook_name()<<endl;
237 if(judge(bk[0],bk[1],bk[2])==true)
238 {
239 (*it).add(bk);
240 Count++;
241 Index(bk[0]);
242 }
243 else
244 {
245 cout<<"对不起,这本书已存在,您无法添加"<<endl;
246 pCe.pop_back();
247 }
248 if(i+1!=num)
249 pCe.push_back(t);
250 }
251 }
252 BookManage::~BookManage()
253 {
254 for(it=pCe.begin();it!=pCe.end();it++)
255 {
256 pCe.erase(it);
257 }
258 for(re=user.begin();re!=user.end();re++)
259 {
260 user.erase(re);
261 }
262 }
263 BookManage::BookManage(int up)
264 {
265 maxCount=up;
266 Count=0;
267 }
268 char BookManage::search_Menu()
269 {
270 cout<<"========================================"<<endl;
271 cout<<" 查询菜单 "<<endl;
272 cout<<"========================================"<<endl;
273 cout<<" 1.按书名查找 "<<endl;
274 cout<<" 2.按作者查找 "<<endl;
275 cout<<" 3.按出版社查找 "<<endl;
276 cout<<" 4.按价格区间查找 "<<endl;
277 cout<<" 0.退出 "<<endl;
278 cout<<"========================================"<<endl;
279 cout<<"请在(0,4)内选择您要执行的操作:";
280 char m;
281 cin>>m;
282 return m;
283
284 }
285 void BookManage::search_bname()
286 {
287 string sr;
288 cout<<"请输入您要查找的姓名:";
289 cin>>sr;
290 map<int,int>str;
291 int i=0;
292 for(it=pCe.begin(),i=0; it!=pCe.end(); it++,i++)
293 {
294 if((*it).getbook_name()==sr)
295 str[i]++;
296 }
297 cout<<"一共查询到满足条件的书籍有"<<str.size()<<"本"<<endl;
298 for(it=pCe.begin(),i=0; it!=pCe.end(); it++,i++)
299 {
300 if(str.count(i))
301 (*it).show_book();
302 }
303 }
304 void BookManage::search_baul()
305 {
306 string sr;
307 cout<<"请输入您要查找的作者:";
308 cin>>sr;
309 map<int,int>str;
310 int i=0;
311 for(it=pCe.begin(),i=0; it!=pCe.end(); it++,i++)
312 {
313 if((*it).getbook_aulthor()==sr)
314 str[i]++;
315 }
316 cout<<"一共查询到满足条件的书籍有"<<str.size()<<"本"<<endl;
317 for(it=pCe.begin(),i=0; it!=pCe.end(); it++,i++)
318 {
319 if(str.count(i))
320 (*it).show_book();
321 }
322 }
323 void BookManage::search_bpub()
324 {
325 string sr;
326 cout<<"请输入您要查找的出版社:";
327 cin>>sr;
328 map<int,int>str;
329 int i=0;
330 for(it=pCe.begin(),i=0; it!=pCe.end(); it++,i++)
331 {
332 if((*it).getbook_publisher()==sr)
333 str[i]++;
334 }
335 cout<<"一共查询到满足条件的书籍有"<<str.size()<<"本"<<endl;
336 for(it=pCe.begin(),i=0; it!=pCe.end(); it++,i++)
337 {
338 if(str.count(i))
339 (*it).show_book();
340 }
341 }
342 void book::reviseBname(string sr)
343 {
344 this->book_name=sr;
345 }
346 void book::reviseBaul(string sr)
347 {
348 this->book_author=sr;
349 }
350 void book::reviseBpub(string sr)
351 {
352 this->book_publisher=sr;
353 }
354 void book::reviseBval(int value)
355 {
356 this->book_val=value;
357 }
358 void book::reviseBamount(int Sum)
359 {
360 this->sum=Sum;
361 }
362 void BookManage::Delete(int pos)
363 {
364 int i;
365 for(it=pCe.begin(),i=0; it!=pCe.end(); i++,it++)
366 {
367 if(pos==i)
368 {
369 pCe.erase(it);
370 return;
371 }
372 }
373 }
374 void BookManage::search_bval()
375 {
376 int from,to,i;
377 cout<<"请输入您要查找的价格区间:"<<"从:";
378 cin>>from;
379 cout<<"到:";
380 cin>>to;
381 map<int,int>str;
382 for(it=pCe.begin(),i=0; it!=pCe.end(); it++,i++)
383 {
384 if((*it).getbook_val()>=from&&(*it).getbook_val()<=to)
385 str[i]++;
386 }
387 cout<<"一共查询到满足条件的书籍有"<<str.size()<<"本"<<endl;
388 for(it=pCe.begin(),i=0; it!=pCe.end(); it++,i++)
389 {
390 if(str.count(i))
391 (*it).show_book();
392 }
393 }
394 void BookManage::search_book()
395 {
396 int choice=1;
397 while(1)
398 {
399 choice=search_Menu();
400 switch(choice)
401 {
402 case '0':
403 {
404 return ;
405 }
406 case '1':
407 {
408 search_bname();
409 break;
410 }
411 case '2':
412 {
413 search_baul();
414 break;
415 }
416 case '3':
417 {
418 search_bpub();
419 break;
420 }
421 case '4':
422 {
423 search_bval();
424 break;
425
426 }
427 default :
428 {
429 cout<<"您输入的信息有误,请重新输入!"<<endl;
430 }
431 }
432 cout<<"请按任意键继续..."<<endl;
433 char ch=getchar();
434 if(ch=='
')
435 getchar();
436 system("cls");
437 }
438 }
439 int BookManage::borrow_Menu(string &str,int num)
440 {
441 cout<<"======================================"<<endl;
442 cout<<" 图书选择系统 "<<endl;
443 cout<<"======================================"<<endl;
444 int i,cnt=0;
445 for(it=pCe.begin(),i=0; it!=pCe.end()&&cnt<num; it++,i++)
446 {
447 int pos=(str[cnt]-'0');
448 if(pos==i)
449 {
450 cout<<" "<<++cnt<<". "<<(*it).getbook_aulthor()<<endl;
451 }
452 }
453 cout<<"======================================"<<endl;
454 cout<<"请在(1,"<<num<<")内选择您要执行的操作:";
455 int m;
456 while(cin>>m)
457 {
458 if(judgeInput(0,num,m)==false)
459 {
460 cout<<"您输入的格式不正确,请重新输入"<<endl;
461 }
462 else
463 break;
464 };
465 return m;
466 }
467 void BookManage::update(string sr)
468 {
469 int flag=0,cnt=0,i=0;
470 string str,boname,ss[2],kmp;
471 for(it=pCe.begin(),i=0; it!=pCe.end(); it++,i++)
472 {
473 if((*it).getbook_name()==sr)
474 {
475 if((*it).getbook_sumBorrow()<(*it).getbook_amount())
476 {
477 str+=i+'0';
478 cnt++;
479 flag=1;
480 }
481 }
482 }
483 if(!flag)
484 {
485 cout<<"对不起,您要借的书被借走了"<<endl;
486 }
487 else
488 {
489 cout<<"一共查询到该书籍"<<cnt<<"个版本"<<endl;
490 cout<<"为了还书方便请留下您的姓名:";
491 cin>>boname;
492 int pos=borrow_Menu(str,cnt);
493 pos=(str[pos-1]-'0');
494 for(it=pCe.begin(),i=0; it!=pCe.end(); it++,i++)
495 {
496 if(i==pos)
497 {
498 (*it).reviseBsurplus(1);
499 kmp=(*it).getbook_publisher();
500 User t;
501 user.push_back(t);
502 re=user.end();
503 re--;
504 (*re).BorrowBook(boname,sr,kmp);
505 break;
506 }
507 }
508 }
509 }
510 void BookManage::Index(string sr)
511 {
512 IpndeX[sr]++;
513 }
514 bool BookManage::judgeBook(string sr)
515 {
516 if(IpndeX.count(sr))
517 return true;
518 return false;
519 }
520 void BookManage::borrow_book()
521 {
522 cout<<"请输入您要查找的书名"<<endl;
523 string sr;
524 cin>>sr;
525 if(judgeBook(sr)==false)
526 {
527 cout<<"对不起,您要查找的图书不存在!"<<endl;
528 return ;
529 }
530 update(sr);
531 }
532 void BookManage::OutputAll()
533 {
534 for(it=pCe.begin(); it!=pCe.end(); it++)
535 {
536 (*it).show_book();
537 }
538 }
539 char BookManage::reviseMenu()
540 {
541 system("cls");
542 cout<<"================================="<<endl;
543 cout<<" 图书修改菜单 "<<endl;
544 cout<<"================================="<<endl;
545 cout<<" 1.修改图书名 "<<endl;
546 cout<<" 2.修改作者名 "<<endl;
547 cout<<" 3.修改出版社名 "<<endl;
548 cout<<" 4.修改单价 "<<endl;
549 cout<<" 5.修改数量 "<<endl;
550 cout<<" 6.删除图书 "<<endl;
551 cout<<" 0.退出 "<<endl;
552 cout<<"================================="<<endl;
553 cout<<"请在(0,6)内选择您要执行的操作:";
554 char m;
555 return m;
556 }
557 void BookManage::reviseBook()
558 {
559 cout<<"请输入您要修改的图书名"<<endl;
560 string sr;
561 cin>>sr;
562 if(judgeBook(sr)==false)
563 {
564 cout<<"对不起,您要查找的图书不存在!"<<endl;
565 return;
566 }
567 char choice;
568 int val,i=0;
569 string str;
570 for(it=pCe.begin(),i=0; it!=pCe.end(); it++,i++)
571 {
572 if((*it).getbook_name()==sr)
573 str+=i+'0';
574 }
575 cout<<"共查询到满足条件的书籍有"<<str.size()<<"种"<<endl;
576 int pos=borrow_Menu(str,str.size());
577 pos=(str[pos-1]-'0');
578 while(true)
579 {
580 choice=reviseMenu();
581 string ssr;
582 switch(choice)
583 {
584 case '0':
585 {
586 return;
587 }
588 case '1':
589 {
590 cout<<"请输入修改之后的书名:";
591 cin>>ssr;
592 (*it).reviseBname(ssr);
593 for(iter=IpndeX.begin(); iter!=IpndeX.end(); iter++)
594 {
595 if(iter->first==sr)
596 {
597 iter->second--;
598 if(iter->second==0)
599 {
600 IpndeX.erase(iter);
601 }
602 IpndeX[ssr]++;
603 }
604 }
605 break;
606 }
607 case '2':
608 {
609 cout<<"请输入修改之后的作者名:";
610 cin>>ssr;
611 (*it).reviseBaul(ssr);
612 break;
613 }
614 case '3':
615 {
616 cout<<"请输入修改之后的出版社名:";
617 cin>>ssr;
618 (*it).reviseBpub(ssr);
619 break;
620 }
621 case '4':
622 {
623 cout<<"请输入修改之后的单价:";
624 cin>>val;
625 (*it).reviseBval(val);
626 break;
627 }
628 case '5':
629 {
630 cout<<"请输入修改之后的图书数量:";
631 cin>>val;
632 (*it).reviseBamount(val);
633 break;
634 }
635 case '6':
636 {
637 Delete(pos);
638 break;
639 }
640 default :
641 {
642 cout<<"您输入的信息有误,请重新输入!"<<endl;
643 }
644 }
645 cout<<"请按任意键继续..."<<endl;
646 char ch=getchar();
647 if(ch=='
')
648 getchar();
649 system("cls");
650 }
651 }
652 User::User()
653 {
654 sum=0;
655 }
656 User::~User()
657 {
658
659 }
660 string User::getUserName()
661 {
662 return this->UserName;
663 }
664 void BookManage::giveBook()
665 {
666 cout<<"请输入您要还的书: ";
667 string sr,str,Sname,bpub;
668 int i;
669 cin>>sr;
670 if(judgeBook(sr)==false)
671 {
672 cout<<"对不起,您要换的书不存在,请回!"<<endl;
673 return ;
674 }
675 for(it=pCe.begin(),i=0; it!=pCe.end(); it++,i++)
676 {
677 if((*it).getbook_name()==sr)
678 {
679 str+=i+'0';
680 }
681 }
682 cout<<"一共查询到满足条件的书籍有"<<str.size()<<"本"<<endl;
683 int pos=borrow_Menu(str,str.size()),flag=0,cnt;
684 pos=(str[pos-1]-'0');
685 cout<<"请输入您的姓名:";
686 cin>>Sname;
687 for(it=pCe.begin(),i=0; it!=pCe.end(); it++,i++)
688 {
689 if(i==pos)
690 {
691 bpub=(*it).getbook_publisher();
692 break;
693 }
694 }
695 for(re=user.begin(); re!=user.end(); re++)
696 {
697 if((*re).getUserName()==Sname)
698 {
699 flag=1;
700 cnt=(*re).judge_date(pos,sr,bpub);
701 }
702 }
703 if(!flag)
704 {
705 cout<<"对不起,后台显示您并没有借书记录"<<endl;
706 }
707 else
708 {
709 if(it==pCe.end())
710 {
711 it--;
712 }
713 (*it).reviseBsurplus(0);
714 }
715 }
716 int User::find_Man(string sr)
717 {
718 for(int i=0; i<sum; i++)
719 {
720 if(opp[i].bookName==sr)
721 return i;
722 }
723 return -1;
724 }
725 Login::Login()
726 {
727
728 }
729 Login::~Login()
730 {
731
732 }
733 void Login::readFile(string*&tar,string*& bk,int &cnt)
734 {
735 ifstream file1;
736 file1.open("d:\Login.txt");
737 string sno,scret,s,t;
738 cnt=1;
739 while(getline(file1,s))
740 {
741 if(s.size()==0)
742 break;
743 sno=s.substr(4,s.size()-4);
744 getline(file1,t);
745 scret=t.substr(6,t.size()-6);
746 tar[cnt]=sno;
747 bk[cnt++]=scret;
748 }
749 file1.close();
750 }
751 bool Login::judgeStatus(string sno,string scret)
752 {
753 string *LoginNum,*LoginPass;
754 LoginNum=new string[100];
755 LoginPass=new string [100];
756 int cnt;
757 readFile(LoginNum,LoginPass,cnt);
758 for(int i=1; i<=cnt; i++)
759 {
760 if(LoginNum[i]==sno&&LoginPass[i]==scret)
761 {
762 return true;
763 }
764 }
765 return false;
766 }
767 void Login::saveFile(string sn,string spass,ostream &out)
768 {
769 out<<"sno:"<<sn<<endl;
770 out<<"scret:"<<spass<<endl;
771 }
772 char Login::MainMenu()
773 {
774 string sno,scret;
775 cout<<"=========================================="<<endl;
776 cout<<" 欢迎来到山商在线图书馆 "<<endl;
777 cout<<"=========================================="<<endl;
778 cout<<" 1.登录 "<<endl;
779 cout<<" 2.注册 "<<endl;
780 cout<<" 0.退出 "<<endl;
781 cout<<"=========================================="<<endl;
782 cout<<"请选择:";
783 char m;
784 cin>>m;
785 return m;
786 }
787 void Login::UserMenu()
788 {
789 int choice=1,ch='1';
790 string sno,scret;
791 while(1)
792 {
793 choice=MainMenu();
794 if(choice=='1')
795 {
796 system("cls");
797 cout<<" 注册账号 "<<endl;
798 cout<<"请输入学号/职工号: ";
799 cin>>sno;
800 cout<<"请输入密码:";
801 getchar();
802 while(ch!=' ')
803 {
804 ch=getch();
805 putchar(ch);
806 if(ch==13&&scret.size()>0)
807 {
808 printf(" ");
809 }
810 else
811 {
812 scret+=ch;
813 }
814 }
815 if(judgeStatus(sno,scret)==false)
816 {
817 cout<<"您输入的信息有误请重新输入"<<endl;
818 continue;
819 }
820 break;
821 }
822 else if(choice=='2')
823 {
824 system("cls");
825 while(1)
826 {
827 cout<<"学号/职工号: ";
828 cin>>sno;
829 cout<<"密码 : ";
830 cin>>scret;
831 if(sno.size()<8||scret.size()<6)
832 {
833 cout<<"您的账号不足8位或者密码不足6位,请重新输入"<<endl;
834 continue;
835 }
836 break;
837 }
838 if(judgeStatus(sno,scret)==true)
839 {
840 cout<<"您已经注册过该账号,尴尬了小老弟!"<<endl;
841 }
842 else
843 {
844 ofstream file;
845 file.open("d:\Login.txt",ios::app);
846 saveFile(sno,scret,file);
847 file.close();
848 cout<<"恭喜您注册成功"<<endl;
849 }
850 }
851 else if(choice=='0')
852 {
853 break;
854 }
855 else
856 {
857 cout<<"对不起,您输入的格式不对"<<endl;
858 }
859 cout<<"请按任意键继续"<<endl;
860 char ch=getchar();
861 if(ch=='
')
862 getchar();
863 system("cls");
864 }
865 }