Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. struct Library {
  7.     string book_name;
  8.     string author_name;
  9.     string author_lastname;
  10.     string genre;
  11.     int year;
  12.     int price;
  13.     int id;
  14. };
  15.  
  16. bool true_cond(Library &lib) {
  17.     return true;
  18. }
  19.  
  20. bool genre_cond(Library &lib) {
  21.     return lib.genre == "roman";
  22. }
  23.  
  24. bool price_cond(Library &lib) {
  25.     return lib.price < 300;
  26. }
  27.  
  28. char* get_book_name(Library &lib) {
  29.     return (char *) lib.book_name.c_str();
  30. }
  31.  
  32. char* get_author_lastname(Library &lib) {
  33.     return (char *) lib.author_lastname.c_str();
  34. }
  35.  
  36. void print(int count, string title, Library *lib,
  37.            bool (*condition)(Library &lib), char* (*get)(Library &lib)) {
  38.     cout << title << endl;
  39.     for (int i = 0; i < count; i++) {
  40.         if (condition(lib[i])) {
  41.             cout << get(lib[i]) << endl;
  42.         }
  43.     }
  44. }
  45.  
  46. int main() {
  47.  
  48.     int const COUNT = 5;
  49.     Library *lib = new Library[COUNT];
  50.  
  51.     for (int i = 0; i < COUNT; i++) {
  52.         cout << "Zadej nazev knihy, prijmeni autora, jmeno autora, zanr knihy, rok vydani, cenu a id:" << endl;
  53.         cin >> lib[i].book_name;
  54.         cin >> lib[i].author_lastname;
  55.         cin >> lib[i].author_name;
  56.         cin >> lib[i].genre;
  57.         cin >> lib[i].year;
  58.         cin >> lib[i].price;
  59.         cin >> lib[i].id;
  60.     }
  61.  
  62.     print(COUNT, "Romany jsou:", lib, genre_cond, get_book_name);
  63.     cout << endl;
  64.  
  65.     print(COUNT, "Knihy s cenou mensi nez 300,- Kc jsou:", lib, price_cond, get_book_name);
  66.     cout << endl;
  67.  
  68.     print(COUNT, "Prijmeni vsech autoru jsou:", lib, true_cond, get_author_lastname);
  69.  
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement