资源简介
c++ 面向对象 图书管理系统 课程设计
代码片段和文件信息
#include
#include
#include
#include
#include
using namespace std;
#define rm 5
class book
{
public:
int id;
int tag;// shi fou cun zai zhe lei shu;
char name[20];
int onshelfcount;
int outcount;
public:
int getid(){return id;}
char* getname(){return name;}
int getonshelfcount(){return onshelfcount;}
int getoutcount(){return outcount;}
int gettag(){return tag;}
public:
void addbook(int nochar *naint count)
{
id=no;strcpy(namena);tag=1;
onshelfcount=count;outcount=0;
}
void deletebook(){tag=0;}
void disp()
{
cout< }
int borrowbook()
{
if(tag==0)
{
cout<<“无此书“< return 0;
}
else if(onshelfcount==0)
{
cout<<“已借完“< disp();
return 0;
}
else
{
onshelfcount--;outcount++;
disp();
cout<<“借书成功“< return 1;
}
}
int retbook()
{
if(tag==0)
{
cout<<“无此书,不能还“< return 0;
}
else if(outcount==0)
{
cout<<“此书没有借出,不能还“< disp();
return 0;
}
else
{
onshelfcount++;outcount--;
disp();
cout<<“还书成功“< return 1;
}
}
};
class Books
{
private:
book bk[100];
int top;
public:
Books()
{
book b;
top=-1;
fstream file(“book.txt“ios::in);
while(1)
{
file.read((char*)&bsizeof(b));
if(!file) break;
top++;
bk[top]=b;
}
file.close();
}
~Books()
{
fstream file(“book.txt“ios::out);
for(int i=0;i<=top;i++)
{
if(bk[i].gettag()==1)
{
file.write((char*)&bk[i]sizeof(bk[i]));
}
}
file.close();
}
void clear(){top=-1;}
book* query(int bookid)
{
for(int i=0;i<=top;i++)
{
if(bk[i].getid()==bookid&&bk[i].gettag()==1)
{
return &bk[i];
}
}
// cout<<“查无此书“< return NULL;
}
int addbook(int idchar na[]int count)
{
book*p=query(id);
if(p==NULL)
{
top++;
bk[top].addbook(idnacount);
return 1;
}
else
{
cout<<“该书已经存在“< return 0;
}
}
void bookdata();
void disp()
{
cout< for(int i=0;i<=top;i++)
{
if(bk[i].gettag()==1)
{
bk[i].disp();
}
}
}
};
void Books::bookdata()
{
int choicechoice2;
char bookname[20];
int bookid;
int bookcount;
book *p;
cout<<“图书管理“< do
{
cout<<“\t\t\t“<<“1新增图书“< cout<<“\t\t\t“<<“2修改图书“< cout<<“\t\t\t“<<“3删除图书“< cout<<“\t\t\t“<<“4查找图书“< cout<<“\t\t\t“<<“5显示全部图书“< cout<<“\t\t\t“<<“6删除全部图书“< cout<<“\t\t\t“<<“0退出图书管理“<
cout<<“输入选项:“;cin>>choice;
switch(choice)
{
case 1:
cout<<“输入图书的编号、书名、数目:“;
cin>>bookid>>bookname>>bookcount;
Books::addbook(bookidbooknamebookcount);
- 上一篇:MFC Tabcontrol 标签控件美化
- 下一篇:数字识别之神经网络法
相关资源
- C++获取计算机的CPU ID,硬盘序列号等
- C++头文件转delphi工具 + 源码
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
川公网安备 51152502000135号
评论
共有 条评论