![]() |
#2
zaq20082011-01-18 23:53
![]() #include "book.h" #include <vector> #include <iostream> #include <windows.h> #include <string> using std::cout; using std::endl; using std::string; Book::Book(string title,string category,string press,string responsible,string isbn,string seriesname,string keywords,int inventory,int intended): Title(title),Category(category),Press(press),Responsible(responsible),ISBN(isbn),SeriesName(seriesname),Keywords(keywords),Inventory(inventory),Intended(intended){} bool Book::Compare_isbn(const string& isbn) const { if(isbn==ISBN) return true; return false; } bool Book::Compare_title(const string& title)const{ if(title==Title) return true; return false; } std::vector<Book>::iterator book_find_by_title(std::vector<Book> &x,string y){ for(std::vector<Book>::iterator iter=x.begin();iter!=x.end();++iter) if(iter->Compare_title(y)) return iter; return x.end(); } std::vector<Book>::iterator book_find_by_isbn(std::vector<Book> &x,string y){ for(std::vector<Book>::iterator iter=x.begin();iter!=x.end();++iter) if(iter->Compare_isbn(y)) return iter; return x.end(); } void output_book(std::vector<Book>::iterator &a){ system("cls"); cout<< "\n\n\n\t\t书 名:"<<a->Title<<"\n" <<"\t\t分 类:"<<a->Category<<"\n" <<"\t\t出版社:"<<a->Press<<"\n" <<"\t\t责任者:"<<a->Responsible<<"\n" <<"\t\t ISBN :"<<a->ISBN<<"\n" <<"\t\t丛书名:"<<a->SeriesName<<"\n" <<"\t\t主题词:"<<a->Keywords<<"\n" <<"\t\t库 存:"<<a->Inventory<<endl; } istream& operator>>(istream& os,Book &a){ os>>a.Title>>a.Category>>a.Press>>a.Responsible>>a.ISBN>>a.SeriesName>>a.Keywords>>a.Inventory>>a.Intended; return os; } ostream& operator<<(ostream& os,std::vector<Book>::iterator &a){ os<<a->Title<<" "<<a->Category<<" "<<a->Press<<" "<<a->Responsible<<" "<<a->ISBN<<" "<<a->SeriesName<<" "<<a->Keywords<<" "<<a->Inventory<<" "<<a->Intended; return os; } void Book::edit_Title(string title){ Title=title; } void Book::edit_Category(string category){ Category=category; } void Book::edit_Press(string press){ Press=press; } void Book::edit_Responsible(string responsible){ Responsible=responsible; } void Book::edit_ISBN(string isbn){ ISBN=isbn; } void Book::edit_SeriesName(string seriesname){ SeriesName=seriesname; } void Book::edit_Keywords(string keyword){ Keywords=keyword; } void Book::edit_Inventory(int inventory){ Inventory=inventory; } string Book::get_Title(){ return Title; } string Book::get_Category(){ return Category; } string Book::get_Press(){ return Press; } string Book::get_Responsible(){ return Responsible; } string Book::get_ISBN(){ return ISBN; } string Book::get_SeriesName(){ return SeriesName; } string Book::get_Keywords(){ return Keywords; } int Book::get_Inventory(){ return Inventory; } int Book::get_Intended(){ return Intended; } void Book::add_Intended(){ ++Intended; } void Book::less_Intended(){ --Intended; } void Book::add_Inventory(){ ++Inventory; } void Book::less_Inventory(){ --Inventory; } |

#ifndef BOOK_H
#define BOOK_H
#include <string>
#include <iostream>
#include <vector>
using std::ostream;
using std::istream;
using std::string;
class Book{ //书类
public:
friend void output_book(std::vector<Book>::iterator &a);
friend ostream& operator<<(ostream& os,std::vector<Book>::iterator &a);
Book():Inventory(0),Intended(0){};
Book(string title,string category,string press,string responsible,string isbn,string seriesname,string keywords,int inventory,int intended=0);
bool Compare_title(const string& isbn)const;
bool Compare_isbn(const string& title)const;
friend istream& operator>>(istream& os,Book &a);
void edit_Title(string title);
void edit_Category(string category);
void edit_Press(string press);
void edit_Responsible(string responsible);
void edit_ISBN(string isbn);
void edit_SeriesName(string seriesname);
void edit_Keywords(string keyword);
void edit_Inventory(int inventory);
string get_Title();
string get_Category();
string get_Press();
string get_Responsible();
string get_ISBN();
string get_SeriesName();
string get_Keywords();
int get_Inventory();
int get_Intended();
void add_Intended();
void less_Intended();
void add_Inventory();
void less_Inventory();
private:
string Title; //题名
string Category; //分类
string Press; //出版社
string Responsible; //责任者
string ISBN; //ISBN
string SeriesName; //丛书名
string Keywords; //主题词
int Inventory; //库存
int Intended; //预定量
};
#endif
代码写的有点凌乱 大家将就着看吧。。#define BOOK_H
#include <string>
#include <iostream>
#include <vector>
using std::ostream;
using std::istream;
using std::string;
class Book{ //书类
public:
friend void output_book(std::vector<Book>::iterator &a);
friend ostream& operator<<(ostream& os,std::vector<Book>::iterator &a);
Book():Inventory(0),Intended(0){};
Book(string title,string category,string press,string responsible,string isbn,string seriesname,string keywords,int inventory,int intended=0);
bool Compare_title(const string& isbn)const;
bool Compare_isbn(const string& title)const;
friend istream& operator>>(istream& os,Book &a);
void edit_Title(string title);
void edit_Category(string category);
void edit_Press(string press);
void edit_Responsible(string responsible);
void edit_ISBN(string isbn);
void edit_SeriesName(string seriesname);
void edit_Keywords(string keyword);
void edit_Inventory(int inventory);
string get_Title();
string get_Category();
string get_Press();
string get_Responsible();
string get_ISBN();
string get_SeriesName();
string get_Keywords();
int get_Inventory();
int get_Intended();
void add_Intended();
void less_Intended();
void add_Inventory();
void less_Inventory();
private:
string Title; //题名
string Category; //分类
string Press; //出版社
string Responsible; //责任者
string ISBN; //ISBN
string SeriesName; //丛书名
string Keywords; //主题词
int Inventory; //库存
int Intended; //预定量
};
#endif
希望大家对这个程序提些意见,好下次改进。
[ 本帖最后由 zaq2008 于 2011-1-18 23:57 编辑 ]