急用C++图书管理系统

1、设计任务:
设计一个计算机管理系统完成图书管理基本业务。
2、要求:
(1)每种书的登记内容包括书号、书名、著作者、现存量和库存量;
(2) 对书号建立索引表(线性表)以提高查找效率;
(3) 系统主要功能如下:
*采编入库:新购一种书,确定书号后,登记到图书帐目表中,如果表中已有,则只将库存量增加;
*借阅:如果一种书的现存量大于0,则借出一本,登记借阅者的书证号和归还期限,改变现存量;
*归还:注销对借阅者的登记,改变该书的现存量。

就是一个简单的图书馆管理系统的基本功能,希望各位高人能帮帮忙,语句尽量简洁一些,以上
请编好后发到我的邮箱[email protected],谢谢
各位,能不能编得简单些,用动态的就行,不用搞成静态的

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>//输入/输出文件流类
using namespace std;
const int Maxr=100;//最多的读者
const int Maxb=100;//最多的图书
const int Maxbor=5;//每位读者最多借五本书
//读者类,实现对读者的信息的描述

class Reader
{
private:
int tag; //删除标记 1:已删 0:未删
int no; //读者编号
char name[10]; //读者姓名
int borbook[Maxbor];//所借图书
public:
Reader() {}
char *getname() {return name;} //获取姓名
int gettag() {return tag;} //获取删除标记
int getno() {return no;} //获取读者编号
void setname(char na[]) //设置姓名
{
strcpy(name,na);

}
void delbook(){ tag=1; }//设置删除标记 1:已删 0:未删
void addreader(int n,char *na)//增加读者
{
tag=0;
no=n;
strcpy(name,na);
for(int i=0;i<Maxbor;i++)
borbook[i]=0;
}
void borrowbook(int bookid)//借书操作
{
for(int i=0;i<Maxbor;i++)
{
if (borbook[i]==0)
{
borbook[i]=bookid;
return;

}
}

}
int retbook(int bookid)//还书操作
{
for(int i=0;i<Maxbor;i++)
{
if(borbook[i]==bookid)
{
borbook[i]=0;
return 1;

}
}
return 0;
}
void disp()//读出读者信息
{
cout << setw(5) << no <<setw(10) << name<<"借书编号:[";
for(int i=0;i<Maxbor;i++)
if(borbook[i]!=0)
cout << borbook[i] << "|";
cout << "]"<<endl;

}
};

//读者类库,实现建立读者的个人资料
class RDatabase
{
private:
int top; //读者记录指针
Reader read[Maxr];//读者记录
public:
RDatabase() //构造函数,将reader.txt读到read[]中
{
Reader s;
top=-1;
fstream file("reader.txt",ios::in);//打开一个输入文件
while (1)
{
file.read((char *)&s,sizeof(s));
if (!file)break;
top++;
read[top]=s;
}
file.close(); //关闭 reader.txt
}
void clear()//删除所有读者信息
{
top=-1;
}
int addreader(int n,char *na)//添加读者时先查找是否存在
{
Reader *p=query(n);
if (p==NULL)
{
top++;
read[top].addreader(n,na);
return 1;
}
return 0;

}
Reader *query(int readerid)//按编号查找
{
for (int i=0;i<=top;i++)
if (read[i].getno()==readerid &&
read[i].gettag()==0)
{
return &read[i];
}
return NULL;
}
void disp() //输出所有读者信息
{
for (int i=0;i<=top;i++)
read[i].disp();
}
void readerdata();//读者库维护
~RDatabase() //析构函数,将read[]写到reader.txt文件中
{
fstream file("reader.txt",ios::out);
for (int i=0;i<=top;i++)
if (read[i].gettag()==0)
file.write((char *)&read[i],sizeof(read[i]));
file.close();

}
};
void RDatabase::readerdata()
{

char choice;
char rname[20];
int readerid;
Reader *r;
while (choice!='0')
{
cout <<"\n\n\t\t\t读 者 维 护\n\n\n\t\t 1 新 增\n\n\t\t 2 更 改\n\n\t\t 3 删 除\n\n\t\t 4 查 找\n\n\t\t 5 显 示\n\n\t\t 6 全 删\n\n\t\t 0 退 出"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout << "输入读者编号:";
cin >> readerid;
cout << "输入读者姓名:";
cin >> rname;
addreader (readerid,rname);
break;
case '2':
cout << "输入读者编号:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout << " 该读者不存在 "<<endl;
break;
}
cout << "输入新的姓名:";
cin >> rname;
r->setname(rname);
break;
case '3':
cout << " 输入读者编号:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout <<" 该读者不存在" << endl;
break;
}
r->delbook();
break;
case '4':
cout << "读入读者编号:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout <<"该读者不存在"<< endl;
break;
}
r->disp();
break;
case '5':
disp();
break;
case '6':
clear();
break;
default:cout<<"输入错误,请从新输入:";break;
}
}
}

//图书类,实现对图书的描述,图书的编号,书名,借出,还入等
class Book
{
private:
int tag;//删除标记 1:已删 0:未删
int no;//图书编号
char name[20];//书名
int onshelf;//是否再架 1:再架 2:已借
public:
Book(){}
char *getname() { return name; }//获取姓名
int getno(){ return no; }//获取图书编号
int gettag(){ return tag; }//获取删除标记
void setname(char na[])//设置书名
{
strcpy(name,na);
}
void delbook(){ tag=1;}//删除图书
void addbook(int n,char *na)//增加图书
{
tag=0;
no=n;
strcpy(name,na);
onshelf=1;
}
int borrowbook()//借书操作
{
if (onshelf==1)
{
onshelf=0;
return 1;
}
return 0;
}
void retbook()//还书操作
{
onshelf=1;
}
void disp()//输出图书
{
cout << setw(6) << no << setw(18) << name << setw(10)
<<(onshelf==1? "在架":"已借") <<endl;
}
};

//图书库类,实现对图书的维护,查找,删除等
class BDatabase
{
private:
int top; //图书记录指针
Book book[Maxb]; //图书记录
public:
BDatabase()//构造函数,将book.txt读到book[]中
{
Book b;
top=-1;
fstream file("book.txt",ios::in);
while (1)
{
file.read((char *)&b,sizeof(b));
if (!file) break;
top++;
book[top]=b;
}
file.close();
}
void clear()//全删
{
top=-1;
}
int addbook(int n,char *na)//增加图书
{
Book *p=query(n);
if (NULL==p)
{
top++;
book[top].addbook(n,na);
return 1;
}
return 0;
}
Book *query(int bookid)//查找图书
{
for (int i=0;i<=top;i++)
if (book[i].getno()==bookid &&book[i].gettag()==0)
{
return &book[i];
}
return NULL;
}
void bookdata();//图书库维护
void disp()
{
for (int i=0;i<=top;i++)
if (book[i].gettag()==0)
book[i].disp();
}
~BDatabase()//析构函数,将book[]写到book.txt文件中
{
fstream file("book.txt",ios::out);
for (int i=0;i<=top;i++)
if (book[i].gettag()==0)
file.write((char *)&book[i],sizeof(book[i]));
file.close();
}
};
void BDatabase::bookdata()
{
char choice;
char bname[40];
int bookid;
Book *b;
while (choice!='0')
{
cout <<"\n\n\n\t\t\t图 书 维 护 "<<endl<<endl;
cout<<"\t\t1 新 增\n \t\t2 更 改\n\t\t3 删 除\n\t\t4 查 找\n\t\t5 显 示\n\t\t6 全 删\n\t\t0 退 出"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout << "输入图书编号:"<<endl;
cin >> bookid;
cout << "输入图书书名:"<<endl;
cin >> bname;
addbook(bookid,bname);
break;
case '2':
cout << "输入图书编号:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout << " 该图书不存在 "<<endl;
break;
}
cout << "输入新的书名:"<<endl;
cin >> bname;
b->setname(bname);
break;
case '3':
cout <<" 读入图书编号:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout <<" 该图书不存在" << endl;
break;
}
b->delbook();
break;
case '4':
cout << " 读入图书编号:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout <<" 该图书不存在"<< endl;
break;
}
b->disp();
break;
case '5':
disp();
break;
case '6':
clear();
break;
default:cout<<"输入错误,请从新输入:";
}
}
}

//main() 函数的实现,程序的主界面的引导

void main()
{
char choice;
int bookid,readerid;
RDatabase ReaderDB;
Reader *r;
BDatabase BookDB;
Book *b;
while(choice!='0')
{
cout <<endl<<endl<<"\t\t\t 图 书 管 理 系 统\n\n\n";

cout <<"\t\t\t1 借 书\n\n\t\t\t2 还 书 \n\n\t\t\t3 图 书 维 护\n\n\t\t\t4 读 者 维 护\n\n\t\t\t0 离 开"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout <<" 借书 读者编号:";
cin >>readerid;
cout <<" 图书编号: ";
cin >>bookid;
r=ReaderDB.query(readerid);//按编号查找
if (NULL==r)
{
cout <<" 不存在该读者,不能借书"<< endl;
break;
}
b=BookDB.query(bookid);
if (b==NULL)
{
cout <<" 不存在该图书,不能借书"<< endl;
break;
}
if (b->borrowbook()==0)
{
cout << " 该图书已借出,不能借书"<< endl;
break;
}
r->borrowbook(b->getno());
break;
case '2':
cout<<"还书\n 读者编号:";
cin >>readerid;
cout << " 图书编号:";
cin >>bookid;
r=ReaderDB.query(readerid);
if (r==NULL)
{
cout <<" 不存在该读者,不能还书" << endl;
break;
}
b=BookDB.query(bookid);
if (b==NULL)
{
cout <<" 不存在该图书,不能还书" <<endl;
break;
}
b->retbook();
r->retbook(b->getno());
break;
case '3':
BookDB.bookdata();
break;
case '4':
ReaderDB.readerdata();
break;
default:cout<<"输入错误,请从新输入:";

}
}
}
我也还是学生,我也用VB和数据库编写了 管理系统。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-12-26
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;

class CBook;
class CLibrary;
class CPeople;

CBook *head=NULL;
static int i;
int k;

bool check(string str)
{
for(int n=0;n<str.length();n++)
{
if((str[n]>'9'||str[n]<'0')&&(str[n]!='.'))
return false;
}
return true;
}

class CBook
{
public:
CBook(){}
virtual ~CBook(){}
friend class CBooksadministrator;
friend class CLibrary;
private:
int m_no;//图书编号
string bookName;//图书书名
string author;//图书作者
string bookCategory;//图书分类
string bookSummary;//图书简介
CBook* next;

};

class CLibrary
{
public:
CLibrary(){}
virtual ~CLibrary(){}
void showbook(CBook *);
void GetTotalbooks(CBook *);
private:
static int totalbook;
};

int CLibrary::totalbook=0;

void CLibrary::showbook(CBook *head)
{
CBook *p1,*p2,*p3;
p1=new CBook;
p2=new CBook;
p3=new CBook;
p1=head;
p2=head;
p3=head;
cout<<endl;
cout<<"图书信息如下:"<<endl;
cout<<"编号"<<setw(8)<<"分类"<<setw(8)<<"书名"<<setw(8)<<"作者"<<setw(8)<<"简介"<<endl;
while(p1)
{
if(p1->bookCategory=="哲学")
cout<<p1->m_no<<setw(8)<<p1->bookCategory<<setw(8)<<p1->bookName
<<setw(8)<<p1->author<<setw(8)<<p1->bookSummary<<endl;
p1=p1->next;
}
while(p2)
{
if(p2->bookCategory=="经济")
cout<<p2->m_no<<setw(8)<<p2->bookCategory<<setw(8)<<p2->bookName
<<setw(8)<<p2->author<<setw(8)<<p2->bookSummary<<endl;
p2=p2->next;
}
while(p3)
{
if(p3->bookCategory=="政治")
cout<<p3->m_no<<setw(8)<<p3->bookCategory<<setw(8)<<p3->bookName
<<setw(8)<<p3->author<<setw(8)<<p3->bookSummary<<endl;
p3=p3->next;
}
}

void CLibrary::GetTotalbooks(CBook *head)
{
while(head)
{
totalbook++;
head=head->next;
}
cout<<totalbook<<" 本图书可供借阅."<<endl;
}

class CBooksadministrator
{
public:
CBooksadministrator(){}
virtual ~CBooksadministrator(){}
CBook* creat();
void Inquiry(CBook * ,int );
void Inquiry(CBook * ,string);
void insert(CBook * ,int ,string ,string ,string ,string );
};

CBook* CBooksadministrator::creat()
{
CBook *p1,*p2;
string str;
p1=new CBook;
head=p1;
p2=p1;

for(i=1;;i++)
{
cout<<"图书编号: "<<i<<endl;
p1->m_no=i;
cout<<"请输入图书分类(哲学/政治/经济):";
cin>>str;
p1->bookCategory=str.c_str();
cout<<"请输入图书书名:";
cin>>str;
p1->bookName=str.c_str();
cout<<"请输入作者:";
cin>>str;
p1->author=str.c_str();
cout<<"请输入图书简介:";
cin>>str;
p1->bookSummary=str.c_str();
p2=p1;
//p1=new CBook;
p2->next=p1;
cout<<"是否继续录入(y/n)"<<endl;
cin>>str;
while(str!="y"&&str!="n")
{
cout<<"输入有误,重输(y/n)"<<endl;
cin>>str;
}
if(str=="y")
cout<<endl;
else
break;
}
k=i;
delete p1;
p2->next=NULL;
return head;
}

void CBooksadministrator::insert(CBook *head,int m_no,string bookCategory,string bookName,string author,string bookSummary)
{
CBook *list=new CBook;
list->next=list;
list->m_no=m_no;
list->bookCategory=bookCategory;
list->bookName=bookName;
list->author=author;
list->bookSummary=bookSummary;
if(m_no <= head->m_no)
{
list->next=head;
::head=list;
return;
}
CBook *temp=NULL;
while((m_no > head->m_no)&&(head->next!=NULL))
{
temp=head;
head=head->next;
}
if(m_no > head->m_no)
{
head->next=list;
list->next=NULL;
}
else
{
temp->next=list;
list->next=head;
}
}

void CBooksadministrator::Inquiry(CBook *head,int num)
{
CBook* p;
if(head->m_no==num)
{
p=head;
head=head->next;
cout<<"编号"<<setw(8)<<"分类"<<setw(8)<<"书名"<<setw(8)<<"作者"<<setw(8)<<"简介"<<endl;
cout<<head->m_no<<setw(8)<<head->bookCategory<<setw(8)<<head->bookName
<<setw(8)<<head->author<<setw(8)<<head->bookSummary<<endl;
p=p->next;
return ;
}
while(head)
{
if(head->next==NULL)
{
cout<<"找不到要查询的图书"<<endl;
return;
}
if(head->next->m_no==num)
{
p=head->next;
cout<<"编号"<<setw(8)<<"分类"<<setw(8)<<"书名"<<setw(8)<<"作者"<<setw(8)<<"简介"<<endl;
cout<<head->m_no<<setw(8)<<head->bookCategory<<setw(8)<<head->bookName
<<setw(8)<<head->author<<setw(8)<<head->bookSummary<<endl;
p=p->next;
return ;
}
head=head->next;
}
cout<<"找不到要查询的编号."<<endl;
}

void CBooksadministrator::Inquiry(CBook *head,string str2)
{
CBook* p;
if(head->bookName==str2)
{
p=head;
head=head->next;
cout<<"编号"<<setw(8)<<"分类"<<setw(8)<<"书名"<<setw(8)<<"作者"<<setw(8)<<"简介"<<endl;
cout<<head->m_no<<setw(8)<<head->bookCategory<<setw(8)<<head->bookName
<<setw(8)<<head->author<<setw(8)<<head->bookSummary<<endl;
p=p->next;
return ;
}
else if(head->author==str2)
{
p=head;
head=head->next;
cout<<"编号"<<setw(8)<<"分类"<<setw(8)<<"书名"<<setw(8)<<"作者"<<setw(8)<<"简介"<<endl;
cout<<head->m_no<<setw(8)<<head->bookCategory<<setw(8)<<head->bookName
<<setw(8)<<head->author<<setw(8)<<head->bookSummary<<endl;
p=p->next;
return ;
}
while(head)
{
if(head->next==NULL)
{
cout<<"找不到要查询的图书"<<endl;
return;
}
if(head->next->bookName==str2)
{
p=head->next;
cout<<"编号"<<setw(8)<<"分类"<<setw(8)<<"书名"<<setw(8)<<"作者"<<setw(8)<<"简介"<<endl;
cout<<head->m_no<<setw(8)<<head->bookCategory<<setw(8)<<head->bookName
<<setw(8)<<head->author<<setw(8)<<head->bookSummary<<endl;
p=p->next;
return ;
}
if(head->next->author==str2)
{
p=head->next;
cout<<"编号"<<setw(8)<<"分类"<<setw(8)<<"书名"<<setw(8)<<"作者"<<setw(8)<<"简介"<<endl;
cout<<head->m_no<<setw(8)<<head->bookCategory<<setw(8)<<head->bookName
<<setw(8)<<head->author<<setw(8)<<head->bookSummary<<endl;
p=p->next;
return ;
}
head=head->next;
}
cout<<"找不到要查询的图书."<<endl;
}

int main()
{
CBook book;
CLibrary library;
CBooksadministrator booksadministrator;
string str;
begin:
cout<<"1->重建图书2->显示图书3->插入图书4->查询图书5->图书数目Q->退出"<<endl;
cin>>str;
if(str[0]=='1')
{
system("cls");
::head=booksadministrator.creat();
system("cls");
goto begin;
}
else if(str[0]=='2')
{
system("cls");
if(head==NULL)
{
cout<<"图书目录为空,请重新键入"<<endl<<"按回车键返回主菜单"<<endl;
cin.get();
cin.get();
system("cls");
goto begin;
}
library.showbook(head);
cout<<"操作完毕,按回车键返回之菜单"<<endl;
}
else if(str[0]=='3')
{
system("cls");
int m_no;
string bookCategory, bookName,author,bookSummary;
if(head==NULL)
{
cout<<"图书目录为空,请重新键入"<<endl<<"按回车键返回主菜单"<<endl;
cin.get();
cin.get();
system("cls");
goto begin;
}
for(i=k+1;;i++)
{
cout<<"图书编号: "<<i<<endl;
m_no=i;
cout<<"请输入图书分类(哲学/政治/经济):";
cin>>str;
bookCategory=str.c_str();
cout<<"请输入图书书名:";
cin>>str;
bookName=str.c_str();
cout<<"请输入作者:";
cin>>str;
author=str.c_str();
cout<<"请输入图书简介:";
cin>>str;
bookSummary=str.c_str();
booksadministrator.insert(head,m_no,bookCategory,bookName,author,bookSummary);
cout<<"是否继续录入(y/n)"<<endl;
cin>>str;
while(str!="y"&&str!="n")
{
cout<<"输入有误,重输(y/n)"<<endl;
cin>>str;
}
if(str=="y")
cout<<endl;
else
break;
}
cout<<"操作完毕,按回车键返回之菜单"<<endl;
}
else if(str[0]=='4')
{
system("cls");
string str1;
cout<<"1->按图书编号查找2->按图书书名查找3->按图书作者查找"<<endl;
cin>>str1;
if(str1[0]=='1')
{
int num;
if(head==NULL)
{
cout<<"图书目录为空,请重新键入"<<endl<<"按回车键返回主菜单"<<endl;
cin.get();
cin.get();
system("cls");
}
cout<<"请输入要查询的图书编号:";
cin>>str1;
while(!check(str1))
{
cout<<"输入的不是数字,请重新输入,按0返回"<<endl;
cin>>str1;
}
num=atoi(str1.c_str());
booksadministrator.Inquiry(head,num);
}
else if(str1[0]=='2')
{
string BookName;
cout<<"输入你要查询的书名:";
cin>>BookName;
booksadministrator.Inquiry(head,BookName);
}
else
{
string m_author;
cout<<"输入你要查询的图书作者:";
cin>>m_author;
booksadministrator.Inquiry(head,m_author);
}
cout<<"操作完毕,按回车键返回之菜单"<<endl;
}
else if(str[0]=='5')
{
system("cls");
cout<<endl;
cout<<" 共有图书 ";
library.GetTotalbooks(head);
cout<<endl;
cout<<"操作完毕,按回车键返回之菜单"<<endl;
}
else
{
if(str[0]!='Q'&&str[0]!='q')
{
cout<<"请输入数字!按回车键返回"<<endl;
}
}
if(str[0]!='Q'&&str[0]!='q')
{
cin.get();
cin.get();
system("cls");
goto begin;
}
return 0;
}
第2个回答  2010-12-19
C++ 实现图书管理系统
2010-12-01 21:46
//book_class.h 代码如下:
#include <iostream>
#include <string>
#include <list>
#include <fstream>
#include <algorithm>
#include <iterator>
using namespace std;

typedef struct book_class
{
string book_number;
string book_name;
string book_public_infor;
string book_type; //图书类型;
string book_pbulic_time;//出版时间;
}book;

class equal1
{
public:
string str;
equal1(string str1):str(str1)
{}
bool operator () (book & book1)
{
if(book1.book_name==str || book1.book_number==str || book1.book_public_infor==str || book1.book_type==str)
return true;
return false;

}
};

class book_manage
{
public:
list<book> book_store_list;
public:
book_manage(){}
void sort();
void show();
void insert();
void erase();
void inquire();
void save(){};
void show(list<book>::iterator itr);
friend bool operator < (const book &book1,const book &book2)
{
return book1.book_name<book2.book_name;
}
friend ostream & operator << ( ostream &out,const book &book1)
{
out<<book1.book_name<<" "<<book1.book_number<<" "
<<book1.book_pbulic_time<<" "<<book1.book_public_infor<<" "
<<book1.book_type<<endl;
return out;
}

};

//book_class.cpp 实现文件内容如下:
#include "book_class.h"
void book_manage::sort()
{
int number;
if(this->book_store_list.size()==0)
{
cout<<"no book in the store!"<<endl;
return ;
}
loop: cout<<"input the information you want the book sort by:"<<endl;
cout<<"you can input:"<<endl;
cout<<"1:book_name"<<endl;
cout<<"2:book_num"<<endl;
cout<<"3:book_public_time."<<endl;
cout<<endl;
cin>>number;
cout<<" input the infor:"<<endl;

switch(number)
{
case 1:
this->book_store_list.sort();
cout<<"the information of book had been sort by book's name!"<<endl;
break;
case 2:
break;
case 3:
break;
default:
cout<<"Ǹʲô"<<endl;
goto loop;
}
cout<<" this is the new sort!"<<endl;

}

void book_manage::show()
{
if(this->book_store_list.size()==0)
cout<<"no book in the store!"<<endl;
else
{
ostream_iterator<book> os(cout," ");
copy(this->book_store_list.begin(),this->book_store_list.end(), os);
}
system("pause");
return ;
}
void book_manage::insert()
{
book_class book1;
cout<<"input the new book's information:"<<endl;
cout<<"eg: 001 ߵѧ 2001-9-10 "<<endl;
cin>>book1.book_number>>book1.book_name>>book1.book_public_infor>>book1.book_pbulic_time>>book1.book_type;
this->book_store_list.push_back(book1);
cout<<"insert successfully!"<<endl;
system("pause");
}

void book_manage::erase()
{
string book_name;
cin>>book_name;
list<book>::iterator itr=find_if(this->book_store_list.begin(),this->book_store_list.end(),equal1(book_name));
if(itr==this->book_store_list.end())
cout<<"can't find the book!"<<endl;
else
this->book_store_list.erase(itr);
}

void book_manage::inquire()
{
string book_infor;
bool find_flag=false;
cin>>book_infor;

list<book>::iterator itr=find_if(this->book_store_list.begin(),this->book_store_list.end(),equal1 (book_infor));
if(itr==this->book_store_list.end())
{
cout<<"can't find the information you want!"<<endl;
return;
}
while(itr!=this->book_store_list.end())
{
this->show(itr);
++itr;
itr=find_if(itr,this->book_store_list.end(),equal1 (book_infor));
}
}

void book_manage::show(list<book>::iterator itr)
{
cout<<"you may need it!"<<endl;
cout<<(*itr).book_name<<" "<<(*itr).book_number<<" "
<<(*itr).book_pbulic_time<<" "<<(*itr).book_public_infor<<" "
<<(*itr).book_type<<endl;
}

//main.cpp 主文件如下:
#include "book_class.h"

using namespace std;
int main()
{
//ifstream infile("book.txt");
// book_manage store(infile);
book_manage store;
loop: cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "<<endl<<endl<<endl;
cout<<"\t welcome to sxl.book_manage 1.0"<<endl<<endl;
cout<<"\t\tthe is the menu!"<<endl<<endl;

cout<<"\t\t1: show the information of book !"<<endl;
cout<<"\t\t2: sort the book's information !"<<endl;
cout<<"\t\t3: insert some book!"<<endl;
cout<<"\t\t4: erase some book!"<<endl;
cout<<"\t\t5: inquire book!"<<endl;
cout<<"\t\t6: exit the system!"<<endl<<endl;

int chose;
cout<<"input your chose:";
cin>>chose;

switch(chose)
{
case 1:
system("cls");
store.show();
cout<<"press any key to continue!"<<endl;
system("cls");
goto loop;
case 2:
system("cls");
store.sort();
store.show();
system("cls");
goto loop;
case 3:
store.insert();
store.show();
system("cls");
goto loop;
case 4:
cout<<"input the book's name or num you want to erase:";
store.erase();
store.show();
system("cls");
goto loop;
case 5:
cout<<" you may input the book's number,or book's name or book's pulbic_type:";
cout<<" input the book's infor:"<<endl;
store.inquire();
system("pause");
system("cls");
goto loop;
case 6:
store.save();
return 0;
default:
cout<<" Ǹʲô?"<<endl;
system("pause");
cout<<"press any key to chose again!"<<endl;
system("cls");
goto loop;
}
return 0;
}

//希望你只作参考。别拿这个东西去交作业什么的。。。对你没有什么好出的。。。
代码还是得自己写,才能有收获呢。。。。祝你好运。。。 by sx_liang
第3个回答  2010-12-20
//---------------------------------------------------------------------------
#include <fstream>
#include <cstdlib>
#include <ctime>

using namespace std;
int reverse(int a)
{
int r=0;
while (a)
{
r=r*10+a%10;
a/=10;
}
return r;
}
int main(void)
{
int rnd[10];
ofstream ofs("reverse.txt",ofstream::app);
srand(time(NULL));
if (!ofs) return -1;
ofs<<"10个[0,25000]区间内的随机数:\t";

for (int i = 0; i<10; i++) {
rnd[i]=rand()%25001;
ofs<<rnd[i]<<"\t" ;
}
ofs<<endl;
ofs<<"逆序数中的奇数有:\t" ;
for (int i=0; i < 10; i++) {
int tem=reverse(rnd[i]);
if (tem%2) {
ofs<<tem<<"\t";
}
}
ofs<<endl;
ofs.close();
return 0;
}
//---------------------------------------------------------------------------本回答被网友采纳
第4个回答  2010-12-25
我空间里有个《图书管理系统》,是用C语言写的,你可以看看。