#include<iostream>
#include<string.h>
using namespace std;
class Book
{
string bookname;
double price;
int number;
public:
void display();
void borrow();
void restore();
void setBook(string, double, int);
};
void Book::display()
{
cout << "存书情况:" << endl
<< "bookname:" << bookname << endl
<< "price:" << price << endl
<< "number:" << number << endl;
}
void Book::borrow()
{
system("cls");
if (number == 0)
{
cout << "已经没有存书,退出" << endl;
exit(0);
}
else
{
number = number - 1;
cout << "借一次书,现在书本存量为:" << number << endl;
}
}
void Book::restore()
{
system("cls");
number = number + 1;
cout << "还一次书,现在书本存量为:" << number << endl;
}
void Book::setBook(string name, double pri, int num)
{
bookname = name;
price = pri;
number = num;
}
int main()
{
Book a;
a.setBook("c++程序设计", 10.00, 10);
int b, c;
cout << "********************" << endl;
cout << "----图书管理系统----" << endl;
cout << "---1.进入---" << endl;
cout << "---2.退出---" << endl;
cout << "---3.查看存书状况---" << endl;
cout << "********************" << endl;
cout << "请输入你的选择:" << endl;
cin >> b;
if (b == 1)
{
system("cls");
cout << "---1.借书---" << endl;
cout << "---2.还书---" << endl;
cout << "---3.退出---" << endl;
cout << "请选择功能:" << endl;
cin >> c;
switch (c)
{
case 1:a.borrow(), a.display();
break;
case 2:a.restore(), a.display();
break;
case 3:exit(0);
}
}
else if (b == 2)
{
exit(0);
}
else if (b == 3)
{
system("cls");
a.display();
}
}