圖書管理系統(tǒng)C代碼_第1頁
圖書管理系統(tǒng)C代碼_第2頁
圖書管理系統(tǒng)C代碼_第3頁
圖書管理系統(tǒng)C代碼_第4頁
圖書管理系統(tǒng)C代碼_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、#include <iostream>#include <iomanip>#include <string>#include <fstream>using namespace std;const int Reader=100;const int Maxb=100;const int Bor=5;class Studentprivate: int tag; int number; char name10; int borbookBor;public: Student() char *getname() return name;int gettag(

2、) return tag;int getnumber() return number;void setname(char *na) strcpy(name,na);void delbook() tag=1;void addStudent(int n,char *na) tag=0; number=n; strcpy(name,na); for(int i=0;i<Bor;i+) borbooki=0;void borrowbook(int bookid)/借書操作for(int i=0;i<Bor;i+) if (borbooki=0) borbooki=bookid; retur

3、n; int retbook(int bookid)/還書操作 for(int i=0;i<Bor;i+) if(borbooki=bookid) borbooki=0; return 1;return 0;void output()/讀出讀者信息 cout << setw(5) << number <<setw(10) << name<<"借書編號:" for(int i=0;i<Bor;i+) if(borbooki!=0) cout << borbooki << "

4、;|" cout << ""<<endl; class RDataprivate: int top; /讀者記錄指針 Student readReader;public: RData() /構(gòu)造函數(shù),將Student.txt讀到read中 Student s; top=-1; fstream file("Student.txt",ios:in);/打開一個輸入文件while (1) file.read(char *)&s,sizeof(s); if (!file)break; top+; readtop=s; f

5、ile.close();void clear() top=-1;int addStudent(int n,char *na)/查找是否存在 Student *p=equal(n);if (p=NULL) top+; readtop.addStudent(n,na); return 1;return 0;Student *equal(int Studentid)/按編號查找for (int i=0;i<=top;i+) if (readi.getnumber()=Studentid && readi.gettag()=0) return &readi;return

6、NULL;void output() for (int i=0;i<=top;i+) readi.output();void Studentdata();/讀者庫維護 RData() /析構(gòu)函數(shù),將read寫到Student.txt文件中 fstream file("Student.txt",ios:out); for (int i=0;i<=top;i+) if (readi.gettag()=0) file.write(char *)&readi,sizeof(readi); file.close();void RData:Studentdata()

7、char choice;char rname20;int Studentid;Student *r; while (choice!='0') cout<<" n" cout<<" 讀 者 維 護 n" cout<<" n" cout<<" 1.新 增 n" cout<<" n" cout<<" 2.更 改 n" cout<<" n" cout<<

8、" 3.刪 除 n" cout<<" n" cout<<" 4.查 找 n" cout<<" n" cout<<" 5.顯 示 n" cout<<" n" cout<<" 6.全 刪 n" cout<<" n" cout<<" 0.退出 n" cout<<" n" /cout<<

9、 cin >> choice; switch (choice) case '1': cout << "輸入讀者編號:" cin >> Studentid; cout << "輸入讀者姓名:" cin >> rname; addStudent (Studentid,rname); break; case '2': cout << "輸入讀者編號:" cin >> Studentid; r=equal(Studentid);

10、 if (r=NULL) cout << " 該讀者不存在 "<<endl; break; cout << "輸入新的姓名:" cin >> rname; r->setname(rname); break; case '3': cout << " 輸入讀者編號:" cin >> Studentid; r=equal(Studentid); if (r=NULL) cout <<" 該讀者不存在" <<

11、; endl; break; r->delbook(); break; case '4': cout << "讀入讀者編號:" cin >> Studentid; r=equal(Studentid); if (r=NULL) cout <<"該讀者不存在"<< endl; break; r->output(); break; case '5': output(); break; case '6': clear(); break; default:

12、cout<<"退出:n"system("cls");break; class Bookprivate: int tag; int number; char name20; int onshelf;public: Book() char *getname() return name; int getnumber() return number; int gettag() return tag; void setname(char na) strcpy(name,na); void delbook() tag=1; void addbook(in

13、t n,char *na) tag=0; number=n; strcpy(name,na); onshelf=1; int borrowbook()/借書操作 if (onshelf=1) onshelf=0; return 1; return 0;void retbook()/還書操作 onshelf=1;void output()/輸出圖書 cout << setw(6) << number << setw(18) << name << setw(10) <<(onshelf=1? "在架":&q

14、uot;已借") <<endl; class BDatabaseprivate: int top; Book bookMaxb; /圖書記錄 public: BDatabase()/構(gòu)造函數(shù),將book.txt讀到book中 Book b; top=-1; fstream file("book.txt",ios:in);while (1) file.read(char *)&b,sizeof(b); if (!file) break; top+; booktop=b; file.close(); void clear() top=-1;int

15、addbook(int n,char *na) Book *p=equal(n);if (NULL=p) top+; booktop.addbook(n,na); return 1;return 0;Book *equal(int bookid) for (int i=0;i<=top;i+) if (booki.getnumber()=bookid &&booki.gettag()=0) return &booki; return NULL;void bookdata();void output() for (int i=0;i<=top;i+) if (

16、booki.gettag()=0) booki.output();BDatabase()/析構(gòu)函數(shù),將book寫到book.txt文件中 fstream file("book.txt",ios:out); for (int i=0;i<=top;i+) if (booki.gettag()=0) file.write(char *)&booki,sizeof(booki); file.close();void BDatabase:bookdata()char choice; char bname40; int bookid;Book *b;while (cho

17、ice!='0') cout<<" n" cout<<" 圖書 維 護 n" cout<<" n" cout<<" 1.新 增 n" cout<<" n" cout<<" 2.更 改 n" cout<<" n" cout<<" 3.刪 除 n" cout<<" n" cout<<&q

18、uot; 4.查 找 n" cout<<" n" cout<<" 5.顯 示 n" cout<<" n" cout<<" 6.全 刪 n" cout<<" n" cout<<" 0.退出 n" cout<<" n"cin >> choice;switch (choice) case '1': cout << "輸入

19、圖書編號:"<<endl; cin >> bookid; cout << "輸入圖書書名:"<<endl; cin >> bname; addbook(bookid,bname); break;case '2': cout << "輸入圖書編號:"<<endl; cin >> bookid; b=equal(bookid); if (b=NULL) cout << " 該圖書不存在 "<<e

20、ndl; break; cout << "輸入新的書名:"<<endl; cin >> bname; b->setname(bname); break;case '3': cout <<" 讀入圖書編號:"<<endl; cin >> bookid; b=equal(bookid); if (b=NULL) cout <<" 該圖書不存在" << endl; break; b->delbook(); break;

21、case '4': cout << " 讀入圖書編號:"<<endl; cin >> bookid; b=equal(bookid); if (b=NULL) cout <<" 該圖書不存在"<< endl; break; b->output(); break;case '5': output(); break;case '6': clear(); break; default:cout<<"退出n" syst

22、em("cls"); break;void main() char choice; int bookid,Studentid; RData StudentDB; Student *r; BDatabase BookDB; Book *b; while(choice!='0') cout<<" n" cout<<" 圖 書 管 理 系 統(tǒng) n" cout<<" n" cout<<" 1.借書 n" cout<<"

23、 n" cout<<" 2.還書 n" cout<<" n" cout<<" 3.圖書維護 n" cout<<" n" cout<<" 4.讀者維護 n" cout<<" n" cout<<" 0.退出 n" cout<<" n" cin >> choice; switch (choice) case '1': system("cls"); cout <<" 借書 讀者編號:" cin >>Studentid; cout <<" 圖書編號: " cin >>bookid; r=StudentDB.equal(Studentid);/按編號查找 if (NULL=r) cout <<" 不存在該讀者,不能借書"<< endl; break; b=BookDB.equal(bookid); if (b=N

溫馨提示

  • 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

提交評論