C++實現(xiàn)圖書管理系統(tǒng)課程設(shè)計_第1頁
C++實現(xiàn)圖書管理系統(tǒng)課程設(shè)計_第2頁
C++實現(xiàn)圖書管理系統(tǒng)課程設(shè)計_第3頁
C++實現(xiàn)圖書管理系統(tǒng)課程設(shè)計_第4頁
C++實現(xiàn)圖書管理系統(tǒng)課程設(shè)計_第5頁
已閱讀5頁,還剩51頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

第C++實現(xiàn)圖書管理系統(tǒng)課程設(shè)計printf("\t第%d次借閱的書籍:",i+1);

printf("%s\t",pp-get_booklist(pp,i));

cout"借閱數(shù)量:"pp-get_books()endl;

}

printf("\n\n請輸入0退出:");

while(scanf("%lld",sign))

{

if(sign==0)

{

break;

}

else

{

printf("-------------無效的輸入!請重新輸入!");

}

}

voidReader::BorrowBook(Reader*pp)

Book*bp=bhead-get_next();

Book*_bp=newBook;

_bp-show_book();

charbookname[200];

intamount;

intflag=1;

intsign=1;

intexist=0;

cout"\n\n\n\n";

cout"請輸入要借書的名稱(按0退出):";

cinbookname;

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==1flag==1)

{

cout"請輸入要借閱書籍的數(shù)量:";

while(cinamount)

{

if(bp-get_amount()amount)

{

cout"借閱數(shù)量超過此書已有庫存!請重新輸入:";

}

else

{

inta=pp-get_books()+amount;

pp-set_books(a);

intb=bp-get_amount()-amount;

bp-set_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==0sign==1flag==1)

{

cout"不存在此書!!\n";

}

elseif(exist==1)

{

cout"圖書:"bookname"借閱成功!!\n";

}

cout"頁面即將跳轉(zhuǎn)...";

Sleep(1200);

voidReader::ReturnBook(Reader*pp)

Book*bp=bhead-get_next();

charbookname[200];

intamount;

intexist=0;

intflag=0;

intcnt=pp-bookcnt;

if(cnt==0)

{

printf("\n\n\n\n\n\n\n");

printf("\t\t\t\t\t\t您還未借閱任何書籍!\n");

system("pause");

return;

}

printf("\n\n\n\n\n\n");

for(inti=0;icnt;i++)

{

cout"-------------第"i+1"次借閱的書籍:"pp-booklist[i]"\t\t";

cout"借閱數(shù)量:"pp-booksendl;

}

cout"請輸入您要退還的書籍(按0退出):";

while(cinbookname)

{

if(strcmp(bookname,"0")==0)

{

return;

}

for(inti=0;ipp-bookcnt;i++)

{

if(strcmp(pp-booklist[i],bookname)==0)

{

flag=i;

exist=1;

break;

}

}

if(!exist)

{

cout"未查詢到該書!\n";

cout"請重新輸入(按0退出):";

}

else

{

break;

}

}

while(bp)

{

if(bp-get_bookname()==bookname)

{

cout"請輸入您要退還書籍的數(shù)量:";

while(cinamount)

{

if(pp-booksamount)

{

cout"您未持有此數(shù)量的書籍!\n";

cout"請重新輸入:";

}

else

{

inta=pp-books-amount;

intb=bp-get_amount()+amount;

pp-set_books(a);

bp-set_amount(b);

break;

}

}

}

bp=bp-get_next();

}

if(pp-books==0)

{

for(inti=flag;ipp-books-1;i++)

{

strcpy_s(pp-booklist[i],pp-booklist[i+1]);

}

pp-bookcnt--;

}

pp-save();

bp-save();

coutbookname"退還成功??!\n";

cout"即將返回上一頁面...";

Sleep(1100);

voidReader::FindPassword()

Reader*rp=rhead-get_next();

charpassword[200];

characcount[200];

charspassword[200];

intflag=0;

intsign=0;

cout"請輸入您的賬戶(按0退出):";

while(cinaccount)

{

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;

}

else

{

printf("此賬號不存在!請重新輸入(按0退出):");

rp=rhead-get_next();

}

}

if(flag)

{

rp=rhead-next;

printf("請輸入您設(shè)置的密保(按0退出):");

while(cinspassword)

{

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("pause");

return;

}

else

{

printf("-------------密保輸入錯誤!請重新輸入(按0退出):");

rp=rhead-get_next();

}

}

}

voidReader::ChangePassword()

DBFile*fp=newDBFile;

Reader*p=rhead-get_next(),*rp=newReader;

intflag=0;

intsign=0;

charraccount[200];

charrpassword[200];

charrspassword[200];

cout"請輸入您的賬戶(按0退出):";

while(cinraccount)

{

if(strcmp(raccount,"0")==0)

{

return;

}

while(p)

{

if(strcmp(p-account,raccount)==0)

{

flag=1;

break;

}

p=p-get_next();

}

if(flag)

{

break;

}

else

{

cout"此賬號不存在!請重新輸入(按0退出):";

p=rhead-get_next();

}

}

if(flag)

{

p=rhead-get_next();

cout"請輸入您設(shè)置的密保(按0退出):";

while(cinrspassword)

{

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(cinrpassword)

{

if(strcmp(rpassword,"0")==0)

{

return;

}

if(strlen(rpassword)=16)

{

break;

}

else

{

cout"請輸入長度為1到16位的密碼(按0退出):";

}

}

strcpy_s(p-password,rpassword);

cout"密碼修改成功!";

fp-usesave(p);

system("pause");

return;

}

else

{

cout"密保輸入錯誤!!請重新輸入(按0退出):";

p=rhead-get_next();

}

}

}

//數(shù)據(jù)操作類

voidDBFile::cls()

system("cls");

voidDBFile::over()

DBFile*dbp=newDBFile;

dbp-cls();

system("color6");

inttime=6;

printf("\n\n\n\n\n\n\n\n\n");

printf("\t\t\t\t\t\t感謝您的使用??!\n\n\n\n\n");

printf("程序即將關(guān)閉...");

while(--time=1)

{

printf("\r%d",time);

printf("\b");

Sleep(1000);

}

dbp-cls();

exit(0);

voidDBFile::login()

Reader*rp=newReader;

Manger*mp=newManger;

intsign=0;

while(1)

{

cls();

Loginmenu();

charchoose=_getch();

switch(choose)

{

case'1':

cls();

useLogin(mp);

break;

case'2':

cls();

useLogin(rp);

break;

case'3':

cls();

sign=1;

break;

case'4':

cls();

over();

break;

default:

cout"輸入無效?。?;

break;

}

if(sign)

{

break;

}

}

voidDBFile::useLogin(User*base)

base-Login();

voidDBFile::regist()

Reader*rp=newReader;

Manger*mp=newManger;

intsign=0;

while(1)

{

cls();

Registmenu();

charchoose=_getch();

switch(choose)

{

case'1':

cls();

useRegist(mp);

break;

case'2':

cls();

useRegist(rp);

break;

case'3':

cls();

sign=1;

break;

case'4':

cls();

over();

break;

default:

cout"無效輸入??!";

break;

}

if(sign)

{

break;

}

}

voidDBFile::usesave(User*base)

base-save();

voidDBFile::usechangepassword(User*base)

base-ChangePassword();

voidDBFile::useRegist(User*base)

base-Regist();

voidDBFile::usebrowsebook(User*base)

base-BrowseBook();

voidDBFile::usefindpassword(User*base)

base-FindPassword();

voidDBFile::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("請按鍵選擇:");

intchoose;

intsign=0;

Reader*rp=newReader;

Manger*mp=newManger;

scanf("%d",choose);

while(1)

{

cls();

switch(choose)

{

case1:

cls();

usefindpassword(mp);

sign=1;

break;

case2:

cls();

usefindpassword(mp);

sign=1;

break;

case3:

sign=1;

break;

default:

printf("輸入無效!");

break;

}

if(sign)

{

break;

}

}

intDBFile::exist(char*account,intflag)

if(flag==0)

{

Reader*p=rhead-get_next();

while(p!=NULL)

{

if(strcmp(account,p-get_account(p))==0)

{

return1;

}

p=p-get_next();

}

}

elseif(flag==1)

{

Manger*p=mhead-get_next();

while(p!=NULL)

{

if(strcmp(account,p-get_account(p))==0)

{

return1;

}

p=p-get_next();

}

}

return0;

voidDBFile::_main()

while(1)

{

cls();

_mainmenu();

charchoose=_getch();

switch(choose)

{

case'1':

cls();

login();

break;

case'2':

cls();

regist();

break;

case'3':

cls();

findpassword();

break;

case'4':

cls();

over();

break;

default:

cout"無效輸入??!";

break;

}

}

voidDBFile::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-set_next(y);

x-set_next(y-get_next());

y-set_next(x);

}

}

f=p-get_next();

}

voidDBFile::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-set_next(y);

x-set_next(y-get_next());

y-set_next(x);

}

}

f=p-get_next();

}

voidDBFile::showidsort()

DBFile*fp=newDBFile;

Book*bp=newBook;

fp-idsort();

bp-show_book();

system("pause");

voidDBFile::showbookamountsort()

DBFile*fp=newDBFile;

Book*bp=newBook;

fp-bookamountsort();

bp-show_book();

system("pause");

voidDBFile::mangerfunction()

DBFile*fp=newDBFile;

Manger*mp=newManger;

intsign=0;

intchoose;

while(1)

{

fp-cls();

mangermenu();

cinchoose;

switch(choose)

{

case1:

fp-cls();

mp-AddBook();

break;

case2:

fp-cls();

mp-DeleteBook();

break;

case3:

fp-cls();

mp-ChangeBook();

break;

case4:

fp-cls();

mp-BrowseReader();

break;

case5:

fp-cls();

mp-BrowseBook();

break;

case6:

fp-cls();

fp-usechangepassword(mp);

break;

case7:

fp-cls();

sign=1;

break;

case8:

fp-cls();

fp-over();

break;

default:

cout"輸入無效??!";

break;

}

if(sign)

{

break;

}

}

voidDBFile::readerfunction(Reader*pp)

DBFile*fp=newDBFile;

Reader*rp=newReader;

intsign=0;

while(1)

{

fp-cls();

readermenu();

charchoose=_getch();

switch(choose)

{

case'1':

fp-cls();

rp-BorrowBook(pp);

break;

case'2':

fp-cls();

rp-ReturnBook(pp);

break;

case'3':

fp-cls();

fp-usebrowsebook(rp);

break;

case'4':

fp-cls();

rp-BrowseBorrowBook(pp);

break;

case'5':

fp-cls();

fp-usechangepassword(rp);

break;

case'6':

fp-cls();

sign=1;

break;

case'7':

fp-over();

break;

default:

cout"輸入無效!!";

break;

}

if(sign)

{

break;

}

}

//管理員類

voidManger::Login()

intcnt=4;

intflag=0;

intk=0;

inti;

charc;

DBFile*fp=newDBFile;

Manger*p=mhead-get_next();

charmpassword[2000];

charmaccount[2000];

cout"\n\n\n\n\n\n\n";

printf("請輸入您的賬戶(按0退出):");

while(cinmaccount)

{

if(strcmp(maccount,"0")==0)

{

return;

}

if(strlen(maccount)=16)

{

break;

}

else

{

cout"請輸入長度為1到16位的賬戶:";

}

}

cout"請輸入您的密碼(按0退出):";

for(i=0;(c=_getch())!='\r';)

{

if(c=='0')

{

return;

}

if(i=15isprint(c))

{

mpassword[i]=c;

i++;

k++;

printf("*");

}

if(k0c0c=='\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"密碼輸入次數(shù)已用完!""\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=15isprint(c))

{

mpassword[i]=c;

i++;

k++;

printf("*");

}

if(k0c0c=='\b')

{

i--;

k--;

printf("\b");

printf("");

printf("\b");

}

}

mpassword[i]='\0';

printf("\n");

}

cout"管理員"maccount"登陸成功!\n""即將跳轉(zhuǎn)至管理員頁面..."endl;

Sleep(2000);

fp-cls();

fp-mangerfunction();

return;

}

p=p-get_next();

}

if(!flag)

{

cout"不存在此賬號!\n請先前往注冊!\n"endl;

cout"即將跳轉(zhuǎn)至主頁面...";

Sleep(2000);

}

voidManger::Regist()

DBFile*fp=newDBFile;

Manger*mp=newManger;

charmaccount[2000];

charmpassword[2000];

charmspassword[2000];

charmangercode[2000];

cout"\n\n\n\n\n\n\n";

cout"請輸入管理員驗證碼:";

cinmangercode;

intcnt=2;

while(--cnt=0)

{

if(strcmp(mangercode,code)==0)

{

cout"管理員驗證成功??!\n""即將跳轉(zhuǎn)至注冊頁面...";

Sleep(1000);

fp-cls();

break;

}

else

{

cout"管理員驗證失?。?!\n""您還有"cnt+1"次機會\n";

cout"請重新輸入:";

cinmangercode;

}

if(cnt==0)

{

cout"輸入次數(shù)已用完\n""即將退出管理員注冊系統(tǒng)...";

Sleep(1000);

fp-cls();

return;

}

}

Manger*p=newManger;

cout"\n\n\n\n\n\n\n";

cout"請輸入賬戶(按0退出):";

while(cinmaccount)

{

if(strcmp(maccount,"0")==0)

{

return;

}

if(strlen(maccount)=16!fp-exist(maccount,1))

{

break;

}

elseif(fp-exist(maccount,1))

{

cout"該賬戶已存在!請重新輸入(按0退出):";

}

else

{

cout"請輸入長度為1到16位的賬戶:";

}

}

strcpy_s(p-account,maccount);

cout"請輸入密碼(按0退出):";

while(cinmpassword)

{

if(strcmp(mpassword,"0")==0)

{

return;

}

if(strlen(mpassword)=16)

{

break;

}

else

{

cout"請輸入長度為1到16位的密碼(按0退出):";

}

}

strcpy_s(p-password,mpassword);

cout"請輸入您的密保(按0退出):";

while(cinmspassword)

{

if(strcmp(mspassword,"0")==0)

{

return;

}

if(strlen(mspassword)=16)

{

break;

}

else

{

cout"請輸入長度為1到16位的密保(按0退出):";

}

}

strcpy_s(p-spassword,mspassword);

mend-set_next(p);

mend=p;

mend-set_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注冊成功?。?/p>

\n",maccount);

printf("\t\t\t\t\t**

即將跳轉(zhuǎn)至主頁面...

**\n");

printf("\t\t\t\t\t**

**\n");

printf("\t\t\t\t\t*******************************\n");

Sleep(1500);

voidManger::BrowseBook()

DBFile*fp=newDBFile;

intsign=0;

while(1)

{

fp-cls();

browsemenu();

charchoose=_getch();

switch(choose)

{

case'1':

fp-cls();

fp-showidsort();

break;

case'2':

fp-cls();

fp-showbookamountsort();

break;

case'3':

fp-cls();

sign=1;

break;

case'4':

fp-cls();

fp-over();

break;

default:

break;

}

if(sign)

{

break;

}

}

voidManger::save()

Manger*mp=mhead-get_next();

ofstreamf_manger("manger.txt",ios::out);

while(mp)

{

f_mangermp-account""mp-password""mp-spasswordendl;

mp=mp-get_next();

}

f_manger.close();

voidManger::creat()

characcount[20];

charpassword[20];

charspassword[20];

ifstreamf_manger("manger.txt",ios::in);

while(f_mangeraccountf_mangerpasswordf_mangerspassword)

{

Manger*p=newManger;

strcpy_s(p-account,account);

strcpy_s(p-password,password);

strcpy_s(p-spassword,password);

mend-set_next(p);

p-set_next(NULL);

mend=mend-get_next();

}

f_manger.close();

voidManger::AddBook()

DBFile*fp=newDBFile;

Book*p=bhead-get_next();

inta;

intid=0;

intamount;

charbookname[2000];

do

{

fp-cls();

cout"\n\n\n\n\n";

cout"請輸入要添加書名id(按0退出):";

while(cinid)

{

if(id==0)

{

return;

}

if(id0)

{

cout"請輸入正確格式的id號(按0退出):";

}

else

{

break;

}

}

intflag=0;

while(p)

{

if(p-get_id()==id)

{

flag=1;

break;

}

p=p-get_next();

}

if(flag)

{

cout"已查出此書,請輸入再次增加圖書的數(shù)量:";

while(cinamount)

{

if(amount=199amount0)

{

inttemp=p-get_amount()+amount;

p-set_amount(temp);

cout"圖書"p-get_bookname()"添加成功!";

break;

}

else

{

cout"請輸入數(shù)量為0-199以內(nèi)的圖書:";

}

}

}

else

{

p=newBook;

p-set_id(id);

cout"請輸入增加圖書的數(shù)量:";

while(cinamount)

{

if(amount=199amount0)

{

p-set_amount(amount);

break;

}

else

{

cout"請輸入數(shù)量為0-199范圍以內(nèi)的圖書:";

}

}

cout"請輸入是否可借:";

intsign=0;

while(cinsign)

{

if(sign==1||sign==0)

{

p-set_flag(sign);

break;

}

elseif(sign0||sign1)

{

cout"請輸入正確格式的可借標志(1為可借,0為不可借):";

}

}

charbookname[200];

cout"請輸入書名:";

cinbookname;

p-set_bookname(bookname);

charauthor[200];

cout"請輸作者:";

cinauthor;

p-set_author(author);

charpress[200];

cout"請輸入出版社:";

cinpress;

p-set_press(press);

bend-set_next(p);

bend=p;

bend-set_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"是否繼續(xù)添加?\n""繼續(xù)請按1,返回請按0:";

cina;

}while(a==1);

printf("頁面即將跳轉(zhuǎn)...");

Sleep(1000);

voidManger::ChangeBook()

DBFile*fp=newDBFile;

Book*p=bhead-get_next();

intid;

intamount;

intflag=0;

charbookname[200];

charauthor[200];

charpress[200];

intexist=0;

intsign=0;

Book*bp=bhead-get_next();

bp-show_book();

cout"請輸入要修改書名的id號(按0退出):";

while(cinid)

{

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退出):";

}

else

{

break;

}

}

if(!exist)

{

return;

}

else

{

intsign=0;

intchoose;

fp-cls();

changebookmenu();

while(1)

{

cout"請輸入您要進行的操作:";

cinchoose;

switch(choose)

{

case1:

cout"請輸入修改后的id號:";

cinid;

p-set_id(id);

cout"修改成功?。n";

break;

case2:

cout"請輸入要修改后的圖書名稱:";

cinbookname;

p-set_bookname(bookname);

cout"修改成功??!\n";

break;

case3:

cout"請輸入要修改后的作者:";

cinauthor;

p-set_author(author);

cout"修改成功!!\n";

break;

case4:

cout"請輸入修改后的出版社:";

cinpress;

p-set

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論