| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 934 人关注过本帖
标题:图书馆程序(希望大家多多执教)
只看楼主 加入收藏
youzehong
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-6-23
收藏
 问题点数:0 回复次数:5 
图书馆程序(希望大家多多执教)

#include<iostream.h> #include<fstream.h> #include<string.h> class BC //图书卡类 { public: void print() { cout<<"BookCardN"<<no<<endl <<"Name:"<<name<<endl <<"sex:"<<(sex=='1'?"man":"women")<<endl; } char *GetNo() { return no; } void Register() { cout<<"BookCardN"; cin>>no; cout<<"user name:"; cin>>name; cout<<"sex(input 0 or 1,1:man,0:women):"; cin>>sex; } friend ostream &operator <<(ostream &stream,BC &card) { stream.write(card.no,sizeof(card.no)); stream.write(card.name,sizeof(card.name)); stream.put(card.sex); return stream; } friend istream &operator >>(istream &stream,BC &card) { stream.read(card.no,sizeof(card.no)); stream.read(card.name,sizeof(card.name)); stream.get(card.sex); return stream; } private: char no[12]; char name[15]; char sex; }; class Book//借书证类 { public: void print() { cout<<"Book Number:"<<no<<endl <<"Book Name:"<<name<<endl <<"Borrowed:"<<(borrowed=='1'?"yes":"no")<<endl; } char *GetName() { return name; } char *GetNo() { return no; } void Register() { cout<<"BookN"; cin>>no; cout<<"BookName:"; cin>>name; borrowed='0'; } char GetBorrowed() { return borrowed; } void SetBorrowed(char b) { borrowed=b; } friend ostream &operator <<(ostream &stream,Book &book) { stream.write(book.no,sizeof(book.no)); stream.write(book.name,sizeof(book.name)); stream.put(book.borrowed); return stream; } friend istream &operator >>(istream &stream,Book &book) { stream.read(book.no,sizeof(book.no)); stream.read(book.name,sizeof(book.name)); stream.get(book.borrowed); return stream; } private: char no[12]; char name[15]; char borrowed; }; class Borrowhofel:public Book,public BC//借书记录类 { public: char *GetCardNo() { return BookCardNo; } char *GetBookNo() { return BookNo; } Borrowhofel(){} Borrowhofel(char bc[12],char b[15]) { strcpy(BookCardNo,bc); strcpy(BookNo,b); } friend ofstream &operator <<(ofstream &stream,Borrowhofel &hofel) { stream.write(hofel.BookCardNo,sizeof(hofel.BookCardNo)); stream.write(hofel.BookNo,sizeof(hofel.BookNo)); return stream; } friend ifstream &operator >>(ifstream &stream,Borrowhofel &hofel) { stream.read(hofel.BookCardNo,sizeof(hofel.BookCardNo)); stream.read(hofel.BookNo,sizeof(hofel.BookNo)); return stream; } private: char BookCardNo[12]; char BookNo[15]; }; void enter_BC() { BC card; ofstream outfile; outfile.open("BC.txt",ios::app); char we='y'; while(we=='y') { card.Register(); outfile<<card; cout<<"Are you continue?(y\\n)"; cin>>we; } outfile.close(); } void enter_book() { Book book; ofstream outfile; outfile.open("book.txt",ios::app); char we='y'; while(we=='y') { book.Register(); outfile<<book; cout<<"Are you continue?(y\\n)"; cin>>we; } outfile.close(); } void borrow_book() { Borrowhofel hofel; BC card; Book book; char cardno[12]; cout<<"Input your BookCardN"; cin>>cardno; ifstream infile; infile.open("BC.txt",ios::in); int flag=0; infile>>card; while(!infile.eof()) { if(strcmp(card.GetNo(),cardno)==0) { flag=1; break; } infile>>card; } infile.close(); if(flag==0) { cout<<"The BookCardNo not exist!\n"; return; } char we='y'; char bookno[10]; while(we=='y') { cout<<"Input the bookno you want borrow:"; cin>>bookno; infile.open("book.txt",ios::in); flag=0; infile>>book; while(!infile.eof()) { if(strcmp(book.GetNo(),bookno)==0) { if(book.GetBorrowed()=='0') { flag=1; break; } } infile>>book; } int pos=infile.tellg(); infile.close(); if(flag==0) { cout<<"The book has borrowed or not exist!\n"; continue; } book.SetBorrowed('1'); ofstream outfile; outfile.open("book.txt",ios::ate); outfile.seekp(pos-21); outfile<<book; outfile.close(); outfile.open("borrow_hofel.txt",ios::app); hofel=Borrowhofel(cardno,bookno); outfile<<hofel; outfile.close(); cout<<"Do you continue?(y\\n)"; cin>>we; } } void return_book() { Borrowhofel hofel; BC card; Book book; char cardno[12]; cout<<"Input your BookCardN"; cin>>cardno; ifstream infile; infile.open("BC.txt",ios::in); int flag=0; infile>>card; while(!infile.eof()) { if(strcmp(card.GetNo(),cardno)==0) { flag=1; break; } infile>>card; } infile.close(); if(flag==0) { cout<<"The BookCardNo not exist!\n"; return; } char we='y'; char bookno[15]; while(we=='y') { cout<<"Input the bookno you want return:"; cin>>bookno; infile.open("book.txt",ios::in); flag=0; infile>>book; while(!infile.eof()) { if(strcmp(book.GetNo(),bookno)==0 &&book.GetBorrowed()=='1') { flag=1; break; } infile>>book; } int pos=infile.tellg(); infile.close(); if(flag==0) { cout<<"The book has not borrowed or not exist!\n"; continue; } book.SetBorrowed('0'); ofstream outfile; outfile.open("book.txt",ios::ate); outfile.seekp(pos-21); outfile<<book; outfile.close();flag=0; infile.open("borrow_hofel.txt",ios::in); outfile.open("tempt.txt",ios::out); infile>>hofel; while(!infile.eof()) { if(strcmp(hofel.GetCardNo(),cardno)|| strcmp(hofel.GetBookNo(),bookno)) outfile<<hofel; infile>>hofel; } infile.close(); outfile.close(); infile.open("tempt.txt",ios::in); outfile.open("borrow_hofel.txt",ios::out); infile>>hofel; while(!infile.eof()) { outfile<<hofel; infile>>hofel; } infile.close(); outfile.close(); cout<<"Do you continue?(y\\n)"; cin>>we; } } void inquire_book() { Book book; char we='y'; ifstream infile; char bookno[10]; while(we=='y') { infile.open("book.txt",ios::in); cout<<"input BookN"; cin>>bookno; infile>>book; while(strcmp(book.GetNo(),bookno)&&!infile.eof()) { infile>>book; } if(infile.eof()) cout<<"the book not exist!\n"; else book.print(); infile.close(); cout<<"Are you continue?(y\\n)"; cin>>we; } } void inquire_BC() { BC card; char we='y'; ifstream infile; char cardno[10]; while(we=='y') { infile.open("BC.txt",ios::in); cout<<"input BookCardN"; cin>>cardno; infile>>card; while(strcmp(card.GetNo(),cardno)&&!infile.eof()) { infile>>card; } if(infile.eof()) cout<<"the BookCard not exist!\n"; else card.print(); infile.close(); cout<<"Are you continue?(y\\n)"; cin>>we; } }

void main() { char a; cout<<"************************************\n" <<"* 1.to inquire card. *\n" <<"* 2.to borrow book. *\n" <<"* 3.to return book. *\n" <<"* 4.to inquire book. *\n" <<"* 5.to enter new book. *\n" <<"* 6.to enter new card. *\n" <<"* 7.to quit the system. *\n" <<"************************************\n"; cout<<"Select the NO!"<<endl; cin>>a; int flag=1; while(flag) { switch(a) { case '1':inquire_BC();break; case '2':borrow_book();break; case '3':return_book();break; case '4':inquire_book();break; case '5':enter_book();break; case '6':enter_BC();break; case '7':flag=0;continue; } cout<<"Select the NO!\n"; cin>>a; } }

搜索更多相关主题的帖子: 图书馆 执教 
2005-07-04 12:31
当当
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2004-4-30
收藏
得分:0 
加些注释,有点看不明白。

学好编程就能编出自己的未来! 加油!自信!努力!奋斗!
2005-07-04 14:47
qiqiaizhuzhu
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2005-7-5
收藏
得分:0 
都加点解释嘛!
2005-07-05 10:48
阿甘
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2005-6-9
收藏
得分:0 
好的代码是要有注释的。
2005-07-05 22:49
Tailor
Rank: 1
等 级:新手上路
帖 子:152
专家分:0
注 册:2005-6-26
收藏
得分:0 
我不爱看没有注释的文章

2005-07-15 09:20
wanshihaohao
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-7-24
收藏
得分:0 
我相信加了注释会更好些
2005-07-24 10:31
快速回复:图书馆程序(希望大家多多执教)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030142 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved