文件名称:
图书管理系统c语言!!!!!!!!!!!!!!!!!
开发工具:
文件大小: 99kb
下载次数: 1
上传时间: 2009-06-30
详细说明:
C语言源代码的图书管理系统 #include #include #include #include struct bookData { int booknumber; char bookname[30]; int store; }; struct Person { char name[20]; char studynumber[10]; int count; b ookData Rbook[2]; //bookData Rbook; }; class History { public: History(fstream& a){readerbook=a;} void writehistory(); void readhistory(fstream&); private: fstream readerbook; }; class Liberian; void Find(fstream&); void CreateTxt(fstream&); class Reader { friend Liberian; public: Reader(fstream&); void print(); void handlebook(fstream&); void change(); bool findreader(); void Addreader(); void deletereader(); private: fstream file; Person person; }; class Liberian { public: Liberian(char *,char *); void changeReader(Reader&); void selfprint(); void Append(fstream&); private: char workname[20]; char worknumber[20]; }; int main() { fstream bookRecord(" book.dat",ios::in| ios::out); if(!bookRecord) { cerr<<" Can't open,try again!"<>choice; switch(choice) { case 1: { cout<<" Hello,图书管理员:\n"; liberian.selfprint();cout<>key; switch(key) { case 1: liberian.Append(bookRecord); break; case 2: liberian.changeReader(reader); break; case 3: rec.readhistory(readerRecord); case 0: break ; } } break; case 2: { cout<<"学生读者\n"; int iflag=1; //reader.findreader(); cout<<"1-- 借书与还书信息\n" <<"2-- 修改个人信息\n" <<"0-- 返回\n"; cin>>key; switch(key) { case 1: reader.handlebook(bookRecord); break; case 2: reader.change(); break; case 0: break; } } break; default: return 0; } } return 0; } //增加书籍 void Liberian::Append(fstream& storef) { bookData book; int choice; int key; int num; storef.seekp(0,ios::end); int posEnd=storef.tellp(); cout<<"*************书籍入库***************"<>choice; switch(choice) { case 1: cout<<" 书号, 书名, 数量?"<>book.booknumber>>book.bookname>>book.store; storef.write(reinterpret_cast(&book),sizeof(bookData)); break; case 2: storef.seekg(0,ios::beg); cout<<"Booknumber?\n"; cin>>key; do{ storef.read(reinterpret_cast(&book),sizeof(bookData)); }while(book.booknumber!=key&&storef.tellg()!=posEnd); if(book.booknumber==key) { cout<>num; if(num>0) book.store+=num; else { cout<<" Invalid input"<(&book),sizeof(bookData)); cout<<"现在书籍: "<>choice; switch(choice) { case 1: f.seekg(0,ios::beg); cout<<"输入你想检索书的书号"<>key; do{ f.read(reinterpret_cast(&book),sizeof(bookData)); }while(book.booknumber!=key&&f.tellg()!=posEnd); if(book.booknumber==key) cout<(&book),sizeof(bookData)); cout<=3) return; } //cout<>choice; switch(choice) { case 1: { filee.seekp(0,ios::end); int posEnd=filee.tellp(); if(person.count<=1) { cout<<" 输入你要借阅图书的书号:"<>key; filee.seekg(0); do{ filee.read(reinterpret_cast(&book),sizeof(bookData)); }while(book.booknumber!=key&&filee.tellp()!=posEnd); //cout<0) { person.Rbook[person.count]=book; person.count+=1; book.store-=1; filee.seekp(-long(sizeof(bookData)),ios::cur); filee.write(reinterpret_cast(&book),sizeof(bookData)); cout<<" 找到你想借阅的图书,成功借阅!"<0) //{ int iflag=0; filee.seekg(0); cout<<" 输入你想要还的书的书号:"<>key; for(int i=0;i<2;i++) { if(key==person.Rbook[i].booknumber) { person.Rbook[i]=blankbook; cout<<"成功归还此书!"; iflag=1; person.count--; do{ filee.read(reinterpret_cast(&book),sizeof(bookData)); }while(book.booknumber!=key&&filee.tellp()!=posEnd); if(book.booknumber==key) { book.store+=1; filee.seekp(-long(sizeof(bookData)),ios::cur); filee.write(reinterpret_cast(&book),sizeof(bookData)); cout<<"书籍 :"<=3) return; } cout<<" 请输入你的选择!"<>choice; switch(choice) { case 1: cout<<"输入你的新名字!\n"; cin>>newname; strcpy(person.name,newname); break; case 2: cout<<"输入你的信学号?\n"; cin>>newnumber; strcpy(person.studynumber,newnumber); break; default: break;; } file.seekp(-long(sizeof(Person)),ios::cur); file.write(reinterpret_cast(&person),sizeof(Person)); cout<<"信息修改成功!"<>choice; switch(choice) { case 1: a.Addreader(); break; case 2: a.deletereader(); break; case 0: return; } } void Reader::Addreader() { Person temp;bookData book={0,"0",0}; file.seekp(0,ios::end); int Posend=file.tellp(); cout<<"输入你想要增加的读者的名字"<>temp.name; cout<<"新读者的学号:"<>temp.studynumber; temp.Rbook[1]=book; temp.Rbook[0]=book; temp.count=0; file.write(reinterpret_cast(&temp),sizeof(Person)); cout<<" 成功添加!"<>name; file.seekg(0); do{ file.read(reinterpret_cast(&person),sizeof(Person)); }while(strcmp(name,person.name)&&file.tellp()!=Posend); if(!strcmp(name,person.name)) { bookData blankbook={0,"0",0}; Person guest={"0","0",0,{{0,"0",0},{0,"0",0}}}; file.seekp(-long(sizeof(Person)),ios::cur); file.write(reinterpret_cast(&guest),sizeof(Person)); cout<<"成功删除!"<>name; file.seekg(0); do{ file.read(reinterpret_cast(&person),sizeof(Person)); }while(strcmp(name,person.name)&&file.tellp()!=Posend); if(!strcmp(name,person.name)) { cout<<"查到此人:"<(&guest),sizeof(Person)); if(strcmp(guest.Rbook[1].bookname,name) || strcmp(guest.Rbook[1].bookname,name)) { cout<
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.