#include <iostream>
#include <cstdio>
using namespace std;
class Book
{
public:
void setBook();
void borrow();
void restore();
void print();
void set_NO(int);
int get_NO();
private:
char name[81];
char writer[30];
char public_name[30];
float price;
int number;
int NO;
};
void Book::setBook()
{
cout<<"please input the book'sinformation:"<<endl;
cout<<"name:";
gets(name);
cout<<"writer:";
cin>>writer;
cout<<"public_name:";
cin>>public_name;
cout<<"price:";
cin>>price;
cout<<"number:";
cin>>number;
cout<<"NO:";
cin>>NO;
cout<<endl;
}
void Book::set_NO(int n)
{
NO=n;
}
int Book::get_NO()
{
return NO;
}
void Book::borrow()
{
number--;
}
void Book::restore()
{
number++;
}
void Book::print()
{
cout<<"name:"<<name<<endl;
cout<<"writer:"<<writer<<endl;
cout<<"public_name:"<<public_name<<endl;
cout<<"price:"<<price<<endl;
cout<<"number:"<<number<<endl;
cout<<"NO:"<<NO<<endl<<endl;;
}
int main( )
{
Book b1;
b1.setBook();
b1.print();
b1.borrow();
b1.print();
b1.restore();
b1.print();
b1.set_NO(5445);
b1.print();
cout<<"New book_NO is "<<b1.get_NO()<<endl;
return 0;
}
运行结果:
学习总结:
表示题目真心没看太懂,only 借鉴。