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

程序现在能用了 忘哥哥姐姐门改进一下,功能实现的不是很好
#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()
{
ofstream file("person.txt" , ios::ate );
if(!file)
{
cerr << "打开文件person.txt失败" << endl;
exit(1);
}
reader re;
cout << "输入1添加读者的信息,0退出!"<<endl;
int x;
cin >> x;
while(x == 1)
{
cout << "请输入读者姓名:\n";
cin>>re.name;
cout <<"请输入读者的编号:\n";
int num;
cin >> num;
//cout<<"请输入读者所借书的编号!";
re.readernum = num;
re.rebonum = 0;
file.seekp((num- 1)*sizeof(reader));
file.write(reinterpret_cast<const char *>(&re), sizeof(reader));
cout << "输入1读入读者的信息,0退出!"<<endl;
cin >> x;
}
}


//设置日期
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.seekg((n-1)*sizeof( bookrecord));
infile.read(reinterpret_cast< char *>(&management) , sizeof(bookrecord));
while(infile&&!infile.eof())
{
if(n == management.booknum)
{
cout<<"图书馆里有这本书!"<<endl;
cout<<"请输入读者的编号!"<<endl;
cin>>pn;
pinfile.seekg((pn-1)*sizeof( reader));
pinfile.read(reinterpret_cast< char *>(&people) , sizeof(reader));
while(pinfile&&!pinfile.eof())
{
if(pn == people.readernum && n == people.rebonum)
{
cout<<"你已经借过这本书了!!!"<<endl;
return;
}
else if(pn != people.readernum)
{
cout <<"该用户不存在!"<<endl;
return;
}
else
{
people.rebonum = people.rebonum+ 1;//读者所借的书的数量
poutfile.seekp((pn - 1)*sizeof(reader));
poutfile.write(reinterpret_cast<const char *>(&people), sizeof(reader));

management.nownum --;//现有图书减少一本

outfile.seekp((management.booknum - 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();
return;
}
}
}
else
{
cout<<"图书馆里没有这本书!"<<endl;
return;
}
}
}

//还书管理
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;
cout<<"请输入你的编号!"<<endl;
cin>>peonum;
borrow bor;
bookrecord rec;
reader r;
ibookback.seekg((boonum-1)*sizeof(borrow));
ibookback.read(reinterpret_cast<char *>(&bor) , sizeof(borrow));
while(ibookback && !ibookback.eof())
{
if(bor.booknumber != boonum || bor.readernumber != peonum)
{
cout<<"你的编号或者书的编号有错误!"<<endl;
return;
}
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));
// reader r;

ipeople.seekg((peonum-1)*sizeof(reader));
ipeople.read(reinterpret_cast<char *>(&r),sizeof(reader));
//while(ipeople && !ipeople.eof())
//{
r.rebonum--;//读者所借书的数量减一
opeople.seekp((peonum-1)*sizeof(reader));

opeople.write(reinterpret_cast<const char *>(&r),sizeof(reader));
// }
cout <<"还书成功!"<<endl;
return;
}
}
}
//输出书库信息
void bookmanage()
{
bookrecord book;
ifstream infile("libraly.txt" , ios::in);
if (!infile)
{
cerr<<"文件没有打开!"<<endl;
exit(1);
}

cout<<setiosflags(ios::left)<<setw(6)<<"图书编号"<<" "
<<setw(15)<<"图书名字"<<setw(15)<<"出版社"<<setw(10)<<"价格"
<<setw(10)<<"藏书数量"<<setw(5)<<"现有数量"<<endl;
infile.seekg(0);
infile.read(reinterpret_cast<char *>(& book),sizeof(bookrecord));
while(infile && !infile.eof())
{
if(book.booknum !=0)
cout<<setiosflags(ios::left | ios::fixed | ios::showpoint)<<setprecision(2)
<<setw(11)<<book.booknum<<setw(15)<<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(1)<<*/" "<<"读者编号"<<" "
<<setw(15)<<"读者名字"<<setw(15)<<"已借图书数量 "
<<setw(10)<<endl;
pminfile.seekg(0);
pminfile.read(reinterpret_cast<char *>(& pmanage),sizeof(reader));
while(pminfile && !pminfile.eof())
{
if(pmanage.readernum !=0)
cout<<setiosflags(ios::right)<<setw(11)<<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();
for(int i = 0 ;i <70 ; i ++)
cout<<"-";
readerout();
}
else if(ch == 3)
bookback();
else if(ch == 4)
bookborrow();
else if(ch == 5)
person();
}


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-7-26 10:34:37编辑过]

搜索更多相关主题的帖子: 图书管理系统 int include void struct 
2006-07-25 16:16
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 
那么凌乱的啊,今晚我重新写过,当是锻炼一下C++,这个问题你应该发去我们数据结构的板块嘛

[此贴子已经被作者于2006-7-25 17:05:04编辑过]



c++/C + 汇编 = 天下无敌
2006-07-25 17:04
yushui
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:1355
专家分:22
注 册:2006-7-19
收藏
得分:0 

呵呵 多谢大哥哥了 我也慢慢去改一下 哎 可爱的老师好严哦


fighting!from now on!
2006-07-25 17:36
快速回复:[求助]图书管理系统能用了,就是不是很好用
数据加载中...
 
   



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

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