圖書管理程序-完美控制檯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;
}

一次實驗報告,被做成了課程設計,做了一個周,我賠死了!

下面是調試:

一、圖書入庫

二、借書

三、借書超支、再次入庫

四、借書,退還空間

發佈了18 篇原創文章 · 獲贊 9 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章