南航 图书馆管理系统课设(2)

2019-03-22 11:55

#endif

Lib_sys.h

#ifndef LIB_SYS_H #define LIB_SYS_H

#include\#include\

class lib_sys{ private:

int book_tot; int student_tot;

book lbook[100];

student lstudent[100];

char username[50]; char password[50];

int user_state; //0 is no user , 1 is login

public:

lib_sys(){

username[0]='\\0'; password[0]='\\0'; user_state=0; book_tot=0; student_tot=0; }

int input_data(); int output_data();

int user_login();

int check_user_right(); int check_admin_right();

book edit_book_inner(book k); book add_book_inner();

int show_book_inner(book k); int find_book_inner(char *isbn);

6

int find_student_inner(char *username);

int add_book();

int edit_book(char *isbn);

int del_book(char *isbn,int much); int show_book();

int borrow_book(); int return_book();

int register_user(); char * get_username(){ return username; }

int show_user_detail(); };

#endif

Lib_sys.cpp

#include\

#include #include #include #include

#include

int lib_sys::input_data(){ int i,j;

fstream fbook,fstudent;

fbook.open(\

fstudent.open(\ if (!fbook) return 0; if (!fstudent) return 0;

fbook >> book_tot; fbook.ignore();

for (i=1;i<=book_tot;i++){

fbook.getline(lbook[i].isbn,50);

fbook.getline(lbook[i].bookTitle,50);

7

fbook.getline(lbook[i].author,50); fbook.getline(lbook[i].publisher,50); fbook.getline(lbook[i].datepublished,50); fbook >> lbook[i].left; fbook.ignore(); }

fbook.close();

fstudent >> student_tot; fstudent.ignore();

for (i=1;i<=student_tot;i++){

fstudent.getline(lstudent[i].username,50); fstudent.getline(lstudent[i].password,50); fstudent >> lstudent[i].num; fstudent.ignore();

for (j=1;j<=lstudent[i].num;j++)

fstudent.getline(lstudent[i].isbn[j],50); }

fstudent.close();

return 1; }

int lib_sys::output_data(){ int i,j;

fstream fbook,fstudent;

fbook.open(\

fstudent.open(\ if (!fbook) return 0; if (!fstudent) return 0;

fbook << book_tot << endl; for (i=1;i<=book_tot;i++){

fbook << lbook[i].isbn << endl;

fbook << lbook[i].bookTitle << endl; fbook << lbook[i].author << endl; fbook << lbook[i].publisher << endl; fbook << lbook[i].datepublished << endl; fbook << lbook[i].left << endl; }

fbook.close();

fstudent << student_tot << endl; for (i=1;i<=student_tot;i++){

8

fstudent << lstudent[i].username << endl; fstudent << lstudent[i].password << endl; fstudent << lstudent[i].num << endl; for (j=1;j<=lstudent[i].num;j++)

fstudent << lstudent[i].isbn[j] << endl; }

fstudent.close();

return 1; }

int lib_sys::user_login(){ char ua[50],pw[50]; int i;

cout << \ cin.getline(ua,50); cout << \ cin.getline(pw,50);

for (i=1;i<=student_tot;i++){

//cout << lstudent[i].username << endl << lstudent[i].password << endl; if (strcmp(lstudent[i].username,ua)==0 && strcmp(lstudent[i].password,pw)==0){ user_state=1;

strcpy(username,ua); strcpy(password,pw);

//cout << username << endl; //cout << password << endl; break; } }

if (user_state) cout << \ else cout << \ return user_state; }

int lib_sys::check_user_right(){ return user_state; }

int lib_sys::check_admin_right(){ if (!user_state) return 0;

if (strcmp(username,\ return 0;

9

}

book lib_sys::edit_book_inner(book k){ char ch; char st[50];

if (!check_admin_right()) return k; ch='0';

while (!(ch=='6')){ system(\

cout << \请输入要修改的项目,在新数据输入状态下直接回车表示取消修改\\n\ cout << \ cout << \书名\\n\ cout << \作者\\n\ cout << \出版社\\n\ cout << \出版时间\\n\ cout << \确定\\n\ cout.flush(); ch=getch(); switch (ch){ case '1':

cout << \当前的isbn是: \ cout << \请输入新数据: \ cin.getline(st,50);

if (!strlen(st)==0) strcpy(k.isbn,st); break; case '2':

cout << \当前的书名是: \ cout << \请输入新数据: \ cin.getline(st,50);

if (!strlen(st)==0) strcpy(k.bookTitle,st); break; case '3':

cout << \当前的作者是: \ cout << \请输入新数据: \ cin.getline(st,50);

if (!strlen(st)==0) strcpy(k.author,st); break; case '4':

cout << \当前的出版社是: \ cout << \请输入新数据: \ cin.getline(st,50);

if (!strlen(st)==0) strcpy(k.publisher,st); break; case '5':

10


南航 图书馆管理系统课设(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2017年医院工作总结

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: