图书管理程序-完美控制台c++(cpp)

//图书馆图书管理程序-完整版
//本程序提供了多次性入库图书的存储、反复借书还书的功能,一旦退出,库存书信息将会丢失
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int sort=0;
int a[1000];
 float b[1000];
 string n[1000]; //分别存放对象的名字、数量和价格
class Book
{
private:
 float s_p; //书本n的单本抵押金额
 int sum;  //某种书的总拥有量
public:
 double price;
 string bookname;
 Book()
 {

 }
 int Bookchange(string n,int a,float s)  //构造函数不能显式调用!!!!!!
 {
  sum=a;
  bookname=n;
  s_p=s;
  return(1);
 }
 void disp(); //显示图书存借情况
 int borrow(); //
 int restore(); //
};
/
void Book::disp()
 {
  cout<<setfill('-');
  cout<<"***"<<setw(18)<<right<<bookname<<"---------"<<left<<setw(23)<<sum<<"***"<<endl;
 };
int Book::borrow() //借出这些书本后剩下的书本数量
{
 int number_out;//一次性借出书的数量
 cout<<"请输入您想借的书的数量"<<endl;
 cin>>number_out;
 
 if(sum==0)
  cout<<"该书已经借完,请借其他书或者下次再来"<<endl;
  else if(sum<number_out)
  {
   cout<<"该书还剩下"<<sum<<"本,不能满足您的要求,请重新选择借书数量"<<endl;
  }
  else
  {
   price=s_p*number_out;
   sum=sum-number_out;
   cout<< "要借《" <<bookname<< "》书"<<number_out<<"本(其中,该书押金"<<s_p<<"元/本) "<<endl<<"您共需要付"<<price<<"元; "<<endl<<"书库还剩下"<<"该书"<<sum<<""<<endl;
  }
  return(sum);
}
int Book::restore()
{
 int number_in; //一次性存入这些本书后共有的数量
 cout<<"您想还书,请输入还书的数量"<<endl;
 cin>>number_in;
 price=s_p*number_in;
 sum=sum+number_in;
 cout<<"您要归还  "<<bookname<<" 》书"<<number_in<<"本(其中,押金"<<s_p<<"元/本) "<<endl<<"我们需要返还给您"<<price<<" "<<endl<<"书库还剩下"<<"该书"<<sum<<""<<endl;
 return (sum);
}
/
Book p[1000];
void inlibrary()
  {
   cout<<"现在您要进行图书入库操作,请输入本次入库书籍的种类数"<<endl;
   int sort_add;
   cin>>sort_add;
   cout<<"然后,请依次输入 "<<endl<<"书名  本次入库数量 单本借书押金"<<endl;
   int i;
   for(i=1;i<=sort_add;i++) //sort种书的对象初始化,并且为各种书进行编号
   {
    cin>>n[i-1]>>a[i-1]>>b[i-1];
    p[sort+i-1].Bookchange(n[i-1],a[i-1],b[i-1]); //通过函数bookchange来对p[i]进行初始化,避免了对构造函数的显式调用
    cout<<"请记住,该书的编号为"<<sort+i-1<<"下次借还时请直接输入书的编号 "<<endl;
   }
   sort=sort+sort_add;
  }
void library()
{
 cout<<setfill('-');
 cout<<"/"<<endl;
 cout<<"///-------编号-------书名-----------------/// "<<endl;
 for(int i=0;i<sort;i++)
  {
   cout<<"///"<<setw(10)<<right<<i<<"---------"<<left<<setw(20)<<p[i].bookname<<"///"<<endl;
  }
 cout<<"/////"<<endl;
}

void main()
{
 cout<<"#######敖#############鸿#############制#############作############Elf#########"<<endl;
        cout<<" ########图书管理程序-完美控制台.本程序提供了以下三种功能功能############"<<endl;
 cout<<"####永##########远###########的############精############灵##########Elf######"<<endl;
 cout<<"一、图书反复入库操作"<<endl<<"二、反复借书"<<endl<<"三、反复还书"<<endl;
/
 cout<<"现在书库还没有书呢,请先进行图书入库操作(库存上限1000种)"<<endl;
 char jud1='n';
 while(jud1=='n')
 {
  int book_no;
  char jud2;
  loop:cout<<"借书--b,存书--s,图书入库--r"<<endl;
  cin>>jud2;
  if(jud2=='r')
    inlibrary();
  else if(jud2=='s')
  {
   library();
   cout<<"您还哪种书?请输入该书的编号"<<endl;
   cin>>book_no;
   p[book_no].restore();
  }
  else if (jud2=='b')
  {
   library();
   cout<<"您借哪种书?请输入该书的编号"<<endl;
   cin>>book_no;
   p[book_no].borrow();
   }
  else goto loop;
  cout<<"请问你的操作完了吗?y/n?"<<endl;
  cin>>jud1;
 }
 int j=0;
 cout<<"********************************************************"<<endl;
 cout<<"***------------书名-------还剩(本)-----------------***"<<endl;
 for(j;j<sort;j++)
  p[j].disp();
 cout<<"********************************************************"<<endl;
 char xx;
 cout<<"输入任意字符按回车退出"<<endl;
 cin>>xx;
}

一次实验报告,被做成了课程设计,做了一个周,我赔死了!

下面是调试:

一、图书入库

二、借书

三、借书超支、再次入库

四、借书,退还空间

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值