Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Лабораторная работа для Гайделя №4 вариант 4
- #include<iostream>
- #include<fstream>
- #include<string>
- #include<map>
- using namespace std;
- bool Prod()
- {
- cout << "Continue Y/N" << endl;
- char yn;
- cin >> yn;
- cin.clear();
- if (yn == 'Y' && cin.get() == '\n') return true;
- else if (yn == 'N' && cin.get() == '\n') return false;
- else
- {
- while (cin.get() != '\n');
- cout << "Error. Try again" << endl;
- Prod();
- }
- }
- int main()
- {
- setlocale(LC_ALL, ".1251");
- string fileName;
- do {
- ifstream file;
- do {
- cout << "Input a filename > ";
- cin >> fileName;
- file.open(fileName);
- if (file.good())
- break;
- cout << "Error: File not found" << endl;
- } while (true);
- map <char, int> chars;
- map <char, int>::iterator begin, at, end;
- string str;
- if (file.is_open())
- {
- while (file)
- {
- getline(file, str);
- for (int i = 0; i < str.length(); i++) {
- chars[str[i]]++;// считаем каждый символ
- }
- str = "";
- };
- file.close();
- begin = chars.begin();
- end = chars.end();
- for (at = begin; at != end; at++)
- {
- int i = 0;
- double coef = (double)at->second / chars.size();
- cout << at->first << " >" << at->second << " times >" << coef << endl; // выводим результат
- i++;
- }
- }
- } while (Prod());
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement