c++编程问题

图书管理(***)
问题描述:图书管理的基本业务活动包括:对一本书的采编入库,清除库存,借阅和归还等。试设计一个简单的图书管理系统,实现图书采编、图书编目、图书查询及图书流通(借、还书)等的功能。
基本要求:每种书的登记内容至少包含书号、书名、作者、现存量和总库存量等五项。建立图书信息数据库文件以及相应的索引文件;建立关于书号、书名及作者的图书查询;实现图书的借还子系统,包括建立读者文件、借还文件、读者管理及图书借还等相关的处理。
测试数据:自行设

这是我大一(现在大三)时学C++的期末最后一个作业题,和同学两人一组做的。呵,如果你很想看,发给你看看也无妨,不过是控制台程序,MFC也有做,不过没做完。本人有说明文档,如果你想要,可以发给你看看。我的QQ363525805
#include<iostream.h>
#include<string.h>

struct Book //图书资料库
{ unsigned long num;
char name[30];
char writer[20];
char agency[30];
char key_word[5][20];
int state;
char Name[20];
unsigned long tel;
int date[3];
Book*next;

};

class LIB{
public:
LIB();
Book*creat();//创建图书资料库
void output();
unsigned set_maxday();
void search();
void borrow();
void retn();
int y_d(int yw); //计算天数相关函数
int m_d(int yw,int mw);
int s_d(int yw,int mw,int dw);
int cal_day(int data[],int date_1[]);
void urge();
private:
Book*h;
int days;
int date_1[3];
unsigned tot_day;
unsigned max_day;
};

LIB::LIB() //构造函数
{ h=NULL;
}

unsigned LIB::set_maxday()
{ cout<<"\n请输入借书的最大天数:\n";
cin>>max_day;
return max_day;
}

Book* LIB::creat()
{
Book *p, *q,*temp,*pre; Book* temp2; unsigned number;

do{temp=h;
int i=0;
p=new Book;
q=p;
do
{
cout<<"请输入书号(0 结束输入): ";
cin>>number;
temp2=h;
while(temp2!=NULL&&temp2->num!=number)
{ temp2=temp2->next;}
if(temp2!=NULL&&temp2->num==number)
cout<<"\n书号已经存在,请重新输入!"<<endl;

}while(temp2!=NULL&&temp2->num==number);
p->num=number;
if(p->num==0) break;

if(p->num==0) break;
cout<<"请输入书名(不超过30个字符): ";
cin>>p->name;
cout<<"请输入作者(不超过20个字符): ";
cin>>p->writer;
cout<<"请输入出版社(不超过30个字符): ";
cin>>p->agency;
cout<<"请输入关键词(最多5个,每个关键字不超过10个字符,中文不超过5个):\n";
do{

cout<<"请输入关键词"<<i+1<<"(0退出): ";
cin>>p->key_word[i];
i++;
}while(strcmp(p->key_word[i-1],"0")!=0&&i<=5);

do
{ cout<<"请输入该书状态(1:在库 0:借出): ";
cin>>p->state;
if(p->state!=0&&p->state!=1) cout<<"状态须为0或1!\n请重输!\n";
}while(p->state!=0&&p->state!=1);
if(p->state==0)
{ cout<<"\n请输入借阅者的名字: ";
cin>>p->Name;
cout<<"\n请输入借阅者的电话号码: ";
cin>>p->tel;
cout<<"\n请输入借阅日期(年,月,日): ";
cin>>p->date[0]>>p->date[1]>>p->date[2];
}
cout<<endl;
if(h==NULL) { h=p; p->next=NULL; }
else
{ while(q->num>temp->num&&temp->next!=NULL){ pre=temp; temp=temp->next; }
if(q->num<temp->num)
{ if(h==temp) { q->next=temp; h=q; }
else { pre->next=q; q->next=temp; }
}
else
{ temp->next=q; q->next=NULL; }
}
}while(1);
return h;
}

void LIB::output()
{ Book *temp; int ch,k; int i=0;
k=0;
if(h==NULL) cout<<"图书馆没有藏书!\n";
else
{
{ cout<<"请选择所要的操作:\n 1:查看全部在库图书\n 2:查看全部借出的图书 \n 3:查看所有图书\n";
cin>>ch;
}while(ch!=1&&ch!=2&&ch!=3);
temp=h;
cout<<"\n您想要的资料如下:\n";
switch(ch){
case(1):
while(temp!=NULL)
{ if(temp->state==1)
{ cout<<" 书号: "<<temp->num<<endl;
cout<<" 书名: "<<temp->name<<endl;
cout<<" 作者: "<<temp->writer<<endl;
cout<<" 出版社: "<<temp->agency<<endl;
while(strcmp(temp->key_word[i],"0")!=0&&i<=4)
{ cout<<"关键词"<<i+1<<": "<<temp->key_word[i]<<endl;
i++;
}
i=0;
k=1;
cout<<endl;
}
temp=temp->next;
}
break;
case(2): while(temp!=NULL)
{ if(temp->state==0)
{ cout<<" 书号: "<<temp->num<<endl;
cout<<" 书名: "<<temp->name<<endl;
cout<<" 作者: "<<temp->writer<<endl;
cout<<" 出版社: "<<temp->agency<<endl;
cout<<"借阅者姓名: "<<temp->Name<<endl;
cout<<"借阅者电话: "<<temp->tel<<endl;
cout<<" 借阅日期: "<<temp->date[0]<<"年"<<temp->date[1]<<"月"<<temp->date[2]<<"日"<<endl;
cout<<endl;
while(strcmp(temp->key_word[i],"0")!=0&&i<=4)
{ cout<<"关键词"<<i+1<<": "<<temp->key_word[i]<<endl;
i++;
}
i=0;
k=1;
}
temp=temp->next;
}
break;
case(3): while(temp!=NULL)
{ if(temp->state==0)
{ cout<<" 书号: "<<temp->num<<endl;
cout<<" 书名: "<<temp->name<<endl;
cout<<" 作者: "<<temp->writer<<endl;
cout<<" 出版社: "<<temp->agency<<endl;
cout<<"借阅者姓名: "<<temp->Name<<endl;
cout<<"借阅者电话: "<<temp->tel<<endl;
cout<<" 借阅日期: "<<temp->date[0]<<"年"<<temp->date[1]<<"月"<<temp->date[2]<<"日"<<endl;
while(strcmp(temp->key_word[i],"0")!=0&&i<=4)
{ cout<<" 关键词"<<i+1<<": "<<temp->key_word[i]<<endl;
i++;
}
i=0;
cout<<endl;
k=1;
}
if(temp->state==1)
{ cout<<" 书号: "<<temp->num<<endl;
cout<<" 书名: "<<temp->name<<endl;
cout<<" 作者: "<<temp->writer<<endl;
cout<<" 出版社: "<<temp->agency<<endl;
while(strcmp(temp->key_word[i],"0")!=0&&i<=4)
{ cout<<"关键词"<<i+1<<": "<<temp->key_word[i]<<endl;
i++;
}
i=0;
cout<<endl;
k=1;
}
temp=temp->next;
}
break;
}
}
if(k==0) cout<<"没有你想要的资料!\n\n";
}

//计算天数的相关函数
int LIB::y_d(int yw) //计算某年的天数
{ if((yw%4==0&&yw%100!=0)||yw%400==0) return 366;
else return 365;
}

int LIB::m_d(int yw,int mw) //计算某月的天数
{
long d;
if(mw==1||mw==3||mw==5||mw==7||mw==8||mw==10||mw==12) d=31;
else
if(mw==2) { d=28;
if(y_d(yw)==366) d++;
}
else d=30;
return d;
}

int LIB::s_d(int yw,int mw,int dw) //计算某天到当年年初的天数
{ long s; int i;
s=dw;
for(i=1;i<mw;i++)
s+=m_d(yw,i);
return s;
}
//计算天数的相关函数结束

int LIB::cal_day(int date[],int date_1[]) //计算两日期间的天数的主函数
{ int year;

if(date[0]<date_1[0])
{ tot_day=y_d(date[0])-s_d(date[0],date[1],date[2]);
for(year=date[0]+1;year<date_1[0];year++) tot_day+=y_d(year);
tot_day+=s_d(date_1[0],date_1[1],date_1[2]);
}
else tot_day=s_d(date_1[0],date_1[1],date_1[2])-s_d(date[0],date[1],date[2]);
return tot_day;
}

void LIB:: urge() //催还书
{
Book*temp; int i=0;

cout<<"请输入当前日期(年 月 日):\n";
cin>>date_1[0]>>date_1[1]>>date_1[2];

temp=h;
if(h==NULL) cout<<"图书馆没有藏书!"<<endl;
else
{ cout<<"借阅到期名单:\n";
while(temp!=NULL)
{
if(temp->state==0)
{ tot_day=cal_day(temp->date,date_1);
if(tot_day>=max_day)
{ cout<<" 姓名: "<<temp->Name<<endl;
cout<<" 电话: "<<temp->tel<<endl;
cout<<" 书号: "<<temp->num<<endl;
cout<<" 书名: "<<temp->name<<endl;
cout<<" 作者: "<<temp->writer<<endl;
cout<<" 出版社: "<<temp->agency<<endl;
cout<<"借阅日期: "<<temp->date[0]<<"年"<<temp->date[1]<<"月"<<temp->date[2]<<"日"<<endl;
cout<<endl;
i=1;
}
}
temp=temp->next;
}
if(i==0) cout<<"没过期借阅的图书!\n";
}
}

void LIB::borrow() //借书函数
{ unsigned long number; Book *p;
cout<<"\n请输入所要借的书号:";
cin>>number;

p=h;
while(p!=NULL&&p->num!=number)
{

p=p->next;
}
if(p!=NULL&&p->num==number)
{
if( p->state==1) //如果在馆
{ cout<<"\n请输入你的名字:";
cin>>p->Name;
cout<<"\n请输入你的电话号码:";
cin>>p->tel;
cout<<"\n请输入今天的日期(年,月,日):";
cin>>p->date[0]>>p->date[1]>>p->date[2];
p->state=0;
cout<<"\n操作已成功完成!\n";
}
else cout<<"\n这本书已经借出!\n";

}
else cout<<"\n本馆未收藏此书!";
}

void LIB::retn() //还书的函数
{ unsigned long number; Book *p;
cout<<"\n请输入所要还书的书号:";
cin>>number;
p=h;
while(p!=NULL&&p->num!=number)
{

p=p->next;
}
if(p!=NULL&&p->num==number)
{ if(p->state==1) cout<<"\n此书未借出!\n";
else
{
p->state=1;
cout<<"操作已成功!\n";
}
}
else cout<<"\n非本图书馆藏书!\n";
}

void LIB::search()
{ int choice;
cout<<"\n你想通过哪种方式查询(1:书号;2:书名;3:关键词;其他 退出)?:";
cin>>choice;
Book *p;
p=h;
if(choice==1) //通过书号
{ unsigned long number;
cout<<"\n请输入想要查找的书号: ";
cin>>number;
int a=0;
while(p!=NULL)
{

if(p->num==number)
{ cout<<"\n 书号: "<<p->num;
cout<<"\n 书名: "<<p->name;
cout<<"\n 作者: "<<p->writer;
cout<<"\n出版社: "<<p->agency;
if(p->state==1) cout<<"\n这本书在馆内 ."<<endl;
else cout<<"\n这本书已被借出 ."<<endl;
a=1;
}

p=p->next;
}
if(a==0) cout<<"\n 馆内无此书。";
}
if(choice==2) //通过书名
{
char name1[30];
cout<<"\n请输入想要查找的书名:";
cin>>name1;
int a=0;
while(p!=NULL)
{
if(strcmp(p->name,name1)==0)
{ cout<<"\n 书号: "<<p->num;
cout<<"\n 书名: "<<p->name;
cout<<"\n 作者: "<<p->writer;
cout<<"\n出版社: "<<p->agency;
if(p->state==1) cout<<"\n这本书在馆内 ."<<endl;
else cout<<"\n这本书已经被借出 ."<<endl;
a=1;
}
p=p->next;
}
if(a==0) cout<<"\n馆内没有这本书。";
}
if(choice==3)
{ p=h;
int a=0;
char key[5][20];
int i=0;
do
{ cout<<"\n请输入关键词"<<i+1<<"(0 to end):";
cin>>key[i];
i++;
}while(strcmp(key[i-1],"0")!=0&&i!=5);

do
{ int u=0; int j=0; //j用来记录关键词的个数,u用于记录相同关键词的个数
for(i=0; i<5; i++)
{
if(strcmp(p->key_word[i],"0")!=0)
j++;
}

for(int m=0;m<5;m++)
{
for(int n=0;n<5;n++)
{
if(strcmp(p->key_word[m],key[n])==0)
u++;
}
}
if(u>(j/2))
{ cout<<"\n 书号: "<<p->num;
cout<<"\n 书名: "<<p->name;
cout<<"\n 作者: "<<p->writer;
cout<<"\n出版社: "<<p->agency;
if(p->state==1) cout<<"\n这本书在馆内 ."<<endl;
else cout<<"\n这本书已经被借出 ."<<endl;
a=1;
}
p=p->next;
}while(p!=NULL);
if(a==0) cout<<"\n馆内没有这样的书。";
}
}

void main()
{
int ch;
LIB library;
library.creat();
library.set_maxday();
library.output();
do{
cout<<"\n请选择所要的操作:\n";
cout<<"1:图书查询 2:借书 3:还书 4:催还 5:查看书库 0:追加图书 其他:退出\n";
cin>>ch;

if(ch==0) library.creat();
if(ch==1) library.search();
if(ch==2) library.borrow();
if(ch==3) library.retn();
if(ch==4) library.urge();
if(ch==5) library.output();
}while(ch==0||ch==1||ch==2||ch==3||ch==4||ch==5);
cout<<"-------------- 谢谢使用!--------------\n";
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2007-01-02
我有个VF的管理系统,也是我以前的.如果要的话,加我QQ说话:331012005
下面是部分代码
SET EXACT ON
CLOSE all
USE manager

nam=thisform.text1.Text
pwd=thisform.text2.Text

LOCATE FOR ALLTRIM(用户名)=ALLTRIM(nam)
IF EOF()
MESSAGEBOX("用户名不存在")
return
else
IF ALLTRIM(密码)=ALLTRIM(pwd)
MESSAGEBOX("管理员成功登录!")
quanxian=1
supadmin=超管
thisform.Release
ELSE
MESSAGEBOX("密码错误!",48)
ENDIF
endif
return

PUBLIC findname,rem

ENDPROC
PROCEDURE Init
flstudentinf=flstudentinf+1
if flstudentinf>=2

messagebox("该窗口的一个范例已经在运行,为确保系统稳定性,请不要同时打开多个窗口!",48)
KEYBOARD "{ctrl+f4}"
return

endif
if quanxian=0
thisform.command4.enabled=.F.
thisform.command5.enabled=.F.
thisform.command6.enabled=.F.
endif
xuanding=-1
ENDPROC
PROCEDURE Destroy

flstudentinf=flstudentinf-1本回答被提问者采纳
第2个回答  2006-12-23
呵呵,你真拿百度这上面的积分当回事呀 .
图书管理(***)
问题描述:图书管理的基本业务活动包括:对一本书的采编入库,清除库存,借阅和归还等。试设计一个简单的图书管理系统,实现图书采编、图书编目、图书查询及图书流通(借、还书)等的功能。
基本要求:每种书的登记内容至少包含书号、书名、作者、现存量和总库存量等五项。建立图书信息数据库文件以及相应的索引文件;建立关于书号、书名及作者的图书查询;实现图书的借还子系统,包括建立读者文件、借还文件、读者管理及图书借还等相关的处理。
测试数据:自行设
第3个回答  2006-12-24
不管你是用 C++ 还是C,

不如调用数据库来写,方便且快,

当然如果是作业,你就当我没说吧
第4个回答  2006-12-24
晕~~可以直接做个网页去上传了
还是动态网~~
呵呵~~~如果资料齐全~~
做这个样的网站需要一天到两天时间~~
我比较感兴趣哈
相似回答