| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 567 人关注过本帖
标题:[求助]修改一下这个图书管理系统的程序实现功能
只看楼主 加入收藏
yushui
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:1355
专家分:22
注 册:2006-7-19
结帖率:100%
收藏
 问题点数:0 回复次数:0 
[求助]修改一下这个图书管理系统的程序实现功能

没有语法错误了,但是该实现的功能实现不了 555 就要交了
#include <iostream.h>
#include <fstream.h>
#include<string.h>
#include<stdlib.h>
#include<iomanip.h>

//void enterchoice( int );
//void bookmanage();
//void readerout();

struct reader{
int readernum;//读者编号
char name[9];//读者姓名
int rebonum;//已借书的编号
};

struct borrow{
//借书的日期
int byear;
int bmonth ;
int bday;
//还书的日期
int ryear;
int rmonth ;
int rday;
int readernumber ; //读者的编号
int booknumber ; //所借的图书编号
};

/*struct reback{
int ryear;
int rmouth ;
int rday;
};*/

struct bookrecord{
int booknum;//图书编号
char bookname[20];//图书名字;
char publishhouseofbook[50];//图书出版社
double bookprice;//图书价格
int number;//图书的数量
int nownum;//图书馆该书现有数量
};

//输入图书记录
void input(bookrecord &record)
{
cout<<"请输入图书的名字:\n";
cin>>record.bookname;
cout<<"请输入图书出版社:\n";
cin>>record.publishhouseofbook;
cout<<"请输入图书的价格:\n";
cin>>record.bookprice;
cout<<"请输入图书数量:\n";
cin>>record.number;
record.nownum = record.number;
return;
}

//增加图书记录
void addbookrecord()
{
int num;
bookrecord record;
ofstream outfile("libraly.txt" , ios::ate );
ifstream infile("libraly.txt" , ios::in );
if(!outfile && !infile)
{

cerr << "打开文件libraly.txt失败" << endl;
exit(1);
}
cout <<"请输入图书的编号(o to end):\n";
cin>>num;
infile.seekg((num-1)*sizeof( bookrecord));
infile.read(reinterpret_cast< char *>(&record) , sizeof(bookrecord));
while(num!=0)
{
if(num == record.booknum)//看书的编号是否一样
{

cout<<"书库中有这本书!/n";
record.number++;//增加这本书的记录
record.nownum++;//现有图书增加
outfile.seekp((num-1)*sizeof( bookrecord));
outfile.write(reinterpret_cast<const char *>(&record),sizeof( bookrecord));
}
else
{
input(record); //新书入库
record.booknum=num;
outfile.seekp((num-1)*sizeof( bookrecord));
outfile.write(reinterpret_cast<const char *>(&record),sizeof( bookrecord));

}
cout <<"请输入图书的编号(0 to end):\n";
cin>>num;


}

}

//读者管理
void person(reader &aread)
{
ofstream file("person.txt" , ios::ate );
if(!file)
{
cerr << "打开文件person.txt失败" << endl;
exit(1);
}
cout << "请输入读者的编号,0退出!"<<endl;
cin >> aread.readernum;
while(aread.readernum!=0)
{
cout << "请输入读者姓名:\n";
cin >> aread.name;
//cout<<"请输入读者所借书的编号!";
aread.rebonum = 0;

file.seekp((aread.rebonum - 1)*sizeof(reader));
file.write(reinterpret_cast<const char *>(&aread), sizeof(reader));
cout << "请输入读者的编号,0退出!"<<endl;
cin >> aread.readernum;

}
file.close();
}

//设置日期
void setday(borrow &reb)
{

reb.ryear = reb.byear;
reb.rmonth =reb.bmonth + 1;
reb.rday = reb.bday;
}

//借阅管理
void bookborrow()
{

ofstream outfile("libraly.txt", ios::ate );
ifstream infile("libraly.txt", ios::in);
ofstream poutfile("person.txt",ios::ate);
ifstream pinfile("person.txt",ios::in);
if(!outfile||!infile||!poutfile||!pinfile)
{
cerr << "打开文件失败" << endl;
exit(1);
}
reader people;
int pn;//读者的编号
int n;//图书的编号
bookrecord management;

cout << "请输入借的图书编号:" << endl;
cin>> n ;
infile.read(reinterpret_cast< char *>(&management) , sizeof(bookrecord));
while(infile&&!infile.eof())
{
if(n == management.booknum)
{
cout<<"图书馆里有这本书!"<<endl;
cout<<"请输入读者的编号!"<<endl;
cin>>pn;
pinfile.read(reinterpret_cast< char *>(&people) , sizeof(reader));
while(pinfile&&!pinfile.eof())
{
if(pn == people.readernum && n == people.rebonum)

cout<<"你已经借过这本书了!!!"<<endl;
else if(pn != people.readernum)

cout <<"该用户不存在!"<<endl;
else
{
people.rebonum = n;//读者所借的书
poutfile.seekp((people.rebonum - 1)*sizeof(reader));
poutfile.write(reinterpret_cast<const char *>(&people), sizeof(reader));
management.nownum --;//现有图书减少一本
outfile.seekp((management.nownum - 1)*sizeof(bookrecord));
outfile.write(reinterpret_cast<const char *>(&management), sizeof(bookrecord));

ofstream bookoutfile("borrow.txt" , ios::ate);
borrow bookborrow;
outfile.close();
infile.close();
poutfile.close();
pinfile.close();
if(!bookoutfile)
{
cerr << "打开文件失败" << endl;
exit(1);
}
bookborrow.booknumber = n;
bookborrow.readernumber = pn;
cout<<"请输入借书的年 、 月 、 日!"<<endl;
cin >>bookborrow.byear >>bookborrow.bmonth >>bookborrow.bday;
setday(bookborrow);//设置还书限制时间
bookoutfile.seekp((bookborrow.booknumber - 1)*sizeof(borrow));
bookoutfile.write(reinterpret_cast<const char *>(&bookborrow), sizeof(borrow));
cout <<"你已经借到这本书了!"<<endl;
bookoutfile.close();
}
}
}
}
}

//还书管理
void bookback()
{

int peonum;//还书者的编号
int boonum;//要还的书编号
int year ,month , day;
ifstream ibookback("borrow.txt" , ios::in);
ofstream obookback("borrow.txt" , ios::ate);
ofstream obookmanage("libraly.txt", ios::ate );
ifstream ibookmanage("libraly.txt", ios::in );
ofstream opeople("person.txt",ios::ate);
ifstream ipeople("person.txt",ios::in);
if(!obookback || !ibookback|| !obookmanage|| !ibookmanage|| !opeople ||!opeople)
{
cerr<<"文件没有打开!"<<endl;
exit(1);
}
cout << "请输入你要还的书的编号和你的编号!"<<endl;
cin >>boonum>>peonum;
borrow bor;
bookrecord rec;
//ibookback.seekg((bor.booknumber-1)*sizeof(borrow));
ibookback.read(reinterpret_cast<char *>(&bor) , sizeof(borrow));
while(ibookback && !ibookback.eof())
{
if(bor.booknumber != boonum || bor.readernumber != peonum)
cout<<"你的编号或者书的编号有错误!"<<endl;
else
{
cout<<"请输入你的还书年 、 月、 日!"<<endl;
cin>>year>>month>>day;
if(bor.ryear<year || (bor.ryear == year && ((bor.rmonth == month &&bor.rday<day) || bor.rmonth <month)) )
cout<<"你借的书超过期限!!"<<endl;
borrow index = {0,0,0,0,0,0,0,0};
obookback.seekp((peonum - 1)*sizeof(borrow));
obookback.write(reinterpret_cast<const char *>(&index), sizeof(borrow));

ibookmanage.seekg((boonum-1)*sizeof(bookrecord));
ibookmanage.read(reinterpret_cast<char *>(&rec),sizeof(bookrecord));
rec.nownum++;//现有书量加一
obookmanage.seekp((boonum-1)*sizeof(bookrecord));
obookmanage.write(reinterpret_cast<const char *>(&rec),sizeof(bookrecord));
ipeople.seekg((boonum-1)*sizeof(reader));
ipeople.read(reinterpret_cast<char *>(&rec),sizeof(reader));
boonum = 0;//读者所借的这本书清零
obookmanage.seekp((boonum-1)*sizeof(bookrecord));
obookmanage.write(reinterpret_cast<const char *>(&rec),sizeof(bookrecord));
cout <<"还书成功!"<<endl;
obookback.close();
ibookback.close();
obookmanage.close();
ibookmanage.close();
ipeople.close();
opeople.close();
}
}
}
//输出书库信息
void bookmanage()
{
bookrecord book;
ifstream infile("libraly.txt" , ios::in);
if (!infile)
{
cerr<<"文件没有打开···"<<endl; exit(1);
}

cout<<setiosflags(ios::left)<<setw(8)<<"图书编号"
<<setw(20)<<"图书名字"<<setw(15)<<"出版社"<<setw(10)<<"价格"
<<setw(10)<<"藏书数量"<<setw(5)<<"现有数量"<<endl;
infile.seekg(0);
infile.read(reinterpret_cast<char *>(& book),sizeof(bookrecord));
while(infile && !infile.eof())
{
cout<<setiosflags(ios::left | ios::fixed | ios::showpoint)<<setprecision(2)
<<setw(8)<<book.booknum<<setw(20)<<book.bookname<<setw(15)
<<book.publishhouseofbook<<setw(10)<<book.bookprice<<setw(10)<<book.number<<setw(5)
<<book.nownum<<endl;
infile.read(reinterpret_cast<char *>(& book),sizeof(bookrecord));
}
infile.close();
}

//输出读者信息
void readerout()
{
reader pmanage;
ifstream pminfile("person.txt",ios::in);
if (!pminfile)
{
cerr<<"文件没有打开···"<<endl;
exit(1);
}
cout<<setiosflags(ios::left)<<setw(10)<<"读者编号"
<<setw(15)<<"读者名字"<<setw(15)<<"已借图书 "
<<setw(10)<<endl;
pminfile.read(reinterpret_cast<char *>(& pmanage),sizeof(reader));
while(pminfile && !pminfile.eof())
{
cout<<setiosflags(ios::left)<<setw(10)<<pmanage.readernum
<<setw(15)<<pmanage.name<<setw(15)<<pmanage.rebonum
<<setw(10)<<endl;
pminfile.read(reinterpret_cast<char *>(& pmanage),sizeof(reader));
}
pminfile.close();
}

void enterchoice(int ch)
{
reader p;
if(ch < 0||ch > 5){
cout<<"输入错误!\n请重新输入!"<<endl;
return;
}
else if(ch == 1)
addbookrecord();
else if(ch == 2)
{
bookmanage();
readerout();
}
else if(ch == 3)
bookback();
else if(ch == 4)
bookborrow();
else if(ch == 5)
person(p);
}


void main()
{
int choice ;
do{
cout <<"\n\n\n\n";
cout <<"\t\t 图书管理系统 \n";
cout <<"\t\t 主菜单      \n";
cout <<"\t\t\t @@@@@@@@@@@@@@@@@@@";
cout <<"\n\n\n";
cout <<"\t\t 1. 新书入库 \n";
cout <<"\t\t 2. 资料输出 \n";
cout <<"\t\t 3.还书    \n";
cout <<"\t\t 4.借书    \n";
cout <<"\t\t 5.读者管理 \n";
cout <<"\t\t 0.退出系统 \n";
cout <<"\n\n\n\n";
cout <<"请输入你要进行的操作:\n";
cin>>choice;
enterchoice(choice);
}while(choice!=0);
cout << "谢谢光临本系统!!!"<<endl;

}


搜索更多相关主题的帖子: 图书管理系统 
2006-07-23 23:37
快速回复:[求助]修改一下这个图书管理系统的程序实现功能
数据加载中...
 
   



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

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