Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Library {
- string book_name;
- string author_name;
- string author_lastname;
- string genre;
- int year;
- int price;
- int id;
- };
- bool true_cond(Library &lib) {
- return true;
- }
- bool genre_cond(Library &lib) {
- return lib.genre == "roman";
- }
- bool price_cond(Library &lib) {
- return lib.price < 300;
- }
- char* get_book_name(Library &lib) {
- return (char *) lib.book_name.c_str();
- }
- char* get_author_lastname(Library &lib) {
- return (char *) lib.author_lastname.c_str();
- }
- void print(int count, string title, Library *lib,
- bool (*condition)(Library &lib), char* (*get)(Library &lib)) {
- cout << title << endl;
- for (int i = 0; i < count; i++) {
- if (condition(lib[i])) {
- cout << get(lib[i]) << endl;
- }
- }
- }
- int main() {
- int const COUNT = 5;
- Library *lib = new Library[COUNT];
- for (int i = 0; i < COUNT; i++) {
- cout << "Zadej nazev knihy, prijmeni autora, jmeno autora, zanr knihy, rok vydani, cenu a id:" << endl;
- cin >> lib[i].book_name;
- cin >> lib[i].author_lastname;
- cin >> lib[i].author_name;
- cin >> lib[i].genre;
- cin >> lib[i].year;
- cin >> lib[i].price;
- cin >> lib[i].id;
- }
- print(COUNT, "Romany jsou:", lib, genre_cond, get_book_name);
- cout << endl;
- print(COUNT, "Knihy s cenou mensi nez 300,- Kc jsou:", lib, price_cond, get_book_name);
- cout << endl;
- print(COUNT, "Prijmeni vsech autoru jsou:", lib, true_cond, get_author_lastname);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement