问题及代码:
/*
*Copyright(c)2014,烟台大学计算学院
*All rights reserved.
*文件名称:test.cpp
*作者:陈银丽
*完成日期:2015年3月18日
*版本号:v1.0
*
*问题描述:编写一个book类,包含name(书名)、writer(作者)、
*输入描述:
*程序输出:
*/
#include <iostream>
#include <string>
using namespace std;
class Book
{
public:
void setBook(string,string,string,int,int,int);
void borrow();
void restore();
void print();
void set_NO(int);
int get_NO();
private:
string name;
string writer;
string public_name;
int price;
int number;
int NO;
};
void Book::setBook(string n,string w,string pn,int p,int num,int N)
{
name=n;
writer=w;
public_name=pn;
price=p;
number=num;
NO=N;
}
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;
}
void Book::borrow()
{
number--;
}
void Book::restore()
{
number++;
}
void Book::set_NO(int n)
{
NO=n;
}
int Book::get_NO()
{
return NO;
}
int main( )
{
Book book;
book.setBook("The Island","Victoria Hislop","南海出版公司",28,100,201501);
book.print();
book.borrow();
book.restore();
book.get_NO();
book.set_NO(201501);
book.print();
}
运行结果:知识点总结:熟练
学习心得:准备补考。下周一好运。