Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5. typedef enum {SELECT, RESELECT, INSERT, UPDATE, DELETE, PRINT} CommandType;
  6. typedef enum {author, title, publisher, genre, theme} Field;
  7. class Query{
  8.     private:
  9.         CommandType command_;
  10.         vector<Condition>* condition_:
  11.         vector<Field>* fields_; //for print
  12.     public:
  13.         Query(const string &qu); //if command != print -> fields = NULL
  14. };
  15.  
  16. class Condition{
  17.     private:
  18.         Field field;
  19.         string relation_;
  20.         string comment_; //value-?
  21.     public:
  22.         Condition(const string &str);
  23. };
  24.  
  25. class DataBase{
  26.     private:
  27.         Library *library_;
  28.     public:
  29.         DataBase(const string &filename);
  30.         process(Session user)
  31.         bool db_select(Session *user, Query *query);
  32.         bool db_reselect(Session *user, Query *query);
  33.         bool db_insert(Session *user, Query *query);
  34.         bool db_update(Session *user, Query *query);
  35.         bool db_delete(Session *user, Query *query);
  36.         bool db_print(Session *user, Query *query);
  37. };
  38.  
  39. class Session{
  40.     private:
  41.         string query_;
  42.         Library* result;
  43.     public:
  44.         Session();
  45. }
  46.  
  47. class Book {
  48.         private:
  49.                 char author_[64];
  50.                 char title_[124];
  51.                 char publisher_[64];
  52.                 int class_1;
  53.                 int class_2;
  54.                 bool presence_;
  55.         public:
  56.                 Book(FILE *file);
  57.                 bool compare(const Book &book);
  58.  
  59.  
  60.  
  61. class Library {
  62.         private:
  63.                 vector<Book*> library_;
  64.         public:
  65.                 Library() {}
  66.                 Library(FILE* fin);
  67.                 void add_book(const Book *book)
  68.                 {
  69.                         library_.push_back(book);
  70.                         library_.sort(0, library_.size() - 1);
  71.                 }
  72.                 void sort(Field field, int first, int last)
  73.                 {
  74.                         int i = first, j = last;
  75.                         Book *tmp, *mid = (library_[(i + j) / 2])->field;
  76.                         if(!(library_.emty()))
  77.                         {
  78.                                 while(i <= j)
  79.                                 {
  80.                                         while((library_[i])->field < mid)
  81.                                                 i++;
  82.                                         while((library_[j])->field > mid)
  83.                                                 j--;
  84.                                         if(i < j)
  85.                                         {
  86.                                                 tmp = library_[i];
  87.                                                 library_[i] = library_[j];
  88.                                                 library_[j] = tmp;
  89.                                                 i++;
  90.                                                 j--;
  91.                                         }
  92.                                 }
  93.                                 if(first < j)
  94.                                         library_.sort(field, first, j);
  95.                                 if(last > i)
  96.                                         library_.sort(field, i, last);
  97.                         }
  98.                 }
  99.                 bool empty_library();
  100.                 void del_book();
  101.                 void change(Field field, string value);
  102.                
  103. };
  104.  
  105.  
  106.  
  107.  
  108.  
  109. class DB_Exception {
  110.     private:
  111.         int code_;
  112.         std::string messege_;
  113.     public:
  114.         DB_Exception(int c, std::string c)
  115.         {
  116.             code_ = c;
  117.             messege_ = s;
  118.         }
  119. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement