C++ 输入N本书,查找并且显示书相关信息

#include 
#include
using namespace std;
class Book {
private:
	char title[20], author[10], publish[30];
	const float price;
public:
	Book();
	void PrintPrice() const;
	void Print();
	friend int Find(Book ob[], int n);
};


int main() {
	int n, i;
	cin >> n;
	Book* b = new Book[n];
	i = Find(b,n);
	if (i != -1) {
		b[i].Print();
	}
	else
		cout << "没有该书" << endl;
	delete[] b;
	return 0;
}

Book::Book():price(23.8f) {
	cin >> title>> author>> publish;	
}
int Find(Book ob[], int n) {
	
	char title[20];
	cin >> title;

	for (int i = 0; i < n; i++)
		if (strcmp(title, ob[i].title) == 0)
			return i;
	return -1;
}
void Book::PrintPrice() const {
	cout << price<

你可能感兴趣的:(算法,数据结构)