Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp: определяет точку входа для консольного приложения.
- //
- #pragma once
- #include "stdafx.h"
- #include <windows.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fstream>
- #include <sys/types.h>
- #include <winsock.h>
- #include <iostream>
- #include <vector>
- using namespace std;
- struct Record
- {
- char journal[64];
- int year, number;
- char author[32];
- char article[128];
- };
- bool records_equal(Record r1, Record r2)
- {
- if (!(strcmp(r1.journal, r2.journal)) && r1.year == r2.year && !(strcmp(r1.author, r2.author)) && !(strcmp(r1.article, r2.article)) && r1.number == r2.number)
- return true;
- return false;
- }
- class Base
- {
- vector<Record> base;
- int count;
- public:
- Base()
- {
- ifstream fin;
- fin.open("base.txt");
- fin >> count;
- for (int i = 0; i < count; i++)
- {
- Record rec;
- fin >> rec.journal;
- fin >> rec.year;
- fin >> rec.number;
- fin >> rec.author;
- fin >> rec.article;
- base.push_back(rec);
- }
- fin.close();
- }
- void add_record(Record rec)
- {
- base.push_back(rec);
- }
- void delete_record(Record rec)
- {
- auto it = base.begin();
- while (!records_equal(*it, rec))
- {
- it++;
- }
- base.erase(it);
- }
- vector<Record> search_articles(char* str = "", int year1 = -1, int year2 = -1, int number1 = -1, int number2 = -1)
- {
- vector<Record> articles;
- int c = 0;
- for (int i = 0; i < count; i++)
- {
- if ((!strcmp(str, base[i].journal) || str == "") && ((base[i].year > year1 && base[i].year < year2) || year2 == -1) && ((base[i].number > number1 && base[i].number < number2) || number2 == -1))
- {
- articles.push_back(base[i]);
- }
- }
- return articles;
- }
- void save_base(char* name)
- {
- ofstream fout;
- fout.open(name);
- fout << count << endl;
- for (int i = 0; i < count; i++)
- {
- fout << base[i].journal << ' ' << base[i].year << ' ' << base[i].number << ' ' << base[i].author << ' ' << base[i].article << endl;
- }
- fout.close();
- }
- /*int code(int c)
- {
- switch (c)
- {
- case 1:
- }
- }*/
- };
- char* generate_journal()
- {
- int count = rand() % 63 + 1;
- char* name = new char[count + 1];
- name[0] = 'A' + rand() % 26;
- for (int i = 1; i < count; i++)
- {
- name[i] = 'a' + rand() % 26;
- }
- name[count] = '\0';
- return name;
- }
- char* generate_author()
- {
- int count = rand() % 31 + 1;
- char* name = new char[count + 1];
- name[0] = 'A' + rand() % 26;
- for (int i = 1; i < count; i++)
- {
- name[i] = 'a' + rand() % 26;
- }
- name[count] = '\0';
- return name;
- }
- char* generate_article()
- {
- int count = rand() % 78 + 50;
- char* name = new char[count + 1];
- name[0] = 'A' + rand() % 26;
- for (int i = 1; i < count; i++)
- {
- name[i] = 'a' + rand() % 26;
- }
- name[count] = '\0';
- return name;
- }
- void generate_base(char* name)
- {
- ofstream fout;
- fout.open(name);
- int count = rand() + 10000;
- fout << count << endl;
- for (int i = 0; i < count; i++)
- {
- fout << generate_journal() << ' ';
- fout << rand() % 66 + 1950 << ' ';
- fout << rand() % 100 << ' ';
- fout << generate_author() << ' ';
- fout << generate_article() << endl;
- }
- fout.close();
- }
- int main()
- {
- Base data_base;
- int socket_number = socket(AF_INET, SOCK_STREAM, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement