@serhey797

Как сделать фильтр?

Нужно сделать фильтр который фильтрует за жанром, номером, месяцем, годом издания, издательством.Помогите сделать.
#include <iostream>
#include <fstream>
#include <math.h>
#include <string>

using namespace std;

struct BookCathalog {
	string author;
	string name;
	string date;
	string publishing;
	string size;
	string genre;

};

int globalSize = 0;
int CinNewCathalog(struct BookCathalog* cath) {
	int BookSize;
	cout << "Количество новых позиций > ";
	cin >> BookSize;
	for (int i = 0; i < BookSize; i++) {

		cout << "Автор: ";
		cin >> cath[i].author;
		cout << "Название: ";
		cin >> cath[i].name;
		cout << "Дата: ";
		cin >> cath[i].date;
		cout << "Издательство: ";
		cin >> cath[i].publishing;
		cout << "Жанр: ";
		cin >> cath[i].genre;
		cout << "Кол-во стр:";
		cin >> cath[i].size;

		cout << " ---" << endl;
	}
	::globalSize = BookSize;
	return BookSize;
}

void FillCathalog(BookCathalog* cath) {
	cath[0].author = "Richard Lymon";
	cath[0].name = "Moon - park";
	cath[0].date = "1989 year";
	cath[0].publishing = "Funland";
	cath[0].genre = "horrors";
	cath[0].size = "638 country";

	cath[1].author = "Bram Stoker";
	cath[1].name = "Dracula";
	cath[1].date = "1897 year";
	cath[1].publishing = "Archibald Constable and Company";
	cath[1].genre = "horrors";
	cath[1].size = "448 country";

	cath[2].author = "Roger Zelazny";
	cath[2].name = "Prince of Light";
	cath[2].date = "1967 year";
	cath[2].publishing = "Doubleday";
	cath[2].genre = "fantastic";
	cath[2].size = "530 country";

	cath[3].author = "H.G. Wells";
	cath[3].name = "War of the Worlds";
	cath[3].date = "1987 year";
	cath[3].publishing = "Heinemann";
	cath[3].genre = "fantastic";
	cath[3].size = "480 country";

	cath[4].author = "Victor Astafiev";
	cath[4].name = "Cursed and killed";
	cath[4].date = "1992 year";
	cath[4].publishing = "UK";
	cath[4].genre = "military";
	cath[4].size = "541 country";


	::globalSize = 4;
	cout << "GlobalSize = " << ::globalSize << endl;
}

void CoutCathalog(struct BookCathalog* cath, int genre) {
	for (int i = 0; i < genre; i++) {
		cout << "-" << endl;
		cout << "Автор: " << cath[i].author << endl;
		cout << "Название: " << cath[i].name << endl;
		cout << "Дата: " << cath[i].date << endl;
		cout << "Издательство: " << cath[i].publishing << endl;
		cout << "Жанр: " << cath[i].genre << endl;
		cout << "Кол-во стр: " << cath[i].size << endl;
	}
}

void SearchInCathalog(struct BookCathalog* cath, int genre) {
	setlocale(LC_ALL, "Russian");
	bool found = false;
	string genreF;
	string author;

	cout << "Жанр:\n ";
	cin >> genreF;
	cout << "Автор:\n ";
	cin >> author;

	for (int i = 0; i < genre; i++) {

		if (genreF == cath[i].genre && author == cath[i].author) {
			cout << "Автор: " << cath[i].author << endl;
			cout << "Название: " << cath[i].name << endl;
			cout << "Дата: " << cath[i].date << endl;
			cout << "Издательство: " << cath[i].publishing << endl;
			cout << "Жанр: " << cath[i].genre << endl;
			cout << "Кол-во стр: " << cath[i].size << endl;
			found = true;
		}
	}
	if (!found) {
		cout << "\n Ничего не найдено :/" << endl;
	}
}

int main() {
	setlocale(LC_ALL, "Russian");
	int cathSize;
	int v, v2;
	cout << "1.Создать новый\n2.Заполнить по стандарту\n";
	cin >> v;
	cout << "\n" << endl;

	BookCathalog* buildingSuppliesList = new BookCathalog[10];
	switch (v) {
	case 1:
		cathSize = CinNewCathalog(buildingSuppliesList);
		CoutCathalog(buildingSuppliesList, cathSize);
		break;
	case 2:
		FillCathalog(buildingSuppliesList);
		CoutCathalog(buildingSuppliesList, 5);
		break;
	default:
		break;
	}

	cout << "\n\n1.Поиск\n2.Выход\n";
	cin >> v2;

	switch (v2) {
	case 1:
		SearchInCathalog(buildingSuppliesList, ::globalSize);
		break;
	default:
		break;
	}

}
  • Вопрос задан
  • 73 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы