</pre><pre name="code" class="cpp">/*
* 文件名称:Ex1-2.cpp
* 作 者:莫洋
* 完成日期:2016 年 3 月 30 日
* 版 本 号:v1.0
* 对任务及求解方法的描述部分:
* 输入描述:无
* 问题描述:类和对象
* 程序输出:略
* 问题分析:略
* 算法设计:略
*/
#include <iostream>
#include <cstring>
using namespace std;
class Book
{
private:
char name[10];
char writer[10];
char publicer[10];
double price;
int number;
int No;
public:
void setbook(char *n,char *w,char *p,double x,int y,int z);
void borrow();
void restore();
void print();
void set_No(int r);
int get_No();
};
void Book::setbook(char *n,char *w,char *p,double x,int y,int z)
{
strcpy(name,n);
strcpy(writer,w);
strcpy(publicer,p);
price=x;
number=y;
No=z;
}
void Book::borrow()
{
number--;
}
void Book::restore()
{
number++;
}
void Book::set_No(int r)
{
No=r;
}
int Book::get_No()
{
return No;
}
void Book::print()
{
cout<<"name:"<<name<<endl;
cout<<"writer:"<<writer<<endl;
cout<<"publicer:"<<publicer<<endl;
cout<<"price:"<<price<<endl;
cout<<"number:"<<number<<endl;
cout<<"No."<<No<<endl;
}
void main()
{
Book b;
b.setbook("longzu","jiangnan","cjchubanshe",32,10,1202);
b.print();
b.borrow();
b.print();
b.restore();
b.print();
b.set_No(1203);
b.print();
b.get_No();
}
运行结果: