11.Алгоритм работы
12.Текст программы
listNodeV.cpp #include
"FormV.h" using
namespace std; bool
ListNodeV::ReadV(std::ifstream& input, std::ofstream& res) {
if
(input.eof())return false; char s = 0; int counter = 0;
f_H.head
= new ListNodeH; f_H.cur = f_H.head;
while
(s != '\n')
{if
(input.eof())break; input >> noskipws >> s;
if
(input.eof())break;
if
(s == '\n' || s == 0) break;
f_H.cur->podstroka.massiv[counter
% N] = s;
++counter;
if
(counter % N == 0)
{f_H.cur->podstroka.len
= N;
f_H.cur->next
= new ListNodeH;
f_H.cur
= f_H.cur->next; }}
f_H.cur->podstroka.len
= counter % N; return true; }
void
ListNodeV::print1(std::ofstream& res) {f_H.cur
= f_H.head;
if
(f_H.head == nullptr) return;
while
(f_H.cur != nullptr)
{for
(int i = 0; i < f_H.cur->podstroka.len; i++){
cout
<< f_H.cur->podstroka.massiv[i];
res
<< f_H.cur->podstroka.massiv[i]; }
cout
<< " -> ";res << " -> ";f_H.cur
= f_H.cur->next; }
cout <<
" NULL_Str" << endl; res << " NULL_Str"
<< endl;}
lab4.cpp #include
"com.h" #include
"FormV.h" #include
"laba4.h" using
namespace std;
bool
Read_file(std::ifstream& input, std::ofstream& res,
FormularV& formularVert) {if
(input.eof()){
cout
<< "SPISOK PUST" << endl; return false; }
formularVert.head
= new ListNodeV;
formularVert.cur
= formularVert.head;
while
(!input.eof())
{if
(formularVert.cur->ReadV(input, res))
{formularVert.cur->next
= new ListNodeV;
formularVert.prev
= formularVert.cur;
formularVert.cur
= formularVert.cur->next; }
else
break; }
if
(formularVert.cur->f_H.head == nullptr &&
formularVert.prev != nullptr) {
delete
formularVert.cur; formularVert.prev->next = nullptr; }
return
true;}
void
print2(std::ofstream& res, FormularV& formularVert) {formularVert.cur
= formularVert.head;
while
(formularVert.cur != nullptr)
{formularVert.cur->print1(res);
cout << "------> " << endl;
res
<< "------> " << endl;
formularVert.cur
= formularVert.cur->next; }
cout <<
" NULL_Vertical " << endl<< endl; ;
res <<
" NULL_Vertical " << endl<< endl;;}
void
del(FormularV& toProcess_F, std::ofstream& res) {toProcess_F.cur
= toProcess_F.head; FormularV tmp4;
if
(toProcess_F.cur == nullptr)
{cout
<< " Список
пуст
" << endl;
res
<< " Список
пуст
" << endl; return; }
while
(toProcess_F.cur != nullptr)
{FormularH
tmp3;
toProcess_F.cur->f_H.cur
= toProcess_F.cur->f_H.head;
while
(toProcess_F.cur->f_H.cur != nullptr)
{tmp3.cur
= toProcess_F.cur->f_H.cur->next;
delete
toProcess_F.cur->f_H.cur;
toProcess_F.cur->f_H.cur
= tmp3.cur; }
tmp4.cur
= toProcess_F.cur->next;
delete
toProcess_F.cur;
toProcess_F.cur
= tmp4.cur; }}
ListNodeH.h #pragma
once #include
"StrL.h" struct
ListNodeH {StrL
podstroka;
ListNodeH*
next = nullptr;};
StrL.h #pragma
once #include
"com.h" struct
StrL {char
massiv[N]; int len = 0;};
FormH.h #pragma
once #include
"ListNodeH.h" struct
FormularH {ListNodeH*
head = nullptr;
ListNodeH*
cur = nullptr;
ListNodeH*
last = nullptr;
ListNodeH*
prev = nullptr;};
FormV.h #pragma
once #include
"ListNodeV.h" struct
FormularV {ListNodeV*
cur = nullptr;
ListNodeV*
head = nullptr;
ListNodeV*
last = nullptr;
ListNodeV*
prev = nullptr;};
ListNodeV.h #pragma
once #include
"FormH.h" struct
ListNodeV {FormularH
f_H;
ListNodeV*
next = nullptr;
bool
ReadV(std::ifstream& input, std::ofstream& res);
void
print1(std::ofstream& res);};
com.h #pragma
once #include
<string> #include
<iostream> #include
<fstream> #include
<iomanip> static
const int N = 10;
laba4.h #pragma
once #include
"FormV.h" typedef
void (*ListNodeVFunction)(ListNodeV& toProcess, std::ofstream&
res); typedef
void (*ListNodeVFunction2)(FormularV& toProcess_F,
std::ofstream& res); void
del(FormularV& toProcess_F, std::ofstream& res); bool
Read_file(std::ifstream& input, std::ofstream& res,
FormularV& formularVert); void
Funk(std::ofstream& res, std::string in_filename, std::string
in_filename2); void
print2(std::ofstream& res, FormularV& formularVert);
main.cpp #include
"laba4.h" using
namespace std; int
main(int argc, char* argv[]) {setlocale(LC_ALL,
"ru"); std::string
filename2 = "result4.txt";
std::ofstream
res(filename2, ios::out | ios::trunc);
Funk(res,
"in.txt", "in2.txt");
return 0;}
Funk.cpp
void Funk(std::ofstream& res, std::string in_filename, std::string in_filename2)
{ifstream input; ifstream input2; open(in_filename, std::ios_base::in); FormularV Spisok1; input2.open(in_filename2, std::ios_base::in);
FormularV Spisok2;
cout << "Началась обработка " << in_filename << endl;
res << "Началась обработка " << in_filename << endl;
if (Read_file(input, res, Spisok1))
{cout << "список 1: " << endl; res << "список 1: " << endl;
print2(res, Spisok1);
cout << " конец обработки " << in_filename << endl; res << " конец обработки " << in_filename << endl << endl; }
cout <<endl<<endl<< "Началась обработка " << in_filename2 << endl;
res << endl<<endl<<"Началась обработка " << in_filename2 << endl;
if (Read_file(input2, res, Spisok2))
{cout << "список 2: " << endl; res << "список 2: " << endl;
print2(res, Spisok2);
cout << " конец обработки " << in_filename2 << endl; res << " конец обработки " << in_filename2 << endl << endl; }
int flag = 0; int FLAG = 0; int count = 0; int kol = 0; int k = 0;
Spisok1.cur = Spisok1.head; Spisok2.cur = Spisok2.head;
Spisok1.cur->f_H.cur = Spisok1.cur->f_H.head; Spisok2.cur->f_H.cur = Spisok2.cur->f_H.head;
while (Spisok1.cur != nullptr) {
kol++; k = 0;
while (Spisok2.cur != nullptr) {
Spisok1.cur->f_H.cur = Spisok1.cur->f_H.head; Spisok2.cur->f_H.cur = Spisok2.cur->f_H.head;
for (int i = 0; i < N; i++) {
if (Spisok1.cur->f_H.cur->podstroka.massiv[i] == Spisok2.cur->f_H.cur->podstroka.massiv[i]) {
if (Spisok1.cur->f_H.cur->podstroka.len == Spisok2.cur->f_H.cur->podstroka.len) {
flag = 1; count++;k++;break; }}
else {flag = 0; Spisok1.cur->f_H.cur = Spisok1.cur->f_H.head; break; }}
if (flag == 1) {cout << "\n слова совпали \n";}
Spisok2.cur = Spisok2.cur->next; }
Spisok2.cur = Spisok2.head; Spisok2.cur->f_H.cur = Spisok2.cur->f_H.head;
Spisok1.cur = Spisok1.cur->next;
if (k == 0) {FLAG++; cout << "\nflag " << FLAG << endl; }}
cout << "\n количество совпадающих слов в списке 1: " << count <<" \nКоличество слов всего: " << kol << "\n";
flag = 0; int FLAG2 = 0; int count2 = 0; int kol2 = 0; int k2 = 0;
Spisok1.cur = Spisok1.head; Spisok2.cur = Spisok2.head;
Spisok1.cur->f_H.cur = Spisok1.cur->f_H.head; Spisok2.cur->f_H.cur = Spisok2.cur->f_H.head;
while (Spisok2.cur != nullptr) {
kol2++;
while (Spisok1.cur != nullptr) {
Spisok1.cur->f_H.cur = Spisok1.cur->f_H.head; Spisok2.cur->f_H.cur = Spisok2.cur->f_H.head;
for (int i = 0; i < N; i++) {
if (Spisok1.cur->f_H.cur->podstroka.massiv[i] == Spisok2.cur->f_H.cur->podstroka.massiv[i]) {
if (Spisok1.cur->f_H.cur->podstroka.len == Spisok2.cur->f_H.cur->podstroka.len) {
flag = 1; count2++;k2++;break; }}
else {flag = 0; Spisok2.cur->f_H.cur = Spisok2.cur->f_H.head; break; }}
if (flag == 1) {cout << "\n слова совпали \n";}
Spisok1.cur = Spisok1.cur->next; }
Spisok1.cur = Spisok1.head; Spisok1.cur->f_H.cur = Spisok1.cur->f_H.head; Spisok2.cur = Spisok2.cur->next;
if (k2 == 0) {FLAG++;cout << "\nflag2 " << FLAG2 << endl; }}
cout << "\n количество совпадающих слов в списке 2: " << count2 << " \nКоличество слов всего: " << kol2 << "\n";
if (((FLAG==0) && (FLAG2==0)) && (count >= kol) && (count2 >= kol2)) {
cout << "\n\nМНОЖЕСТВА СОВПАДАЮТ\n\n";res << "\n\nМНОЖЕСТВА СОВПАДАЮТ\n\n";}
else {cout << "\n\nМНОЖЕСТВА не СОВПАДАЮТ\n\n";res << "\n\nМНОЖЕСТВА не СОВПАДАЮТ\n\n";}
del(Spisok1, res);
cout << " список 1 удален " << endl; res << " список 1 удален " << endl;
del(Spisok2, res);
cout << " список 2 удален " << endl; res << " список 2 удален " << endl;}
