#include <iostream>
#include<string>
using namespace std;
class bookscard
{
public:
bookscard(string a ,string b) //建立创建借书用户构造函数
{
name = a;
id = b;
};
void borrowbook(int n) //借书函数
{
books = n;
sum -= n;
};
static void set() //创建静态函数
{
cout << "图书总数:" << sum<<endl;
};
void returnbook() //还书函数
{
sum += books;
books = 0;
};
void read()
{
cout << "姓名:" << name << endl;
cout << "id:" << id << endl;
cout << "借书数目:" << books << endl;
cout << "书库数:" << sum << endl;
};
private:
static int sum;
string name;
string id;
int books=0;
};
int bookscard::sum = 100;
int main()
{
bookscard obj1("tao", "1234" );
bookscard obj2("long", "9697" );
obj1.borrowbook(2);
obj1.read();
obj1.returnbook();
obj2.read();
bookscard::set();
return 0;
}
静态成员static的应用
最新推荐文章于 2023-01-09 22:32:00 发布