Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <string>
- #include <fstream>
- #include <sstream>
- #include <iomanip>
- #include <map>
- #include "Knyga.h"
- using namespace std;
- namespace Knygos {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- /// <summary>
- /// Summary for Form1
- ///
- /// WARNING: If you change the name of this class, you will need to change the
- /// 'Resource File Name' property for the managed resource compiler tool
- /// associated with all .resx files this class depends on. Otherwise,
- /// the designers will not be able to interact properly with localized
- /// resources associated with this form.
- /// </summary>
- public ref class Form1 : public System::Windows::Forms::Form
- {
- public:
- Form1(void)
- {
- InitializeComponent();
- //
- //TODO: Add the constructor code here
- /* LD5S_3. Knygos
- Dviejuose tekstiniuose failuose Knyga1.txt ir Knyga2.txt duotas tekstas sudarytas iš žodžių,
- atskirtų skyrikliais. Skyriklių aibė žinoma ir abejuose failuose yra ta pati. Analizuojant tekstus,
- didžiosios ir mažosios raidės nesvarbios.
- Raskite, spausdinkite faile Analizė.txt ir išveskite ekrane teksto analizės rezultatus:
- ilgiausių žodžių, kuris yra abejuose failuose, sąrašą (ne daugiau nei 10 žodžių) ir jų
- pasikartojimo skaičių kiekviename iš failų; ilgiausių žodžių, kurie yra tik faile Knyga1.txt,
- bet nėra faile Knyga2.txt, sąrašą (ne daugiau nei 10 žodžių) ir jų pasikartojimo skaičių;
- Spausdinkite faile ManoKnyga.txt apjungtą tekstą, sudarytą pagal tokias taisykles:
- kopijuojamas pirmojo failo tekstas tol, kol sutinkamas pirmasis antrojo failo žodis
- arba pasiekiama failo pabaiga; kopijuojamas antrojo failo tekstas tol, kol sutinkamas pirmasis
- nenukopijuotas pirmojo failo žodis arba pasiekiama failo pabaiga; kartojama tol, kol pasiekiama
- abiejų failų pabaiga.*/
- //
- }
- protected:
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- ~Form1()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::TabControl^ tabControl1;
- protected:
- private: System::Windows::Forms::TabPage^ tabPage1;
- private: System::Windows::Forms::TabPage^ tabPage2;
- private: System::Windows::Forms::TabPage^ tabPage3;
- private: System::Windows::Forms::TabPage^ tabPage4;
- private: System::Windows::Forms::MenuStrip^ menuStrip1;
- private: System::Windows::Forms::ToolStripMenuItem^ failasToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ atidarytiPirmąFailąToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ atidarytiAntrąFailąToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ išsaugotiAnalizęToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ išsaugotiKnygąToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ uždarytiToolStripMenuItem;
- private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
- private: System::Windows::Forms::OpenFileDialog^ openFileDialog2;
- private: System::Windows::Forms::SaveFileDialog^ saveFileDialog1;
- private: System::Windows::Forms::SaveFileDialog^ saveFileDialog2;
- private:
- /// <summary>
- /// Required designer variable.
- String^ dfv1;
- String^ dfv2;
- String^ rfv1;
- String^ rfv2;
- Knyga * Kn1;
- Knyga * Kn2;
- ///
- private: System::Windows::Forms::RichTextBox^ richTextBox1;
- private: System::Windows::Forms::RichTextBox^ richTextBox2;
- private: System::Windows::Forms::RichTextBox^ richTextBox3;
- private: System::Windows::Forms::RichTextBox^ richTextBox4;
- private: System::Windows::Forms::ToolStripMenuItem^ funkcijosToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ analizėToolStripMenuItem;
- private: System::Windows::Forms::ToolStripMenuItem^ jungtiTekstusToolStripMenuItem;
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::TextBox^ textBox1;
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- void InitializeComponent(void)
- {
- this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
- this->tabPage1 = (gcnew System::Windows::Forms::TabPage());
- this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
- this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
- this->richTextBox2 = (gcnew System::Windows::Forms::RichTextBox());
- this->tabPage3 = (gcnew System::Windows::Forms::TabPage());
- this->richTextBox3 = (gcnew System::Windows::Forms::RichTextBox());
- this->tabPage4 = (gcnew System::Windows::Forms::TabPage());
- this->richTextBox4 = (gcnew System::Windows::Forms::RichTextBox());
- this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
- this->failasToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->atidarytiPirmąFailąToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->atidarytiAntrąFailąToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->išsaugotiAnalizęToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->išsaugotiKnygąToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->uždarytiToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->funkcijosToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->analizėToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->jungtiTekstusToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
- this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
- this->openFileDialog2 = (gcnew System::Windows::Forms::OpenFileDialog());
- this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
- this->saveFileDialog2 = (gcnew System::Windows::Forms::SaveFileDialog());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->textBox1 = (gcnew System::Windows::Forms::TextBox());
- this->tabControl1->SuspendLayout();
- this->tabPage1->SuspendLayout();
- this->tabPage2->SuspendLayout();
- this->tabPage3->SuspendLayout();
- this->tabPage4->SuspendLayout();
- this->menuStrip1->SuspendLayout();
- this->SuspendLayout();
- //
- // tabControl1
- //
- this->tabControl1->Controls->Add(this->tabPage1);
- this->tabControl1->Controls->Add(this->tabPage2);
- this->tabControl1->Controls->Add(this->tabPage3);
- this->tabControl1->Controls->Add(this->tabPage4);
- this->tabControl1->Location = System::Drawing::Point(-2, 27);
- this->tabControl1->Name = L"tabControl1";
- this->tabControl1->SelectedIndex = 0;
- this->tabControl1->Size = System::Drawing::Size(810, 314);
- this->tabControl1->TabIndex = 0;
- //
- // tabPage1
- //
- this->tabPage1->Controls->Add(this->richTextBox1);
- this->tabPage1->Location = System::Drawing::Point(4, 22);
- this->tabPage1->Name = L"tabPage1";
- this->tabPage1->Padding = System::Windows::Forms::Padding(3);
- this->tabPage1->Size = System::Drawing::Size(713, 288);
- this->tabPage1->TabIndex = 0;
- this->tabPage1->Text = L"Pirma knyga";
- this->tabPage1->UseVisualStyleBackColor = true;
- //
- // richTextBox1
- //
- this->richTextBox1->Dock = System::Windows::Forms::DockStyle::Fill;
- this->richTextBox1->Font = (gcnew System::Drawing::Font(L"Courier New", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(186)));
- this->richTextBox1->Location = System::Drawing::Point(3, 3);
- this->richTextBox1->Name = L"richTextBox1";
- this->richTextBox1->Size = System::Drawing::Size(707, 282);
- this->richTextBox1->TabIndex = 0;
- this->richTextBox1->Text = L"";
- //
- // tabPage2
- //
- this->tabPage2->Controls->Add(this->richTextBox2);
- this->tabPage2->Location = System::Drawing::Point(4, 22);
- this->tabPage2->Name = L"tabPage2";
- this->tabPage2->Padding = System::Windows::Forms::Padding(3);
- this->tabPage2->Size = System::Drawing::Size(713, 288);
- this->tabPage2->TabIndex = 1;
- this->tabPage2->Text = L"Antra knyga";
- this->tabPage2->UseVisualStyleBackColor = true;
- //
- // richTextBox2
- //
- this->richTextBox2->Dock = System::Windows::Forms::DockStyle::Fill;
- this->richTextBox2->Font = (gcnew System::Drawing::Font(L"Courier New", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(186)));
- this->richTextBox2->Location = System::Drawing::Point(3, 3);
- this->richTextBox2->Name = L"richTextBox2";
- this->richTextBox2->Size = System::Drawing::Size(707, 282);
- this->richTextBox2->TabIndex = 0;
- this->richTextBox2->Text = L"";
- //
- // tabPage3
- //
- this->tabPage3->Controls->Add(this->richTextBox3);
- this->tabPage3->Location = System::Drawing::Point(4, 22);
- this->tabPage3->Name = L"tabPage3";
- this->tabPage3->Padding = System::Windows::Forms::Padding(3);
- this->tabPage3->Size = System::Drawing::Size(713, 288);
- this->tabPage3->TabIndex = 2;
- this->tabPage3->Text = L"Analizė";
- this->tabPage3->UseVisualStyleBackColor = true;
- //
- // richTextBox3
- //
- this->richTextBox3->Dock = System::Windows::Forms::DockStyle::Fill;
- this->richTextBox3->Font = (gcnew System::Drawing::Font(L"Courier New", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(186)));
- this->richTextBox3->Location = System::Drawing::Point(3, 3);
- this->richTextBox3->Name = L"richTextBox3";
- this->richTextBox3->Size = System::Drawing::Size(707, 282);
- this->richTextBox3->TabIndex = 0;
- this->richTextBox3->Text = L"";
- //
- // tabPage4
- //
- this->tabPage4->Controls->Add(this->richTextBox4);
- this->tabPage4->Location = System::Drawing::Point(4, 22);
- this->tabPage4->Name = L"tabPage4";
- this->tabPage4->Padding = System::Windows::Forms::Padding(3);
- this->tabPage4->Size = System::Drawing::Size(802, 288);
- this->tabPage4->TabIndex = 3;
- this->tabPage4->Text = L"Mano knyga";
- this->tabPage4->UseVisualStyleBackColor = true;
- //
- // richTextBox4
- //
- this->richTextBox4->Dock = System::Windows::Forms::DockStyle::Fill;
- this->richTextBox4->Font = (gcnew System::Drawing::Font(L"Courier New", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(186)));
- this->richTextBox4->Location = System::Drawing::Point(3, 3);
- this->richTextBox4->Name = L"richTextBox4";
- this->richTextBox4->Size = System::Drawing::Size(796, 282);
- this->richTextBox4->TabIndex = 0;
- this->richTextBox4->Text = L"";
- //
- // menuStrip1
- //
- this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->failasToolStripMenuItem,
- this->funkcijosToolStripMenuItem});
- this->menuStrip1->Location = System::Drawing::Point(0, 0);
- this->menuStrip1->Name = L"menuStrip1";
- this->menuStrip1->Size = System::Drawing::Size(834, 24);
- this->menuStrip1->TabIndex = 1;
- this->menuStrip1->Text = L"menuStrip1";
- //
- // failasToolStripMenuItem
- //
- this->failasToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(5) {this->atidarytiPirmąFailąToolStripMenuItem,
- this->atidarytiAntrąFailąToolStripMenuItem, this->išsaugotiAnalizęToolStripMenuItem, this->išsaugotiKnygąToolStripMenuItem, this->uždarytiToolStripMenuItem});
- this->failasToolStripMenuItem->Name = L"failasToolStripMenuItem";
- this->failasToolStripMenuItem->Size = System::Drawing::Size(48, 20);
- this->failasToolStripMenuItem->Text = L"Failas";
- //
- // atidarytiPirmąFailąToolStripMenuItem
- //
- this->atidarytiPirmąFailąToolStripMenuItem->Name = L"atidarytiPirmąFailąToolStripMenuItem";
- this->atidarytiPirmąFailąToolStripMenuItem->Size = System::Drawing::Size(178, 22);
- this->atidarytiPirmąFailąToolStripMenuItem->Text = L"Atidaryti pirmą failą";
- this->atidarytiPirmąFailąToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::atidarytiPirmąFailąToolStripMenuItem_Click);
- //
- // atidarytiAntrąFailąToolStripMenuItem
- //
- this->atidarytiAntrąFailąToolStripMenuItem->Name = L"atidarytiAntrąFailąToolStripMenuItem";
- this->atidarytiAntrąFailąToolStripMenuItem->Size = System::Drawing::Size(178, 22);
- this->atidarytiAntrąFailąToolStripMenuItem->Text = L"Atidaryti antrą failą";
- this->atidarytiAntrąFailąToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::atidarytiAntrąFailąToolStripMenuItem_Click);
- //
- // išsaugotiAnalizęToolStripMenuItem
- //
- this->išsaugotiAnalizęToolStripMenuItem->Name = L"išsaugotiAnalizęToolStripMenuItem";
- this->išsaugotiAnalizęToolStripMenuItem->Size = System::Drawing::Size(178, 22);
- this->išsaugotiAnalizęToolStripMenuItem->Text = L"Išsaugoti analizę";
- //
- // išsaugotiKnygąToolStripMenuItem
- //
- this->išsaugotiKnygąToolStripMenuItem->Name = L"išsaugotiKnygąToolStripMenuItem";
- this->išsaugotiKnygąToolStripMenuItem->Size = System::Drawing::Size(178, 22);
- this->išsaugotiKnygąToolStripMenuItem->Text = L"Išsaugoti knygą";
- //
- // uždarytiToolStripMenuItem
- //
- this->uždarytiToolStripMenuItem->Name = L"uždarytiToolStripMenuItem";
- this->uždarytiToolStripMenuItem->Size = System::Drawing::Size(178, 22);
- this->uždarytiToolStripMenuItem->Text = L"Uždaryti";
- this->uždarytiToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::uždarytiToolStripMenuItem_Click);
- //
- // funkcijosToolStripMenuItem
- //
- this->funkcijosToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->analizėToolStripMenuItem,
- this->jungtiTekstusToolStripMenuItem});
- this->funkcijosToolStripMenuItem->Name = L"funkcijosToolStripMenuItem";
- this->funkcijosToolStripMenuItem->Size = System::Drawing::Size(69, 20);
- this->funkcijosToolStripMenuItem->Text = L"Funkcijos";
- //
- // analizėToolStripMenuItem
- //
- this->analizėToolStripMenuItem->Name = L"analizėToolStripMenuItem";
- this->analizėToolStripMenuItem->Size = System::Drawing::Size(146, 22);
- this->analizėToolStripMenuItem->Text = L"Analizė";
- this->analizėToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::analizėToolStripMenuItem_Click);
- //
- // jungtiTekstusToolStripMenuItem
- //
- this->jungtiTekstusToolStripMenuItem->Name = L"jungtiTekstusToolStripMenuItem";
- this->jungtiTekstusToolStripMenuItem->Size = System::Drawing::Size(146, 22);
- this->jungtiTekstusToolStripMenuItem->Text = L"Jungti tekstus";
- this->jungtiTekstusToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::jungtiTekstusToolStripMenuItem_Click);
- //
- // openFileDialog1
- //
- this->openFileDialog1->FileName = L"openFileDialog1";
- //
- // openFileDialog2
- //
- this->openFileDialog2->FileName = L"openFileDialog2";
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Location = System::Drawing::Point(29, 356);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(51, 13);
- this->label1->TabIndex = 2;
- this->label1->Text = L"Skyrikliai:";
- //
- // textBox1
- //
- this->textBox1->Location = System::Drawing::Point(107, 353);
- this->textBox1->Name = L"textBox1";
- this->textBox1->Size = System::Drawing::Size(100, 20);
- this->textBox1->TabIndex = 3;
- this->textBox1->Text = L" .,;:!\?\'\"-()<>[]";
- //
- // Form1
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(834, 378);
- this->Controls->Add(this->textBox1);
- this->Controls->Add(this->label1);
- this->Controls->Add(this->tabControl1);
- this->Controls->Add(this->menuStrip1);
- this->MainMenuStrip = this->menuStrip1;
- this->Name = L"Form1";
- this->Text = L"Form1";
- this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
- this->tabControl1->ResumeLayout(false);
- this->tabPage1->ResumeLayout(false);
- this->tabPage2->ResumeLayout(false);
- this->tabPage3->ResumeLayout(false);
- this->tabPage4->ResumeLayout(false);
- this->menuStrip1->ResumeLayout(false);
- this->menuStrip1->PerformLayout();
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- void Stringtostring(String^ s, string & os)
- {
- using namespace System::Runtime::InteropServices;
- const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
- os = chars;
- Marshal::FreeHGlobal(IntPtr((void*)chars));
- }
- void Skaityti(const char fv[], Knyga & Kn)
- {
- string eil;
- ifstream fd(fv);
- while(!fd.eof())
- {
- getline(fd, eil);
- Kn.DetiEilute(eil);
- }
- fd.close();
- }
- unsigned int RastiIlgi(Knyga & Kn, string & skyrikliai)
- {
- string zodis;
- string eilute;
- unsigned int max = 0;
- for(int i = 0; i < Kn.ImtiEilKiek(); i++)
- {
- eilute = Kn.ImtiEilute(i);
- size_t paskPoz = eilute.find_first_not_of(skyrikliai, 0);
- size_t poz = eilute.find_first_of(skyrikliai, paskPoz);
- while (string::npos != poz || string::npos != paskPoz)
- {
- zodis = eilute.substr(paskPoz, poz - paskPoz);
- if(zodis.length() > max)
- max = zodis.length();
- paskPoz = eilute.find_first_not_of(skyrikliai, poz);
- poz = eilute.find_first_of(skyrikliai, paskPoz);
- }
- }
- return max;
- }
- void RinktiPagalIlgi(map<string, int> & Ilgiausi, Knyga & Kn, int max, string skyrikliai)
- {
- Ilgiausi.clear();
- string eilute;
- string zodis;
- for(int i = 0; i < Kn.ImtiEilKiek(); i++)
- {
- eilute = Kn.ImtiEilute(i);
- size_t paskPoz = eilute.find_first_not_of(skyrikliai, 0);
- size_t poz = eilute.find_first_of(skyrikliai, paskPoz);
- while (string::npos != poz || string::npos != paskPoz)
- {
- if(poz - paskPoz == max)
- {
- zodis = eilute.substr(paskPoz, poz - paskPoz);
- for(int i = 0; i < zodis.size(); i++)
- zodis[i] = tolower(zodis[i]);
- Ilgiausi[zodis]? Ilgiausi[zodis]++ : Ilgiausi[zodis]=1;
- }
- paskPoz = eilute.find_first_not_of(skyrikliai, poz);
- poz = eilute.find_first_of(skyrikliai, paskPoz);
- }
- }
- }
- void BendruRadimas(map<string, int> & Bendri, map<string, int> & Ilgiausi1, map<string, int> & Ilgiausi2)
- {
- for (std::map<string, int>::iterator it1 = Ilgiausi1.begin(); it1 != Ilgiausi1.end(); ++it1)
- for (std::map<string, int>::iterator it2 = Ilgiausi2.begin(); it2 != Ilgiausi2.end(); ++it2)
- {
- if(it1->first == it2->first)
- {
- Bendri[it1->first] = it1->second + it2->second;
- break;
- }
- }
- }
- void SkirtinguRadimas(map<string, int> & Nesikart, map<string, int> & Ilgiausi1, map<string, int> & Ilgiausi2)
- {
- for (std::map<string, int>::iterator it1 = Ilgiausi1.begin(); it1 != Ilgiausi1.end(); ++it1)
- {
- bool kartojasi = false;
- for (std::map<string, int>::iterator it2 = Ilgiausi2.begin(); it2 != Ilgiausi2.end(); ++it2)
- {
- if(it1->first == it2->first)
- {
- kartojasi = true;
- break;
- }
- }
- if(kartojasi == false)
- Nesikart[it1->first] = it1->second;
- }
- }
- void RinktiIlgiausius(map<string, int> & Bendri, map<string, int> & Nesikart, Knyga & Kn1, Knyga & Kn2, string & skyrikliai)
- {
- map<string, int> Ilgiausi1;
- map<string, int> Ilgiausi2;
- int max = RastiIlgi(Kn1, skyrikliai);
- while((Bendri.size() == 0 || Nesikart.size() == 0) && max != 0)
- {
- RinktiPagalIlgi(Ilgiausi1, Kn1, max, skyrikliai);
- RinktiPagalIlgi(Ilgiausi2, Kn2, max, skyrikliai);
- if(Bendri.size() == 0)
- BendruRadimas(Bendri, Ilgiausi1, Ilgiausi2);
- if(Nesikart.size() == 0)
- SkirtinguRadimas(Nesikart, Ilgiausi1, Ilgiausi2);
- max--;
- }
- }
- void SpausdintiAnalize(const char fv[], string antraste, map<string, int> Sarasas)
- {
- ofstream fr(fv, ios::app);
- fr << antraste << endl;
- fr << "-------------------------------------------" << endl;
- fr << "|" << setw(30) << "Žodis" << " |" << setw(8) << "Dažnis" << " |" << endl;
- fr << "-------------------------------------------" << endl;
- for(map<string, int>::iterator it = Sarasas.begin(); it != Sarasas.end(); ++it)
- fr << "|" << setw(30) << it->first << " |" << setw(8) << it->second << " |" << endl;
- fr << "-------------------------------------------" << endl;
- fr << endl;
- fr.close();
- }
- void Jungti(Knyga & ManoKnyga, Knyga & Kn1, Knyga & Kn2, string skyrikliai)
- {
- stringstream eilute;
- string zodis1, zodis2;
- string eil1 = Kn1.ImtiEilute(0);
- eil1 += " ";
- eil1.erase(0, eil1.find_first_not_of(skyrikliai, 0));
- string eil2 = Kn2.ImtiEilute(0);
- eil2 += " ";
- eil2.erase(0, eil2.find_first_not_of(skyrikliai, 0));
- int akt1 = 0, akt2 = 0;
- int poz, skPoz;
- while(akt1 < Kn1.ImtiEilKiek() && akt2 < Kn2.ImtiEilKiek())
- {
- while(akt1 < Kn1.ImtiEilKiek() - 1)
- {
- if(eil1.size() == 0)
- {
- akt1++;
- eil1 = Kn1.ImtiEilute(akt1);
- eil1 += " ";
- if(akt1 < Kn1.ImtiEilKiek() - 1)
- break;
- }
- if(eilute.str().size() > 60)
- {
- ManoKnyga.DetiEilute(eilute.str());
- eilute.str("");
- }
- skPoz = eil1.find_first_of(skyrikliai, 0);
- poz = eil1.find_first_not_of(skyrikliai, 0);
- if(skPoz < poz)
- {
- eilute << eil1.substr(0, poz);
- eil1.erase(0, poz);
- }
- else
- {
- zodis1 = eil1.substr(0, skPoz);
- eil1.erase(0, skPoz);
- eilute << zodis1;
- for(int i = 0; i < zodis1.size(); i++)
- zodis1[i] = tolower(zodis1[i]);
- zodis2 = eil2.substr(0, skPoz);
- for(int i = 0; i < zodis2.size(); i++)
- zodis2[i] = tolower(zodis2[i]);
- if(zodis1 == zodis2)
- {
- poz = eil1.find_first_not_of(skyrikliai, 0);
- eil1.erase(0, poz);
- skPoz = eil2.find_first_of(skyrikliai, 0);
- eil2.erase(0, skPoz);
- break;
- }
- }
- }
- while(akt2 < Kn2.ImtiEilKiek() - 1)
- {
- if(eil2.size() == 0)
- {
- akt2++;
- eil2 = Kn2.ImtiEilute(akt2);
- eil2 += " ";
- if(akt2 < Kn2.ImtiEilKiek() - 1)
- break;
- }
- if(eilute.str().size() > 60)
- {
- ManoKnyga.DetiEilute(eilute.str());
- eilute.str("");
- }
- skPoz = eil2.find_first_of(skyrikliai, 0);
- poz = eil2.find_first_not_of(skyrikliai, 0);
- if(skPoz < poz)
- {
- eilute << eil2.substr(0, poz);
- eil2.erase(0, poz);
- }
- else
- {
- zodis2 = eil2.substr(0, skPoz);
- eil2.erase(0, skPoz);
- eilute << zodis2;
- for(int i = 0; i < zodis2.size(); i++)
- zodis2[i] = tolower(zodis2[i]);
- zodis1 = eil1.substr(0, skPoz);
- for(int i = 0; i < zodis1.size(); i++)
- zodis1[i] = tolower(zodis1[i]);
- if(zodis2 == zodis1)
- {
- poz = eil2.find_first_not_of(skyrikliai, 0);
- eil2.erase(0, poz);
- skPoz = eil1.find_first_of(skyrikliai, 0);
- eil1.erase(0, skPoz);
- break;
- }
- }
- }
- }
- }
- private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
- setlocale(LC_ALL, "Lithuanian");
- }
- private: System::Void atidarytiPirmąFailąToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- openFileDialog1->DefaultExt = ".txt";
- openFileDialog1->Filter = "TXT failai | *.txt";
- if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK &&
- openFileDialog1->FileName->Length > 0)
- {
- dfv1 = openFileDialog1->FileName;
- richTextBox1->LoadFile(dfv1, RichTextBoxStreamType::PlainText);
- string dfvs1;
- Kn1 = new Knyga;
- Stringtostring(dfv1, dfvs1);
- Skaityti(dfvs1.c_str(), *Kn1);
- }
- }
- private: System::Void atidarytiAntrąFailąToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- openFileDialog2->DefaultExt = ".txt";
- openFileDialog2->Filter = "TXT failai | *.txt";
- if(openFileDialog2->ShowDialog() == System::Windows::Forms::DialogResult::OK &&
- openFileDialog2->FileName->Length > 0)
- {
- dfv2 = openFileDialog2->FileName;
- richTextBox2->LoadFile(dfv2, RichTextBoxStreamType::PlainText);
- string dfvs2;
- Kn2 = new Knyga;
- Stringtostring(dfv2, dfvs2);
- Skaityti(dfvs2.c_str(), *Kn2);
- }
- }
- private: System::Void uždarytiToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- exit(0);
- }
- private: System::Void analizėToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- const char fv[] = "Analize.txt";
- ofstream fr(fv);
- fr.close();
- String^ skyrikliaiS = "";
- string skyrikliai;
- skyrikliaiS = textBox1->Text->ToString();
- Stringtostring(skyrikliaiS, skyrikliai);
- skyrikliai[skyrikliai.size()] = '\n';
- map<string, int> Bendri;
- map<string, int> Nesikart;
- RinktiIlgiausius(Bendri, Nesikart, *Kn1, *Kn2, skyrikliai);
- SpausdintiAnalize(fv, "Ilgiausi bendri žodžiai:", Bendri);
- SpausdintiAnalize(fv, "Ilgiausi ir tik pirmoje knygoje esantys žodžiai:", Nesikart);
- richTextBox3->LoadFile("Analize.txt", RichTextBoxStreamType::PlainText);
- }
- private: System::Void jungtiTekstusToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
- stringstream eil;
- String^ skyrikliaiS = "";
- string skyrikliai;
- skyrikliaiS = textBox1->Text->ToString();
- Stringtostring(skyrikliaiS, skyrikliai);
- skyrikliai[skyrikliai.size()] = '\n';
- const char fv[] = "ManoKnyga.txt";
- Knyga ManoKnyga;
- Jungti(ManoKnyga, *Kn1, *Kn2, skyrikliai);
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement