Skip to content

Instantly share code, notes, and snippets.

@bilinin
Last active February 28, 2017 14:44
Show Gist options
  • Save bilinin/b2112d396be0c42eeca5456e0d50804d to your computer and use it in GitHub Desktop.
Save bilinin/b2112d396be0c42eeca5456e0d50804d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
class Book{
public:
// Конструктор
Book(string Autor, string Name, string Publishing, int Year, int Sheets){
set_autor(Autor);
set_name(Name);
set_publishing(Publishing);
set_year(Year);
set_sheets(Sheets);
}
// Сеттеры
void set_autor(string autor){
Autor = autor;
}
void set_name(string name){
Name = name;
}
void set_publishing(string publishing){
Publishing = publishing;
}
void set_year(int year){
Year = year;
}
void set_sheets(int sheets){
Sheets = sheets ;
}
// Геттеры
string get_autor(){
return Autor;
}
string get_name(){
return Name;
}
string get_publishing(){
return Publishing;
}
int get_year(){
return Year;
}
int get_sheets(){
return Sheets;
}
// other
void print_all_data(){
cout << Autor << " " << Name << " " << Publishing << " "
<< " " << Year<< " "<< Sheets << endl;
}
private:
// Автор, Название, Издательство, Год, Количество страниц.
string Autor,
Name,
Publishing;
int Year,
Sheets;
};
void show_for_autor(vector <Book> Books, string autor){
cout << "Books by " << autor << endl;
int size = Books.size();
for (int i = 0;i<size; i++){
if(Books[i].get_autor() == autor){
Books[i].print_all_data();
}
}
}
void show_for_publisher(vector <Book> Books, string publisher){
cout << "\n\nBooks by " << publisher << endl;
int size = Books.size();
for (int i = 0;i<size; i++){
if(Books[i].get_publishing() == publisher){
Books[i].print_all_data();
}
}
}
void show_year_more(vector <Book> Books, int year){
cout << "\n\nBooks newer " << year << endl;
int size = Books.size();
for (int i = 0;i<size; i++){
if(Books[i].get_year() > year){
Books[i].print_all_data();
}
}
}
int main() {
vector <Book> Books;
Books.push_back(Book("Bulgakov", "Master i margarita", "Moskow", 1930, 200 ));
Books.push_back(Book("Tolstoy", "Voina i mir", "Moskow", 1870, 1300));
Books.push_back(Book("Dostoevskiy", "Prestuplenie i nakazanie", "Moskow",1866 , 250));
Books.push_back(Book("Dostoevskiy", "Bratia Karamazovy", "Moskow", 1880, 170));
Books.push_back(Book("Tolstoy", "Anna Karenina", "Leningrad", 1873, 300));
show_for_autor(Books, "Bulgakov");
show_for_publisher(Books, "Moskow");
show_year_more(Books, 1900);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment