/*
*Copyright(c)2014,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作者:曾晓
*完成日期:2015年 3月 18日
*版本号:v1.0
*/
#include <iostream>
#include <cstdio>
using namespace std;
class Book
{
private:
char name[81];
char writer[40];
char public_name[40];
double price;
int number;
int NO;
public:
void setBook();
void borrow();
void restore();
void setNO(int);
int getNO();
void print();
};
void Book::setBook()
{
cout<<"请输入书籍信息:"<<endl;
cout<<"name:"<<endl;
gets(name);
cout<<"writer:"<<endl;
cin>>writer;
cout<<"public_name:"<<endl;
cin>>public_name;
cout<<"price:"<<endl;
cin>>price;
cout<<"number:"<<endl;
cin>>number;
cout<<"NO:"<<endl;
cin>>NO;
cout<<endl;
}
void Book::setNO(int n)
{
NO=n;
}
int Book::getNO()
{
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 b;
b.setBook();
b.print();
b.borrow();
b.print();
b.restore();
b.print();
b.setNO(1111);
b.print();
cout<<"新的编号是:"<<b.getNO()<<endl;
return 0;
}
运行结果:
果然还是早上头脑比较清醒 心好累><