Otchyot_OOPro_Laba_6
.docxОтчёт по лабораторной работе №6
По дисциплине «Объектно-ориентированное программирование»
Ст.гр. ИНФ-10-1
Бурдеевой Анастасии
ВАРИАНТ 5
Разработать программу, которая считывает текст и вычисляет отношение длины каждого слова к средней длине слов текста, за исключением слов, указанных в списке (длина / средняя длина слов, не учитывая слова из списка). Слова в тексте разделяются пробелами. Подсчет относительной длины реализовывать с помощью ассоциативного массива, список слов для исключения реализовывать с помощью множества. Каждый раз, когда встретилось слово из списка, выводить сообщение. Исходные данные считать из файла и вывести в файл.
#include <iostream>
#include <vector>
#include<set>
#include <string>
#include <fstream>
using namespace std;
void main()
{
int total_length=0;
set<string> words;
vector<string> text;
words.insert("Alice");
words.insert("sister");
words.insert("book");
fstream fread("Text.txt",ios::in|ios::binary);
copy(istream_iterator<string>(fread),istream_iterator<string>(),back_inserter(text));
cout<<"TEXT:"<<endl;
for(int i=0;i<text.size();i++)
{
if(text[i].find('.')==-1)
cout<<text[i]<<" ";
else
cout<<text[i]<<endl;
if(words.count(text[i])==0)
total_length+=text[i].length();
}
total_length/=text.size();
cout<<"Total length: "<<total_length<<endl;
char total[10];
char ex[] = "=================>This word is in exception list!";
for(int i=0;i<text.size();i++)
{
if(words.count(text[i])==0)
{
text[i]+="\t\t";
text[i]+=itoa(text[i].length(),total,10);
text[i]+="/";
text[i]+=itoa(total_length,total,10);
text[i]+="=";
text[i]+=itoa(text[i].length()/total_length,total,10);
}
else
{
text[i]+="\t\t";
text[i]+=ex;
}
cout<<text[i]<<endl;
}
fstream fwrite("Text_rez.txt",ios::out);
ostream_iterator<string> wr(fwrite,"\n");
copy(text.begin(),text.end(),wr);
system("pause");
}