Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- class Books {
- public:
- string m_name;
- string m_author;
- string m_type;
- Books(string name, string author, string type) {
- m_name = name;
- m_author = author;
- m_type = type;
- }
- };
- class Library {
- public:
- vector<Books*>box;
- ~Library() {
- box.clear();
- }
- };
- void printswich(Library library) {
- int tech = 0;
- int litr = 0;
- for (int i = 0; i < library.box.size(); i++) {
- switch(int(library.box[i]->m_type[0])) {
- case int('T'):
- tech++;
- break;
- case int('L'):
- litr++;
- break;
- }
- }
- cout << "Количество тех. книг = " << tech << endl;
- cout << "Количество художественных книг = " << litr << endl;
- }
- void print(Library library){
- int tech = 0;
- int litr = 0;
- for (int i = 0; i < library.box.size(); i++) {
- if (library.box[i]->m_type == "Tech")
- tech++;
- else
- litr++;
- }
- cout << "Количество тех. книг = " << tech << endl;
- cout << "Количество художественных книг = " << litr<< endl << endl;
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- Library library;
- string author, name, type;
- int n;
- cout << "Введите количество книг: ";
- cin >> n;
- for (int i = 0; i < n; i++) {
- cout << "Введите название, автора и жанр книги";
- cout << "(Жанр: Tech or Litr)";
- cin >> name >> author >> type;
- Books *a = new Books(name, author, type);
- library.box.push_back(a);
- }
- system("cls");
- print(library);
- printswich(library);
- /*
- Books a("Гоголь", "Мёртвые души", "Художественная");
- library.box.push_back(&a);
- Books b("Григорьянс", "Тех. процессы лазерной обработки", "Техническая");
- library.box.push_back(&b);
- Books c("Антонов", "Фрезерная обработка", "Техническая");
- library.box.push_back(&c);
- Books b("Достоевский", "Преступление и наказание", "Художественная");
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement