項目二--圖書館的書,項目--圖書館
/* *Copyright (c) 2014, 煙台大學電腦學院 * All right reserved. * 檔案名稱:test.cpp * 作者:趙嵩 * 完成時間:2014年3月15號 * 版本號碼:v1.0 */ #include <iostream>#include <string>using namespace std;class Book{private: string name; string writer; string public_name; double price; int number; int NO;public: void setBook(string n,string w,string pu,double pr,int nu,int N); void borrow(); void restore(); void set_No(int); int get_No(); void print();};int main(){ Book book; book.setBook("悲慘世界","雨果","上海外語教育出版社",45,23,1234); book.print(); book.borrow(); book.print(); book.restore(); book.print(); book.set_No(4321); book.print(); return 0;}void Book::setBook(string n,string w,string pu,double pr,int nu,int N){ name=n; writer=w; public_name=pu; price=pr; number=nu; NO=N;}void Book::borrow(){ number--;}void Book::restore(){ number++;}void Book::set_No(int n1){ NO=n1;}int Book::get_No(){ return NO;}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;}
運行結果: