第二周项目4图书管理

/*Copyright(c)2014,烟台大学计算机学院    
 *Allrights reserved.    
 *文件名称:MADE2.cpp    
 *作    者:张生栋    
 *完成日期:2015年3月21日    
 *问题描述:编写一个Book类,包含name(书名)、writer(著者)
   、public_name(出版社)、price(价格)、number(数量)、
 NO(书号)等数据成员。定义成员函数setBook,用来为书籍的
 数据成员赋值,定义成员函数borrow和restore,分别办理借出
 和还回(借、还书时,暂时只完成数量的增1减1,这里的书仍
 是一种书的概念,随着课程进展,我们继续做真正的图书管理
 系统,每本书都能追踪到是谁何时借了,何时还了)业务,定
 义成员函数print用于输出—有关书的信息,定义set_NO与get_NO来实现修改类对
 象的书号与获得类对象的书号。自己写main函数,用来测试你编写的类。 
 *输入描述:name(书名)、writer(著者)、public_name(出版社)、price(价格)、number(数量)、NO(书号)等数据。 
 *输出描述:name(书名)、writer(著者)、public_name(出版社)、price(价格)、number(数量)、NO(书号)等数据。
 *版 本 号:v1.0    
 */      
11.  

#include <iostream>
using namespace std;
class Book
{
private:
    string name;
    string writer;
    string public_name;
    double price;
    int number;
    int no;
public:
    void set_book( );
    void borrow();
    void restore();
    void print( );
    void set_NO(int n);
    int get_NO( );
};
void Book::set_book()
{
    string na,w,pn;
    double p;
    int nu,n,i,count=0;
    cout<<"图书名:";
    cin>>na;
    name=na;
    cout<<"作者:";
    cin>>w;
    writer=w;
    cout<<"出版社:";
    cin>>pn;
    public_name=pn;
    cout<<"价格:";
    cin>>p;
    price=p;
    cout<<"数量:";
    cin>>nu;
    cout<<"图书编号:";
    cin>>n;
    no=n;
}
void Book::borrow()
{
    cout<<"请输入要借阅的图书名:";
    cin>>name;
    number--;

}
void Book::restore()
{
    cout<<"请输入要归还的图书名:";
    cin>>name;
    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;
}
void Book::set_NO(int n)
{
    no=n;
}
int Book::get_NO( )
{
    return no;
}
int main( )
{
    int n;
    Book book;
    book.set_book();
    book.print();
    book.borrow();
    book.print();
    book.restore();
    book.print();
   cout<<"请输入要修改的图书编号:";
    cin>>n;
    book.set_NO(n);
    book.print();
    cout<<"修改后的图书编号为:" <<book.get_NO()<<endl;
    return 0;
}
运行结果:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值