void fill(Catalogue& catalogue)
{
    catalogue.add("Life of Pi", "Martel", "Yann");
    catalogue.add("The Call of the Wild", "London", "Jack");
    catalogue.add("To Kill a Mockingbird", "Lee", "Harper");
    catalogue.add("Little Women", "Alcott", "Louisa");
    catalogue.add("The Adventures of Sherlock Holmes", "Doyle", "Conan");
    catalogue.add("And Then There Were None", "Christie", "Agatha");
    catalogue.add("Carrie", "King", "Stephen");
    catalogue.add("It: A Novel", "King", "Stephen");
    catalogue.add("Frankenstein", "Shelley", "Mary");
    catalogue.add("2001: A Space Odyssey", "Clarke", "Arthur");
    catalogue.add("Ender's Game", "Card", "Orson");
}
 
void test(const Catalogue& catalogue)
{
    Book target1("Life of Pi", "Martel", "Yann");
    search(catalogue, target1);
    Book target2("", "King", "");
    search(catalogue, target2);
    Book target3("1984", "Orwell", "George");
    search(catalogue, target3);
    Book target4("", "", "");
    search(catalogue, target4);
}

Wynik działania programu:


Find {TITLE: 'Life of Pi', LAST: 'Martel', FIRST: 'Yann'}
Matches:
 {TITLE: 'Life of Pi', LAST: 'Martel', FIRST: 'Yann'}

Find {TITLE: '', LAST: 'King', FIRST: ''}
Matches:
 {TITLE: 'Carrie', LAST: 'King', FIRST: 'Stephen'}
 {TITLE: 'It: A Novel', LAST: 'King', FIRST: 'Stephen'}

Find {TITLE: '1984', LAST: 'Orwell', FIRST: 'George'}
No matches.

Find {TITLE: '', LAST: '', FIRST: ''}
Matches:
 {TITLE: 'Life of Pi', LAST: 'Martel', FIRST: 'Yann'}
 {TITLE: 'The Call of the Wild', LAST: 'London', FIRST: 'Jack'}
 {TITLE: 'To Kill a Mockingbird', LAST: 'Lee', FIRST: 'Harper'}
 {TITLE: 'Little Women', LAST: 'Alcott', FIRST: 'Louisa'}
 {TITLE: 'The Adventures of Sherlock Holmes', LAST: 'Doyle', FIRST: 'Conan'}
 {TITLE: 'And Then There Were None', LAST: 'Christie', FIRST: 'Agatha'}
 {TITLE: 'Carrie', LAST: 'King', FIRST: 'Stephen'}
 {TITLE: 'It: A Novel', LAST: 'King', FIRST: 'Stephen'}
 {TITLE: 'Frankenstein', LAST: 'Shelley', FIRST: 'Mary'}
 {TITLE: '2001: A Space Odyssey', LAST: 'Clarke', FIRST: 'Arthur'}
 {TITLE: 'Ender's Game', LAST: 'Card', FIRST: 'Orson'}

Zadanie Book - Rozwiązanie

Zadanie Book - Ciąg dalszy

Plik main.cpp

#include <iostream>
#include <vector>
#include <string>
#include "Book.h"
#include "Catalogue.h"
#include "Attributes.h"
using namespace std;
 
 
void fill(Catalogue& catalogue)
{
    catalogue.add(new Attributes("Life of Pi", "Martel", "Yann", 2003, Genre::ADVENTURE));
    catalogue.add(new Attributes("The Call of the Wild", "London", "Jack", 1903, Genre::ADVENTURE));
    catalogue.add(new Attributes("To Kill a Mockingbird", "Lee", "Harper", 1960, Genre::CLASSICS));
    catalogue.add(new Attributes("Little Women", "Alcott", "Louisa", 1868, Genre::CLASSICS));
    catalogue.add(new Attributes("The Adventures of Sherlock Holmes", "Doyle", "Conan", 1892, Genre::DETECTIVE));
    catalogue.add(new Attributes("And Then There Were None", "Christie", "Agatha", 1939, Genre::DETECTIVE));
    catalogue.add(new Attributes("Carrie", "King", "Stephen", 1974, Genre::HORROR));
    catalogue.add(new Attributes("It: A Novel", "King", "Stephen", 1986, Genre::HORROR));
    catalogue.add(new Attributes("Frankenstein", "Shelley", "Mary", 1818, Genre::HORROR));
    catalogue.add(new Attributes("2001: A Space Odyssey", "Clarke", "Arthur", 1968, Genre::SCIFI));
    catalogue.add(new Attributes("Ender's Game", "Card", "Orson", 1985, Genre::SCIFI));
}
 
void search(const Catalogue& catalogue, const Attributes &target_attrs)
{
    cout << endl << "Find " << target_attrs << endl;
    vector<Book *> matches = catalogue.find(target_attrs);
    if (matches.size() == 0) cout << "No matches." << endl;
    else
    {
        cout << "Matches:" << endl;
        for (Book *book : matches)
        {
            cout << "  " << *book->get_attributes() << endl;
        }
    }
}
 
void test(const Catalogue& catalogue)
{
    Attributes target_attrs1("Life of Pi", "Martel", "Yann", 2003, Genre::ADVENTURE);
    search(catalogue, target_attrs1);
 
    Attributes target_attrs2("", "King", "", 0, Genre::HORROR);
    search(catalogue, target_attrs2);
 
    Attributes target_attrs3("1984", "Orwell", "George", 0, Genre::CLASSICS);
    search(catalogue, target_attrs3);
 
    Attributes target_attrs4("", "", "", 1960, Genre::ROMANCE);
    search(catalogue, target_attrs4);
 
    Attributes target_attrs5("", "", "", 1960, Genre::UNSPECIFIED);
    search(catalogue, target_attrs5);
 
    Attributes target_attrs6("", "", "", 0, Genre::SCIFI);
    search(catalogue, target_attrs6);
 
    Attributes target_attrs7("", "", "", 0, Genre::UNSPECIFIED);
    search(catalogue, target_attrs7);
}
 
int main()
{
    Catalogue catalogue;
    fill(catalogue);
    test(catalogue);
}

Wynik działania programu:

Find {TITLE: 'Life of Pi', LAST: 'Martel', FIRST: 'Yann', YEAR: 2003, GENRE: adventure}
Matches:
  {TITLE: 'Life of Pi', LAST: 'Martel', FIRST: 'Yann', YEAR: 2003, GENRE: adventure}

Find {TITLE: '', LAST: 'King', FIRST: '', YEAR: 0, GENRE: horror}
Matches:
  {TITLE: 'Carrie', LAST: 'King', FIRST: 'Stephen', YEAR: 1974, GENRE: horror}
  {TITLE: 'It: A Novel', LAST: 'King', FIRST: 'Stephen', YEAR: 1986, GENRE: horror}

Find {TITLE: '1984', LAST: 'Orwell', FIRST: 'George', YEAR: 0, GENRE: classics}
No matches.

Find {TITLE: '', LAST: '', FIRST: '', YEAR: 1960, GENRE: romance}
No matches.

Find {TITLE: '', LAST: '', FIRST: '', YEAR: 1960, GENRE: unspecified}
Matches:
  {TITLE: 'To Kill a Mockingbird', LAST: 'Lee', FIRST: 'Harper', YEAR: 1960, GENRE: classics}

Find {TITLE: '', LAST: '', FIRST: '', YEAR: 0, GENRE: scifi}
Matches:
  {TITLE: '2001: A Space Odyssey', LAST: 'Clarke', FIRST: 'Arthur', YEAR: 1968, GENRE: scifi}
  {TITLE: 'Ender's Game', LAST: 'Card', FIRST: 'Orson', YEAR: 1985, GENRE: scifi}

Find {TITLE: '', LAST: '', FIRST: '', YEAR: 0, GENRE: unspecified}
Matches:
  {TITLE: 'Life of Pi', LAST: 'Martel', FIRST: 'Yann', YEAR: 2003, GENRE: adventure}
  {TITLE: 'The Call of the Wild', LAST: 'London', FIRST: 'Jack', YEAR: 1903, GENRE: adventure}
  {TITLE: 'To Kill a Mockingbird', LAST: 'Lee', FIRST: 'Harper', YEAR: 1960, GENRE: classics}
  {TITLE: 'Little Women', LAST: 'Alcott', FIRST: 'Louisa', YEAR: 1868, GENRE: classics}
  {TITLE: 'The Adventures of Sherlock Holmes', LAST: 'Doyle', FIRST: 'Conan', YEAR: 1892, GENRE: detective}
  {TITLE: 'And Then There Were None', LAST: 'Christie', FIRST: 'Agatha', YEAR: 1939, GENRE: detective}
  {TITLE: 'Carrie', LAST: 'King', FIRST: 'Stephen', YEAR: 1974, GENRE: horror}
  {TITLE: 'It: A Novel', LAST: 'King', FIRST: 'Stephen', YEAR: 1986, GENRE: horror}
  {TITLE: 'Frankenstein', LAST: 'Shelley', FIRST: 'Mary', YEAR: 1818, GENRE: horror}
  {TITLE: '2001: A Space Odyssey', LAST: 'Clarke', FIRST: 'Arthur', YEAR: 1968, GENRE: scifi}
  {TITLE: 'Ender's Game', LAST: 'Card', FIRST: 'Orson', YEAR: 1985, GENRE: scifi}

Zadanie Book - Ciąg dalszy - Rozwiązanie