/************************************************************************************/
/* 理光C++课程12月3号练习题目集 */
/* 练习名称 资料管理系统 */
/* 实现功能 进行各种新书和新期刊的买入、过时期刊的删除、借阅/归还事 */
/* 务的进行,必须不断地更新数据,在任何时候,资料库有关人员*/
/* 能够获取可借阅的图书或期刊的准确信息。 */
/* 完成日期 2008 年 12 月 4 日 */
/* 担当者 郭红伟 */
/************************************************************************************/
#include "PeridInfo.h"
#include "CBase.h"
#include "CBook.h"
/********<1>向文件添加图书信息<1>***************************/
void InsertBookInfo()
{
CBook *book = new CBook; //定义图书类的对象
char flag = 'y';
FILE *file;
file = fopen("book.dat","a");
if(!file)
{
cout<<"creat or open the file failed!"<<endl;
exit(0);
}
while(flag == 'y')
{
book->SetBookCode();
book->SetName();
book->SetPublisherName();
book->SetAuthorName();
book->SetPublishingDate();
book->SetPrice();
book->SetFlagBit();
book->WriteToFile(file);
cout<<"继续输入?(y/n)";
cin>>flag;
}
cout<<"期刊信息录入成功!可以继续操作!"<<endl;
fclose(file);
delete book;
}
/*****************************************************/
/*********<2>向文件添加期刊信息<2>**************************/
void InsertPeridInfo()
{
CPeriodical *perid = new CPeriodical; //定义期刊类的对象
char flag = 'y';
FILE *file;
file = fopen("periodical.txt","a");
if(!file)
{
cout<<"creat or open the file failed!"<<endl;
exit(0);
}
while(flag == 'y')
{
perid->SetBookCode();
perid->SetName();
perid->SetPublisherName();
perid->SetPeriodicity();
//perid->WriteToFile(file);
cout<<"继续输入?(y/n)";
cin>>flag;
}
cout<<"添加期刊信息成功!可以继续操作!"<<endl;
fclose(file);
delete perid;
}
/*****************************************************/
/*********<2>向文件添加新期刊信息<2>**************************/
void InsertNewPeridInfo()
{
PeridInfo *per = new PeridInfo; //定义新期刊信息类的对象
char flag = 'y';
FILE *file;
file = fopen("periodical.dat","a");
if(!file)
{
cout<<"creat or open the file failed!"<<endl;
exit(0);
}
while(flag == 'y')
{
per->SetPeridCode();
per->SetIssueNuber();
per->SetIssueDate();
per->SetIssuePrice();
cout<<"继续输入?(y/n)";
cin>>flag;
}
cout<<"添加新期刊信息成功!可以继续操作!"<<endl;
fclose(file);
delete per;
}
/*****************************************************/
/*****************************************************/
/*********<4>查询借阅,归还信息<4>****************************
void QueryInfo()
{
char ch;
if (ch == 'I')
cout<<"该图书已经借出!";
if(ch == 'R')
cout<<"该图书已经被归还!";
}
/*********<5>读取在库图书信息<5>****************************/
void SelectBookInfo()
{
FILE *file;
file = fopen("book.dat" , "r");
if(file==NULL)
{
printf("open file failed or the file do not exist!\n");
exit(0);
}
int i = 0;
char c, cb='\0';
while((c=getc(file))!=EOF)
{
if(c == '\n')
i++;
cb = c;
}
if(cb != '\n')
i++;
if(i>0)
{
CBook *book = new CBook[i];
CBase *base = new CBase;
rewind(file); //将光标移动到文件头;
cout<<"查询到的图书是:"<<endl;
for(int j = 0;j<i;j++)
{
cout<<"\n您查询的第"<<j + 1<<"本图书详细信息如下:"<<endl;
book[j].ReadFromFile(file);
base = &book[j];
base->Dis(); //调用基类的成员函数
}
cout<<"图书查找完毕!可以继续操作!"<<endl;
fclose(file);
delete []book;
}
else
{
fclose(file);
cout<<"没有该图书信息!请继续别的操作!"<<endl;
}
}
/*****************************************************/
/*********<5>读取在库期刊信息<5>****************************/
/*void SelectPeriodInfo()
{
FILE *file;
file = fopen("periodical.dat" , "r");
if(file==NULL)
{
printf("open file failed or the file do not exist!\n");
exit(0);
}
int i = 0;
char c, cb='\0';
while((c=getc(file))!=EOF)
{
if(c == '\n')
i++;
cb = c;
}
if(cb != '\n')
i++;
if(i>0)
{
PeridInfo *p = new PeridInfo[i];
rewind(file); //将光标移动到文件头;
cout<<"查询到的图书是:"<<endl;
for(int j = 0;j<i;j++)
{
p[j].ReadFromFile(file);
//p->ShowPerInfo();
}
cout<<"期刊查找完毕!可以继续操作!"<<endl;
fclose(file);
delete []p;
}
else
{
fclose(file);
cout<<"没有该期刊信息!请继续别的操作!"<<endl;
}
}*/
/*****************************************************/
void main()
{
int flag=1;
char flag1;
cout<<"\n\t\t"<<"LIBRARY MANAGEMENT SYSTEM\n"<<endl;
cout<<"1. Add new Book details"<<endl;
cout<<"2. Add new Periodical details"<<endl;
cout<<"3. Record Issue/Return details"<<endl;
cout<<"4. Delete old Periodical Issue details"<<endl;
cout<<"5. View Available Books/Periodicals"<<endl;
cout<<"6. Exit\n"<<endl;
cout<<"\t\tEnter choice:";
while(flag != 0){
cin>>flag;
switch(flag)
{
case 1:
system("cls");
cout<<"\n\t\tADD NEW BOOK/PERIDICAL DETAILS\n"<<endl;
InsertBookInfo();
break;
case 2:
system("cls");
cout<<"\n\t\tAdd Periodical details or Issue details?<P/I>:";
cin>>flag1;
if(flag1 == 'P')
{
cout<<"\n\t\tADD NEW BOOK/PERIDICAL DETAILS\n"<<endl;
InsertPeridInfo();
}
if(flag1 == 'I')
{
InsertNewPeridInfo();
}
break;
case 3:
system("cls");
cout<<"\n\t\tRECORD ISSUE/RETURN\n";
cout<<"\n\t\tIssue or Return? <I/R>:";
cin>>flag1;
if(flag1 == 'I')
{
cout<<"\n\t\tRECORD ISSUE DETAILS\n"<<endl;
cout<<"\t\tIssue Book or Periodical? <B/P>:";
cin>>flag1;
if(flag1 == 'B')
InsertBookInfo();
else
InsertPeridInfo();
}
if(flag1 == 'R')
{
cout<<"您已经归还了该图书或期刊,谢谢使用!"<<endl;
}
break;
case 4:
system("cls");
cout<<"\n\t\tDELETE OLD PERIODICAL ISSUES\n";
break;
case 5:
system("cls");
cout<<"\n\t\tLIST OF AVAILABLE PERIODICAL ISSUES\n";
SelectBookInfo();
// SelectPeriodInfo();
break;
case 6:
system("cls");
cout<<"\n\t\t您退出了图书管理系统!\n\n\t\t谢谢您的光临,欢迎再次访问!\n\n";
exit(0);
default:
break;
}
}
}