本文实例为大家分享了c++实现图书管理系统的具体代码,供大家参考,具体内容如下
大一 c++课设,没有用分文件的形式,只是把菜单页面单独分开了。用的是链表,都是一些基础的东西。另外采用了二维数组来保存读者借书信息,并将二维数组读入文件中。
1.首先是注册,登录,找回密码和修改密码功能,登录和注册使用了多态,并且登录页面采用了*符号加密。
2.管理员在删除图书时,若用户此时已将此书借走,则会将此书从用户的借书书单中删去,实现了动态管理。
3.容错率极高,每个页面都有返回上一页面的功能。
4.每个页面都有设置有滚键盘机制,提高了容错率。
#pragma oncevoid _mainmenu();void loginmenu();void registmenu();void readermenu();void mangermenu();void changebookmenu();void browmenu();
菜单文件
#include "menu.h"#include <cstdio>void _mainmenu(){ printf("\n\n"); printf(" 欢 迎 使 用 图 书 管 理 系 统 !\n"); printf(" **************************************************\n"); printf(" ** 1.登录 **\n"); printf(" ** **\n"); printf(" ** 2.注册 **\n"); printf(" ** **\n"); printf(" ** 3.找回密码 **\n"); printf(" ** **\n"); printf(" 个性化教育** 4.退出 **\n"); printf(" **************************************************\n"); printf("请按键选择:");}void loginmenu(){ printf(" 登录页面\n"); printf(" **************************************************\n"); printf(" ** 1.管理员登录 **\n"); printf(" ** **\n"); printf(" ** 2.用户登录 **\n"); printf(" ** **\n"); printf(" ** 3.返回 **\n"); printf(" ** **\n"); printf(" ** 4.退出 **\n"); printf(" **************************************************\n"); printf("请按键选择:");}void registmenu(){ printf(" 注册页面\n"); printf(" **************************************************\n"); printf(" ** 1.管理员注册 **\n"); printf(" ** **\n"); printf(" ** 2.用户注册 **\n"); printf(" ** **\n"); printf(" ** 3.返回 **\n"); printf(" ** **\n"); printf(" ** 4.退出 **\n"); printf(" **************************************************\n"); printf("请按键选择:");}void readermenu(){ printf(" 用户页面\n"); printf(" **************************************************\n"); printf(" ** 1.借书 **\n"); printf(" ** **\n"); printf(" ** 2.还书 **\n"); printf(" ** **\n"); printf(" ** 3.浏览图书信息 **\n"); printf(" ** **\n"); printf(" ** 4.查看已借阅书籍 **\n"); printf(" ** **\n"); printf(" ** 5.修改密码 **\n"); printf(" ** **\n"); printf(" ** 6.返回 **\n"); printf(" ** **\n"); printf(" ** 7.退出 **\n"); printf(" **************************************************\n"); printf("请按键选择:");}void mangermenu(){ printf(" 管理员页面\n"); printf(" **************************************************\n"); printf(" ** 1.增加图书 **\n"); printf(" ** **\n"); printf(" ** 2.删除图书 **\n"); printf(" ** **\n"); printf(" ** 3.修改图书信息 **\n"); printf(" ** **\n"); printf(" ** 4.查看读者信息 **\n"); printf(" ** **\n"); printf(" ** 5.浏览图书信息 **\n"); printf(" ** **\n"); printf(" ** 6.修改密码 **\n"); printf(" ** **\n"); printf(" ** 7.返回 **\n"); printf(" ** **\n"); printf(" ** 8.退出 **\n"); printf(" **************************************************\n"); printf("请按键选择:");}void changebookmenu(){ printf("\n\n"); printf("\t\t\t\t*******************************\n"); printf("\t\t\t\t** 1.修改id号 **\n"); printf("\t\t\t\t** **\n"); printf("\t\t\t\t** 2.修改图书名称 **\n"); printf("\t\t\t\t** **\n"); printf("\t\t\t\t** 3.修改图书作者 **\n"); printf("\t\t\t\t** **\n"); printf("\t\t\t\t** 4.修改出版社 **\n"); printf("\t\t\t\t** **\n"); printf("\t\t\t\t** 5.修改图书数量 **\n"); printf("\t\t\t\t** **\n"); printf("\t\t\t\t** 6.修改是否可借 **\n"); printf("\t\t\t\t** **\n"); printf("\t\t\t\t** 7.返回 **\n"); printf("\t\t\t\t*******************************"); printf("\n\n");}void browmenu(){ printf("\n\n\n\n"); printf("\t\t\t\t***********************************\n"); printf("\t\t\t\t** 1.按id号浏览 **\n"); printf("\t\t\t\t** **\n"); printf("\t\t\t\t** 2.按图书数量浏览 **\n"); printf("\t\t\t\t** **\n"); printf("\t\t\t\t** 3.返回 **\n"); printf("\t\t\t\t** **\n"); printf("\t\t\t\t** 4.退出 **\n"); printf("\t\t\t\t***********************************\n"); printf("请按键选择:");}
主程序
#define _crt_cure_no_warnings#include <iostream>#include <windows.h>#include <string>#include <fstream>#include <conio.h>#include "menu.h"using namespace std;class ur{protected : char account[20]; char password[20]; char spassword[20];public : virtual void login() = 0; virtual void regist() = 0; virtual void save() = 0; virtual void browbook() = 0; virtual void changepassword() = 0; virtual void findpassword() = 0;};class reader : public ur{private: int number; string name; string x; int books; // 借书数量 int bookcnt;// 借阅次数 char booklist[20][20];// 储存借阅书籍 class reader* next;public : virtual void login(); virtual void regist(); virtual void save(); virtual void browbook(); virtual void changepassword(); virtual void findpassword(); void creat(); void browborrowbook(reader* pp); void borrowbook(reader* pp); void returnbook(reader* pp); public : void t_number(int _number) { number = _number; }; void t_name(string _name) { name = _name; }; void t_x(string _x) { x = _x; }; void t_next(reader* p) { next = p; }; void t_books(int _books) { books = _books; }; void t_bookcnt(int _bookcnt) { bookcnt = _bookcnt; }; int get_bookcnt() { return bookcnt; }; int get_number() { return number; }; int get_books() { return books; }; reader* get_next() { return next; } string get_name() { return name; }; string get_x() { return x; }; char* get_account(reader* p) { return p->account; }; char* get_password(reader* p) { return p->password; }; char* get_spassword(reader* p) { return p->spassword; }; char* get_booklist(reader* p, int i) { return p->booklist[i]; };};class manger : public ur{private: class manger* next;public : virtual void login(); virtual void regist(); virtual void browbook(); virtual void save(); virtual void changepassword(); virtual void findpassword(); void creat(); void addbook(); void changebook(); void deletebook(); void deletereaderbook(char* bookname); void browreader(); public : void t_next(manger* p) { next = p; }; manger* get_next() { return next; }; char* get_account(manger* p) { return p->account; }; char* get_password(manger* p) { return p->password; }; char* get_spassword(manger* p) { return p->spassword; };};class book{private: int id; int amount; int flag; string bookname; string author; string press; class book* next;public : void creat(); void save(); void show_book(); void t_id(int _id) { id = _id; }; void t_amount(int _amount) { amount = _amount; }; void t_flag(int _flag) { flag = _flag; }; void t_bookname(string _bookname) { bookname = _bookname; }; void t_author(string _author) { author = _author; }; void t_press(string _press) { press = _press; }; void t_next(book* p) { next = p; }; int get_id() { return id; }; int get_amount() { return amount; }; int get_flag() { return flag; }; string get_bookname() { return bookname; }; string get_author() { return author; }; string get_press() { return press; }; book* get_next() { return next; };};class dbfile{public : void cls(); void over(); void login(); void ulogin(ur* ba); void regist(); void uregist(ur* ba); void ubrowbook(ur* ba); void usave(ur* ba); void uchangepassword(ur* ba); void ufindpassword(ur* ba); void findpassword(); int exist(char* acconut, int flag); void _main(); void idsort(); void bookamountsort(); void showidsort(); void showbookamountsort(); void mangerfunction(); void readerfunction(reader* rp);};reader* rhead = null; reader* _rend = null;manger* mhead = null, * mend = null;book* bhead = null; book* bend = null;char code[20] = "glysw";// 读者类void reader::login(){ int cnt = 4; int flag = 0; int k = 0; int i; char c; dbfile* fp = new dbfile; reader* p = rhead->get_next(); char rpassword[2000]; char raccount[2000]; cout << "\n\n\n\n\n\n\n"; printf("请输入您的账户(按0退出):"); while (cin >> raccount) { if (strcmp(raccount, "0") == 0) { return; } if (strlen(raccount) <= 16) { break; } el { cout << "请输入长度为1到16位的账户:"; } } cout << "请输入您的密码(按0退出):"; for (i = 0; (c = _getch()) != '\r';) { if (c == '0') { return; } if (i <= 15 && isprint(c)) { rpassword[i] = c; i++; k++; cout << "*"; } if (k > 0 && c > 0 && c == '\b') { i--; k--; cout << "\b"; cout << " "; cout << "\b"; } } rpassword[i] = '\0'; cout << "\n"; while (p) { if (strcmp(p->account, raccount) == 0) { flag = 1; while (strcmp(p->password, rpassword) != 0) { cnt--; if (cnt == 1) { fp->cls(); cout << "\n\n\n\n\n\n\n"; cout << "密码输入次数已用完! " << "\n" << "即将退出登录页面..."; sleep(3000); fp->cls(); return; } cout << "密码错误!您还有" << cnt - 1 << "次机会\n" << endl; cout << "请重新输入(按0退出):"; k = 0; for (i = 0; (c = _getch()) != '\r';) { if (c == '0') { return; } if (i <= 15 && isprint(c)) { rpassword[i] = c; i++; k++; cout << "*"; } if (k > 0 && c > 0 && c == '\b') { i--; k--; cout << "\b"; cout << " "; cout << "\b"; } } rpassword[i] = '\0'; cout << "\n"; } cout << "读者" << raccount << "登陆成功!\n" << "即将跳转至读者页面..." << endl; sleep(2000); fp->cls(); fp->readerfunction(p); return; } p = p->get_next(); } if (!flag) { cout << "不存在此账号!\n请先前往注册!\n" << endl; cout << "即将跳转至主页面..."; sleep(2000); }}void reader::regist(){ dbfile* fp = new dbfile; reader* rp = new reader; char raccount[2000]; char rpassword[2000]; char rspassword[2000]; char name[200]; char x[10]; int number; reader* p = new reader; cout << "\n\n\n\n\n\n\n"; cout << "请输入账户(按0退出):"; while (cin >> raccount) { if (strcmp(raccount, "0") == 0) { return; } if (strlen(raccount) <= 16 && !fp->exist(raccount, 0)) { break; } el if (fp->exist(raccount, 1)) { cout << "该账户已存在!请重新输入(按0退出):"; } el { cout << "请输入长度为1到16位的账户:"; } } strcpy_s(p->account, raccount); cout << "请输入密码(按0退出):"; while (cin >> rpassword) { if (strcmp(rpassword, "0") == 0) { return; } if (strlen(rpassword) <= 16) { break; } el { cout << "请输入长度为1到16位的密码(按0退出):"; } } strcpy_s(p->password, rpassword); cout << "请输入您的密保(按0退出):"; while (cin >> rspassword) { if (strcmp(rspassword, "0") == 0) { return; } if (strlen(rspassword) <= 16) { break; } el { cout << "请输入长度为1到16位的密保(按0退出):"; } } strcpy_s(p->spassword, rspassword); cout << "请输入您的姓名(按0退出):"; cin >> name; if (strcmp(name, "0") == 0) { return; } p->name = name; cout << "请输入您的性别(按0退出):"; while (cin >> x) { if (strcmp(x, "0") == 0) { return; } if (strcmp(x, "男") == 0 || strcmp(x, "女") == 0) { p->x = x; break; } el { cout << "请输入男或女(按0退出):"; } } cout << "请输入您的学号(按0退出):"; while (cin >> number) { if (number == 0) { return; } if (number >= 0) { p->number = number; break; } el { cout << "请输入正确格式的学号(按0退出):"; } } _rend->t_next(p); _rend = p; _rend->t_next(null); rp->save(); fp->cls(); printf("\n\n\n\n\n\n\n"); printf("\t\t\t\t\t*******************************\n"); printf("\t\t\t\t\t** **\n"); printf("\t\t\t\t\t 读者%s注册成功!! \n", raccount); printf("\t\t\t\t\t** 即将跳转至主页面... **\n"); printf("\t\t\t\t\t** **\n"); printf("\t\t\t\t\t*******************************\n"); sleep(1500);}void reader::save(){ reader* rp = rhead->get_next(); ofstream f_reader("reader.txt", ios::out); while (rp) { f_reader << rp->account << " " << rp->password << " " << rp->spassword << " " << rp->number << " " << rp->name << " " << rp->x << " " << rp->bookcnt << " " << rp->books; for (int i = 0; i < rp->bookcnt; i++) { f_reader << " " << booklist[i]; } f_reader << endl; rp = rp->get_next(); } f_reader.clo();}void reader::browbook(){ dbfile* fp = new dbfile; int sign = 0; while (1) { fp->cls(); browmenu(); char choo = _getch(); switch (choo) { ca '1': fp->cls(); fp->showidsort(); break; ca '2': fp->cls(); fp->showbookamountsort(); break; ca '3': fp->cls(); sign = 1; break; ca '4': fp->cls(); fp->over(); break; default: break; } if (sign) { break; } }}void reader::creat(){ ifstream f_reader("reader.txt", ios::in); char _account[20]; char _password[20]; char _spassword[20]; int number; int bookcnt; int books; char name[20]; char x[20]; char booklist[20][20]; while (f_reader >> _account && f_reader >> _password && f_reader >> _spassword) { reader* p = new reader; strcpy_s(p->account, _account); strcpy_s(p->password, _password); strcpy_s(p->spassword, _password); _rend->t_next(p); p->t_next(null); _rend = _rend->get_next(); } while (f_reader >> number && f_reader >> name && f_reader >> x && f_reader >> bookcnt && f_reader >> books) { reader* p = new reader; p->number = number; p->x = x; p->name = name; p->bookcnt = bookcnt; p->books = books; _rend->t_next(p); p->t_next(null); _rend = _rend->get_next(); } while (f_reader >> bookcnt) { reader* p = new reader; for (int i = 0; i < bookcnt; i++) { f_reader >> booklist[i]; strcpy_s(p->booklist[i], booklist[i]); } _rend->t_next(p); p->t_next(null); _rend = _rend->get_next(); } f_reader.clo();}void reader::browborrowbook(reader* pp){ int cnt = pp->bookcnt; long long sign; if (cnt == 0) { printf("\n\n\n\n\n\n\n"); printf("\t\t\t\t\t\t您还未借阅任何书籍!\n"); } printf("\n\n\n\n\n\n"); for (int i = 0; i < cnt; i++) { printf("\t第%d次借阅的书籍:", i + 1); printf("%s\t", pp->get_booklist(pp, i)); cout << "借阅数量:" << pp->get_books() << endl; } printf("\n\n请输入0退出:"); while (scanf("%lld", &sign)) { if (sign == 0) { break; } el { printf("-------------无效的输入!请重新输入!"); } }}void reader::borrowbook(reader* pp){ book* bp = bhead->get_next(); book* _bp = new book; _bp->show_book(); char bookname[200]; int amount; int flag = 1; int sign = 1; int exist = 0; cout << "\n\n\n\n"; cout << "请输入要借书的名称(按0退出):"; cin >> bookname; if (strcmp(bookname, "0") == 0) { return; } while (bp) { if (bp->get_bookname() == bookname) { if (bp->get_amount() == 0) { cout << "此书无余量!\n"; sign = 0; } if (bp->get_flag() == 0) { cout << "此书不可借!\n"; flag = 0; } if (sign == 1 && flag == 1) { cout << "请输入要借阅书籍的数量:"; while (cin >> amount) { if (bp->get_amount() < amount) { cout << "借阅数量超过此书已有库存!请重新输入:"; } el { int a = pp->get_books() + amount; pp->t_books(a); int b = bp->get_amount() - amount; bp->t_amount(b); break; } } pp->bookcnt++; strcpy_s(pp->booklist[pp->bookcnt - 1], bookname); pp->save(); bp->save(); exist = 1; break; } } bp = bp->get_next(); } if (exist == 0 && sign == 1 && flag == 1) { cout << "不存在此书!!\n"; } el if (exist == 1) { cout << "图书:" << bookname << "借阅成功!!\n"; } cout << "页面即将跳转..."; sleep(1200);}void reader::returnbook(reader* pp){ book* bp = bhead->get_next(); char bookname[200]; int amount; int exist = 0; int flag = 0; int cnt = pp->bookcnt; if (cnt == 0) { printf("\n\n\n\n\n\n\n"); printf("\t\t\t\t\t\t您还未借阅任何书籍!\n"); system("pau"); return; } printf("\n\n\n\n\n\n"); for (int i = 0; i < cnt; i++) { cout << "-------------第" << i + 1 << "次借阅的书籍:" << pp->booklist[i] << "\t\t"; cout << "借阅数量:" << pp->books << endl; } cout << "请输入您要退还的书籍(按0退出):"; while (cin >> bookname) { if (strcmp(bookname, "0") == 0) { return ; } for (int i = 0; i < pp->bookcnt; i++) { if (strcmp(pp->booklist[i], bookname) == 0) { flag = i; exist = 1; break; } } if (!exist) { cout << "未查询到该书!\n"; cout << "请重新输入(按0退出):"; } el { break; } } while (bp) { if (bp->get_bookname() == bookname) { cout << "请输入您要退还书籍的数量:"; while (cin >> amount) { if (pp->books < amount) { cout << "您未持有此数量的书籍!\n"; cout << "请重新输入:"; } el { int a = pp->books - amount; int b = bp->get_amount() + amount; pp->t_books(a); bp->t_amount(b); break; } } } bp = bp->get_next(); } if (pp->books == 0) { for (int i = flag; i < pp->books - 1; i++) { strcpy_s(pp->booklist[i], pp->booklist[i + 1]); } pp->bookcnt--; } pp->save(); bp->save(); cout << bookname << "退还成功!!\n"; cout << "即将返回上一页面..."; sleep(1100);}void reader::findpassword(){ reader* rp = rhead->get_next(); char password[200]; char account[200]; char spassword[200]; int flag = 0; int sign = 0; cout << "请输入您的账户(按0退出):"; while (cin >> account) { if (strcmp(account, "0") == 0) { return; } while (rp) { if (strcmp(rp->get_account(rp), account) == 0) { flag = 1; break; } rp = rp->get_next(); } if (flag) { break; } el { printf("此账号不存在!请重新输入(按0退出):"); rp = rhead->get_next(); } } if (flag) { rp = rhead->next; printf("请输入您设置的密保(按0退出):"); while (cin >> spassword) { if (strcmp(spassword, "0") == 0) { return; } while (rp) { if (strcmp(rp->get_spassword(rp), spassword) == 0) { sign = 1; break; } rp = rp->get_next(); } if (sign) { printf("密保输入正确!\n"); printf("您的密码为%s\n", rp->get_password(rp)); system("pau"); return; } el { printf("-------------密保输入错误!请重新输入(按0退出):"); rp = rhead->get_next(); } } }}void reader::changepassword(){ dbfile* fp = new dbfile; reader* p = rhead->get_next(), * rp = new reader; int flag = 0; int sign = 0; char raccount[200]; char rpassword[200]; char rspassword[200]; cout << "请输入您的账户(按0退出):"; while (cin >> raccount) { if (strcmp(raccount, "0") == 0) { return; } while (p) { if (strcmp(p->account, raccount) == 0) { flag = 1; break; } p = p->get_next(); } if (flag) { break; } el { cout << "此账号不存在!请重新输入(按0退出):"; p = rhead->get_next(); } } if (flag) { p = rhead->get_next(); cout << "请输入您设置的密保(按0退出):"; while (cin >> rspassword) { if (strcmp(rspassword, "0") == 0) { return; } while (p) { if (strcmp(p->spassword, rspassword) == 0) { sign = 1; break; } p = p->get_next(); } if (sign) { cout << "请输入修改后的密码(按0退出):"; while (cin >> rpassword) { if (strcmp(rpassword, "0") == 0) { return; } if (strlen(rpassword) <= 16) { break; } el { cout << "请输入长度为1到16位的密码(按0退出):"; } } strcpy_s(p->password, rpassword); cout << "密码修改成功!"; fp->usave(p); system("pau"); return; } el { cout << "密保输入错误!!请重新输入(按0退出):"; p = rhead->get_next(); } } }}// 数据操作类void dbfile::cls(){ system("cls");}void dbfile::over(){ dbfile* dbp = new dbfile; dbp->cls(); system("color 6"); int time = 6; printf("\n\n\n\n\n\n\n\n\n"); printf("\t\t\t\t\t\t感谢您的使用!!\n\n\n\n\n"); printf(" 程序即将关闭..."); while (--time >= 1) { printf("\r%d", time); printf("\b"); sleep(1000); } dbp->cls(); exit(0);}void dbfile::login(){ reader* rp = new reader; manger* mp = new manger; int sign = 0; while (1) { cls(); loginmenu(); char choo = _getch(); switch (choo) { ca '1': cls(); ulogin(mp); break; ca '2': cls(); ulogin(rp); break; ca '3': cls(); sign = 1; break; ca '4': cls(); over(); break; default: cout << "输入无效!!"; break; } if (sign) { break; } }}void dbfile::ulogin(ur* ba){ ba->login();}void dbfile::regist(){ reader* rp = new reader; manger* mp = new manger; int sign = 0; while (1) { cls(); registmenu(); char choo = _getch(); switch (choo) { ca '1': cls(); uregist(mp); break; ca '2': cls(); uregist(rp); break; ca '3': cls(); sign = 1; break; ca '4': cls(); over(); break; default: cout << "无效输入!!"; break; } if (sign) { break; } }}void dbfile::usave(ur* ba){ ba->save();}void dbfile::uchangepassword(ur* ba){ ba->changepassword();}void dbfile::uregist(ur* ba){ ba->regist();}void dbfile::ubrowbook(ur* ba){ ba->browbook();}void dbfile::ufindpassword(ur* ba){ ba->findpassword();}void dbfile::findpassword(){ printf("\n\n\n\n\n\n"); printf("\t\t\t\t\t********************************\n"); printf("\t\t\t\t\t** **\n"); printf("\t\t\t\t\t** 1.管理员找回密码 **\n"); printf("\t\t\t\t\t** **\n"); printf("\t\t\t\t\t** 2.用户找回密码 **\n"); printf("\t\t\t\t\t** **\n"); printf("\t\t\t\t\t** 3.返回 **\n"); printf("\t\t\t\t\t** **\n"); printf("\t\t\t\t\t********************************\n"); printf("请按键选择:"); int choo; int sign = 0; reader* rp = new reader; manger* mp = new manger; scanf("%d", &choo); while (1) { cls(); switch (choo) { ca 1: cls(); ufindpassword(mp); sign = 1; break; ca 2: cls(); ufindpassword(mp); sign = 1; break; ca 3: sign = 1; break; default: printf("输入无效!"); break; } if (sign) { break; } }}int dbfile::exist(char* account, int flag){ if (flag == 0) { reader* p = rhead->get_next(); while (p != null) { if (strcmp(account, p->get_account(p)) == 0) { return 1; } p = p->get_next(); } } el if (flag == 1) { manger* p = mhead->get_next(); while (p != null) { if (strcmp(account, p->get_account(p) ) == 0) { return 1; } p = p->get_next(); } } return 0;}void dbfile::_main(){ while (1) { cls(); _mainmenu(); char choo = _getch(); switch (choo) { ca '1': cls(); login(); break; ca '2': cls(); regist(); break; ca '3': cls(); findpassword(); break; ca '4': cls(); over(); break; default: cout << "无效输入!!"; break; } }}void dbfile::idsort(){ book* f, *x, *y, *p; f = null; if (bhead->get_next() == null || bhead->get_next()->get_next() == null) { return; } while (f != bhead->get_next()->get_next()) { for (p = bhead; p->get_next()->get_next() != f; p = p->get_next()) { if (p->get_next()->get_id() > p->get_next()->get_next()->get_id()) { x = p->get_next(); y = p->get_next()->get_next(); p->t_next(y); x->t_next(y->get_next()); y->t_next(x); } } f = p->get_next(); }}void dbfile::bookamountsort(){ book* f, * x, * y, * p; f = null; if (bhead->get_next() == null || bhead->get_next()->get_next() == null) { return; } while (f != bhead->get_next()->get_next()) { for (p = bhead; p->get_next()->get_next() != f; p = p->get_next()) { if (p->get_next()->get_amount() > p->get_next()->get_next()->get_amount()) { x = p->get_next(); y = p->get_next()->get_next(); p->t_next(y); x->t_next(y->get_next()); y->t_next(x); } } f = p->get_next(); }}void dbfile::showidsort(){ dbfile* fp = new dbfile; book* bp = new book; fp->idsort(); bp->show_book(); system("pau");}void dbfile::showbookamountsort(){ dbfile* fp = new dbfile; book* bp = new book; fp->bookamountsort(); bp->show_book(); system("pau");}void dbfile::mangerfunction(){ dbfile* fp = new dbfile; manger* mp = new manger; int sign = 0; int choo; while (1) { fp->cls(); mangermenu(); cin >> choo; switch (choo) { ca 1: fp->cls(); mp->addbook(); break; ca 2: fp->cls(); mp->deletebook(); break; ca 3: fp->cls(); mp->changebook(); break; ca 4: fp->cls(); mp->browreader(); break; ca 5: fp->cls(); mp->browbook(); break; ca 6: fp->cls(); fp->uchange初中优秀作文600字password(mp); break; ca 7: fp->cls(); sign = 1; break; ca 8: fp->cls(); fp->over(); break; default: cout << "输入无效!!"; break; } if (sign) { break; } }}void dbfile::readerfunction(reader* pp){ dbfile* fp = new dbfile; reader* rp = new reader; int sign = 0; while (1) { fp->cls(); readermenu(); char choo = _getch(); switch (choo) { ca '1': fp->cls(); rp->borrowbook(pp); break; ca '2': fp->cls(); rp->returnbook(pp); break; ca '3': fp->cls(); fp->ubrowbook(rp); break; ca '4': fp->cls(); rp->browborrowbook(pp); break; ca '5': fp->cls(); fp->uchangepassword(rp); break; ca '6': fp->cls(); sign = 1; break; ca '7': fp->over(); break; default: cout << "输入无效!!"; break; } if (sign) { break; } }}// 管理员类void manger::login(){ int cnt = 4; int flag = 0; int k = 0; int i; char c; dbfile* fp = new dbfile; manger* p = mhead->get_next(); char mpassword[2000]; char maccount[2000]; cout << "\n\n\n\n\n\n\n"; printf("请输入您的账户(按0退出):"); while (cin >> maccount) { if (strcmp(maccount, "0") == 0) { return; } if (strlen(maccount) <= 16) { break; } el { cout << "请输入长度为1到16位的账户:"; } } cout << "请输入您的密码(按0退出):"; for (i = 0; (c = _getch()) != '\r';) { if (c == '0') { return; } if (i <= 15 && isprint(c)) { mpassword[i] = c; i++; k++; printf("*"); } if (k > 0 && c > 0 && c == '\b') { i--; k--; printf("\b"); printf(" "); printf("\b"); } } mpassword[i] = '\0'; printf("\n"); while (p) { if (strcmp(p->account, maccount) == 0) { flag = 1; while (strcmp(p->password, mpassword) != 0) { cnt--; if (cnt == 1) { fp->cls(); cout << "\n\n\n\n\n\n\n"; cout << "密码输入次数已用完! " << "\n" << "即将退出登录页面..."; sleep(3000); fp->cls(); return; } cout << "密码错误!您还有"<< cnt - 1 << "次机会\n"<< endl; cout << "请重新输入(按0退出):"; k = 0; for (i = 0; (c = _getch()) != '\r';) { if (c == '0') { return; } if (i <= 15 && isprint(c)) { mpassword[i] = c; i++; k++; printf("*"); } if (k > 0 && c > 0 && c == '\b') { i--; k--; printf("\b"); printf(" "); printf("\b"); } } mpassword[i] = '\0'; printf("\n"); } cout << "管理员"<< maccount << "登陆成功!\n" << "即将跳转至管理员页面..." << endl; sleep(2000); fp->cls(); fp->mangerfunction(); return; } p = p->get_next(); } if (!flag) { cout << "不存在此账号!\n请先前往注册!\n" << endl; cout << "即将跳转至主页面..."; sleep(2000); }}void manger::regist(){ dbfile* fp = new dbfile; manger* mp = new manger; char maccount[2000]; char mpassword[2000]; char mspassword[2000]; char mangercode[2000]; cout << "\n\n\n\n\n\n\n"; cout << "请输入管理员验证码:"; cin >> mangercode; int cnt = 2; while (--cnt >= 0) { if (strcmp(mangercode, code) == 0) { cout << "管理员验证成功!!\n" << "即将跳转至注册页面..."; sleep(1000); fp->cls(); break; } el { cout << "管理员验证失败!!\n" << "您还有" << cnt + 1 << "次机会\n"; cout << "请重新输入:"; cin >> mangercode; } if (cnt == 0) { cout << "输入次数已用完\n" << "即将退出管理员注册系统..."; sleep(1000); fp->cls(); return; } } manger* p = new manger; cout << "\n\n\n\n\n\n\n"; cout << "请输入账户(按0退出):"; while (cin >> maccount) { if (strcmp(maccount, "0") == 0) { return; } if (strlen(maccount) <= 16 && !fp->exist(maccount, 1)) { break; } el if (fp->exist(maccount, 1)) { cout << "该账户已存在!请重新输入(按0退出):"; } el { cout << "请输入长度为1到16位的账户:"; } } strcpy_s(p->account, maccount); cout << "请输入密码(按0退出):"; while (cin >> mpassword) { if (strcmp(mpassword, "0") == 0) { return; } if (strlen(mpassword) <= 16) { break; } el { cout << "请输入长度为1到16位的密码(按0退出):"; } } strcpy_s(p->password, mpassword); cout << "请输入您的密保(按0退出):"; while (cin >> mspassword) { if (strcmp(mspassword, "0") == 0) { return; } if (strlen(mspassword) <= 16) { break; } el { cout << "请输入长度为1到16位的密保(按0退出):"; } } strcpy_s(p->spassword, mspassword); mend->t_next(p); mend = p; mend->t_next(null); mp->save(); fp->cls(); printf("\n\n\n\n\n\n\n"); printf("\t\t\t\t\t*******************************\n"); printf("\t\t\t\t\t** **\n"); printf("\t\t\t\t\t 管理员%s注册成功!! \n", maccount); printf("\t\t\t\t\t** 即将跳转至主页面... **\n"); printf("\t\t\t\t\t** **\n"); printf("\t\t\t\t\t**************qualify*****************\n"); sleep(1500);}void manger::browbook(){ dbfile* fp = new dbfile; int sign = 0; while (1) { fp->cls(); browmenu(); char choo = _getch(); switch (choo) { ca '1': fp->cls(); fp->showidsort(); break; ca '2': fp->cls(); fp->showbookamountsort(); break; ca '3': fp->cls(); sign = 1; break; ca '4': fp->cls(); fp->over(); break; default: break; } if (sign) { break; } }}void manger::save(){ manger* mp = mhead->get_next(); ofstream f_manger("manger.txt", ios::out); while (mp) { f_manger << mp->account << " " << mp->password << " " << mp->spassword << endl; mp = mp->get_next(); } f_manger.clo();}void manger::creat(){ char account[20]; char password[20]; char spassword[20]; ifstream f_manger("manger.txt", ios::in); while (f_manger >> account && f_manger >> password && f_manger >> spassword) { manger* p = new manger; strcpy_s(p->account, account); strcpy_s(p->password, password); strcpy_s(p->spassword, password); mend->t_next(p); p->t_next(null); mend = mend->get_next(); } f_manger.clo();}void manger::addbook(){ dbfile* fp = new dbfile; book* p = bhead->get_next(); int a; int id = 0; int amount; char bookname[2000]; do { fp->cls(); cout << "\n\n\n\n\n"; cout << "请输入要添加书名id(按0退出):"; while (cin >> id) { if (id == 0) { return; } if (id < 0) { cout << "请输入正确格式的id号(按0退出):"; } el { break; } } int flag = 0; while (p) { if (p->get_id() == id) { flag = 1; break; } p = p->get_next(); } if (flag) { cout << "已查出此书,请输入再次增加图书的数量:"; while (cin >> amount) { if (amount <= 199 && amount > 0) { int temp = p->get_amount() + amount; p->t_amount(temp); cout << "图书" << p->get_bookname() << "添加成功!"; break; } el { cout << "请输入数量为0-199以内的图书:"; } } } el { p = new book; p->t_id(id); cout << "请输入增加图书的数量:"; while (cin >> amount) { if (amount <= 199 && amount > 0) { p->t_amount(amount); break; } el { cout << "请输入数量为0-199范围以内的图书:"; } } cout << "请输入是否可借:"; int sign = 0; while (cin >> sign) { if (sign == 1 || sign == 0) { p->t_flag(sign); break; } el if (sign < 0 || sign > 1) { cout << "请输入正确格式的可借标志(1为可借,0为不可借):"; } } char bookname[200]; cout << "请输入书名:"; cin >> bookname; p->t_bookname(bookname); char author[200]; cout << "请输作者:"; cin >> author; p->t_author(author); char press[200]; cout << "请输入出版社:"; cin >> press; p->t_press(press); bend->t_next(p); bend = p; bend->t_next(null); } p->save(); fp->cls(); printf("\n\n\n\n\n\n"); printf("\t\t\t\t\t********************************\n"); printf("\t\t\t\t\t** **\n"); printf("\t\t\t\t\t 图书%d添加成功! \n", bend->get_id()); printf("\t\t\t\t\t** **\n"); printf("\t\t\t\t\t********************************\n"); sleep(1000); fp->cls(); cout << "\n\n\n\n\n"; cout << "是否继续添加?\n" << "继续请按1,返回请按0:"; cin >> a; } while (a == 1); printf("页面即将跳转..."); sleep(10contradiction00);}void manger::changebook(){ dbfile* fp = new dbfile; book* p = bhead->get_next(); int id; int amount; int flag = 0; char bookname[200]; char author[200]; char press[200]; int exist = 0; int sign = 0; book* bp = bhead->get_next(); bp->show_book(); cout << "请输入要修改书名的id号(按0退出):"; while (cin >> id) { if (id == 0) { return; } while (p) { if (p->get_id() == id) { exist = 1; break; } p = p->get_next(); } if (!exist) { p = bhead->get_next(); cout << "为查询到该id号!请重新输入(按0退出):"; } el { break; } } if (!exist) { return; } el { int sign = 0; int choo; fp->cls(); changebookmenu(); while (1) { cout << "请输入您要进行的操作:"; cin >> choo; switch (choo) { ca 1: cout << "请输入修改后的id号:"; cin >> id; p->t_id(id); cout << "修改成功!!\n"; break; ca 2: cout << "请输入要修改后的图书名称:"; cin >> bookname; p->t_bookname(bookname); cout << "修改成功!!\n"; break; ca 3: cout << "请输入要修改后的作者:"; cin >> author; p->t_author(author); cout << "修改成功!!\n"; break; ca 4: cout << "请输入修改后的出版社:"; cin >> press; p->t_press(press); cout << "修改成功!!\n"; break; ca 5 : cout << "请输入修改后的图书数量:"; while (cin >> amount) { if (amount <= 199 && amount > 0) { p->t_amount(amount); break; } el { cout << "请输入0-199以内的图书数量:"; } } cout << "修改成功!!\n"; break; ca 6 : if (p->get_flag() == 1) { cout << "是否将此书修改为不可借?(1确认,2返回):"; while (cin >> flag) { if (flag == 2) { break; } if (flag == 1) { p->t_flag(1); p->save(); cout << "修改成功!!\n"; break; } el { cout << "请输入正确格式的借书标志!(1确认,2返回):"; } } } el if (p->get_flag() == 0) { cout << "是否将此书修改为可借?(1确认,2返回):"; while (cin >> flag) { if (flag == 2) { break; } if (flag == 1) { p->t_flag(0); p->save(); cout << "修改成功!!\n"; break; } el { cout << "请输入正确格式的借书标志!(1确认,2返回):"; } } } break; ca 7: sign = 1; break; default : cout << "输入无效!!"; cin.clear(); break; } if (sign) { break; } } }}void manger::deletebook(){ book* bp = bhead->get_next(); char bookname[20]; int flag = 0; bp->show_book(); cout << "请输入您要删除图书的名称(按0退出):"; while (cin >> bookname) { if (strcmp(bookname, "0") == 0) { return; } while (bp) { if (bp->get_bookname() == bookname) { flag = 1; break; } bp = bp->get_next(); } if (flag == 0) { cout << "未查询到此书!\n" << "请重新输入(按0退出):"; bp = bhead->get_next(); } el { break; } } deletereaderbook(bookname); bp = bhead->get_next(); book* pp = bhead; while (bp) {// bp->next 可能是链表的最后一个 if (bp->get_bookname() == bookname) { if (bp->get_next() == null) { bhead->t_next(null); } el { pp->t_next(bp->get_next()); } } pp = pp->get_next(); bp = bp->get_next(); } cout << "\n\n\n\n\n\n"; cout << "图书" << bookname << "删除成功!!\n"; cout << "页面即将跳转.."; sleep(1500); book* p = new book; p->save();}void manger::deletereaderbook(char* bookname){ reader* rp = rhead->get_next(); reader* pp = new reader; int flag = 0; while (rp) { flag = 1; for (int i = 0; i < rp->get_bookcnt(); i++) { if (strcmp(rp->get_booklist(rp, i), bookname) == 0) { flag = i; break; } } if (flag != 1) { for (int j = flag; j < rp->get_bookcnt() - 1; j++) { strcpy(rp->get_booklist(rp, j), rp->get_booklist(rp, j + 1)); } int temp = rp->get_bookcnt(); temp--; rp->t_bookcnt(temp); } rp = rp->get_next(); } pp->save();}void manger::browreader(){ cout << "账户\t\t" << "密码\t\t" << "密保\t\t" << "性别\t\t" << "姓名\t\t" << "学号\t\t" << "借书次数\n"; reader* rp = rhead->get_next(); while (rp) { cout << rp->get_account(rp) << "\t\t" << rp->get_password(rp) << "\t\t" << rp->get_spassword(rp) << "\t\t" << rp->get_x() << "\t\t" << rp->get_name() << "\t\t" << rp->get_number() << "\t\t" << rp->get_bookcnt() << endl; rp = rp->get_next(); } system("pau");}void manger::findpassword(){ manger* mp = mhead->get_next(); char password[200]; char account[200]; char spassword[200]; int flag = 0; int sign = 0; cout << "请输入您的账户(按0退出):"; while (cin >> account) { if (strcmp(account, "0") == 0) { return; } while (mp) { if (strcmp(mp->get_account(mp), account) == 0) { flag = 1; break; } mp = mp->get_next(); } if (flag) { break; } el { printf("此账号不存在!请重新输入(按0退出):"); mp = mhead->get_next(); } } if (flag) { mp = mhead->get_next(); printf("请输入您设置的密保(按0退出):"); while (cin >> spassword) { if (strcmp(spassword, "0") == 0) { return; } while (mp) { if (strcmp(mp->get_spassword(mp), spassword) == 0) { sign = 1; break; } mp = mp->get_next(); } if (sign) { printf("密保输入正确!\n"); printf("您的密码为%s\n", mp->get_password(mp)); system("pau"); return; } el { printf("-------------密保输入错误!请重新输入(按0退出):"); mp = mhead->get_next(); } } }}void manger::changepassword(){ dbfile* fp = new dbfile; manger* p = mhead->get_next(), *mp = new manger; int flag = 0; int sign = 0; char maccount[200]; char mpassword[200]; char mspassword[200]; cout << "请输入您的账户(按0退出):"; while (cin >> maccount) { if (strcmp(maccount, "0") == 0) { return; } while (p) { if (strcmp(p->account, maccount) == 0) { flag = 1; break; } p = p->get_next(); } if (flag) { break; } el { cout << "此账号不存在!请重新输入(按0退出):"; p = mhead->get_next(); } } if (flag) { p = mhead->get_next(); cout << "请输入您设置的密保(按0退出):"; while (cin >> mspassword) { if (strcmp(mspassword, "0") == 0) { return; } while (p) { if (strcmp(p->spassword, mspassword) == 0) { sign = 1; break; } p = p->get_next(); } if (sign) { cout << "请输入修改后的密码(按0退出):"; while (cin >> mpassword) { if (strcmp(mpassword, "0") == 0) { return; } if (strlen(mpassword) <= 16) { break; } el { cout << "请输入长度为1到16位的密码(按0退出):"; } } strcpy_s(p->password, mpassword); cout << "密码修改成功!"; fp->usave(p); system("pau"); return; } el { cout << "密保输入错误!!请重新输入(按0退出):"; p = mhead->get_next(); } } }}// 图书类void book::creat(){ ifstream f_book("book.txt", ios::in); int id; int amount; int flag; string bookname; string author; string press; while (f_book >> id && f_book >> flag && f_book >> amount && f_book >> bookname && f_book >> author && f_book >> press) { book* p = new book; p->id = id; p->flag = flag; p->amount = amount; p->bookname = bookname; p->author = author; p->press = press; bend->t_next(p); p->t_next(null); bend = bend->get_next(); } f_book.clo();}void book::save(){ book* bp = bhead->get_next(); ofstream f_book("book.txt", ios::out); while (bp) { f_book << bp->id << " " << bp->flag << " " << bp->amount << " " << bp->bookname << " " << bp->author << " " << bp->press << endl; bp = bp->get_next(); } f_book.clo();}void book::show_book(){ book* bp = bhead->get_next(); cout << "id号\t\t" << "是否可借\t\t" << "数量\t\t" << "书名\t\t" << "作者\t\t" << "出版社\n"; while (bp) { cout << bp->get_id() << "\t\t" << bp->get_flag() << "\t\t\t" << bp->get_amount() << "\t\t" << bp->get_bookname() << "\t\t" << bp->get_author() << "\t\t" << b少年派的奇幻漂流主题曲p->get_press() << "\n"; bp = bp->get_next(); }}int main(){ mhead = new manger; mend = new manger; mhead->t_next(null); mend = mhead; rhead = new reader; _rend = new reader; rhead->t_next(null); _rend = rhead; bhead = new book; bend = new book; bhead->t_next(null); bend = bhead; reader* rp = new reader; rp->creat(); manger* mp = new manger; mp->creat(); book* bp = new book; bp->creat(); dbfile* dbp = new dbfile; system("color b"); dbp->_main(); delete dbp; return 0;}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。
本文发布于:2023-04-06 03:24:02,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/81043cb2fe2c8dfb835078ffbd8db114.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:C++实现图书管理系统课程设计.doc
本文 PDF 下载地址:C++实现图书管理系统课程设计.pdf
留言与评论(共有 0 条评论) |