Created
May 11, 2016 13:07
-
-
Save anonymous/be83d40789e43b6ee360fa6f27b02aed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include"Tekst.h" | |
int main() | |
{ | |
Tekst T("test2"); | |
T.Analyze(); | |
T.Sort(); | |
T.Save(); | |
system("pause"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Tekst.h" | |
Tekst::Tekst(std::wstring name):name_of_file(name) | |
{ | |
wchar_t z = 'a'; | |
for (int i = 0; i < size; i++, z++) | |
{ | |
Litera.first = z; | |
Litera.second = 0; | |
Alfabet.push_back(Litera); | |
} | |
} | |
Tekst::~Tekst() | |
{ | |
} | |
void Tekst::Analyze() | |
{ | |
ifstream file; | |
file.imbue(locale("Polish_poland.852")); | |
wstring namefile = name_of_file + ".txt"; | |
file.open(namefile.c_str()); | |
if (!file.is_open()) | |
{ | |
cout << "Nie udalo sie otworzyc pliku o nazwie: " << name_of_file << endl; | |
system("pause"); | |
exit(EXIT_FAILURE); | |
} | |
wchar_t znak; | |
while (file >> znak) | |
{ | |
if (isalpha(znak)) | |
{ | |
znak = tolower(znak); | |
Alfabet[znak - 97].second++; | |
} | |
} | |
} | |
void Tekst::Sort() | |
{ | |
sort(Alfabet.begin(), Alfabet.end(),Compare); | |
} | |
void Tekst::Show() | |
{ | |
for (auto i : Alfabet) | |
cout << i.first << " " << i.second << endl; | |
} | |
void Tekst::Save() | |
{ | |
ofstream file; | |
string name = name_of_file + " - analiza.txt"; | |
file.open(name.c_str()); | |
if (!file.is_open()) | |
{ | |
cout << "Nie udalo sie otworzyc pliku o nazwie: " << name_of_file << endl; | |
cout << "Byla to proba zapisu do pliku" << endl; | |
system("pause"); | |
exit(EXIT_FAILURE); | |
} | |
for (auto i : Alfabet) | |
{ | |
file << i.first << " " << i.second << endl; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include<iostream> | |
#include<fstream> | |
#include<string> | |
#include<cctype> | |
#include<utility> | |
#include<vector> | |
#include<algorithm> | |
#include<locale> | |
using namespace std; | |
class Tekst | |
{ | |
wstring name_of_file; | |
enum | |
{ | |
size = 26 | |
}; | |
struct compare | |
{ | |
bool operator()(pair<wchar_t, int> a, pair<wchar_t, int> b) | |
{ | |
return a.second > b.second; | |
} | |
}Compare; | |
pair<wchar_t, int> Litera; | |
vector<pair<wchar_t, int>> Alfabet; | |
public: | |
Tekst() {}; | |
Tekst(wstring name); | |
~Tekst(); | |
void Analyze(); | |
void Sort(); | |
void Show(); | |
void Save(); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment