Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Вихрев Иван Борисович. Лабораторная работа №2 #30

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added VihrevIB/lab1/doc/Otchet_lab1_Vikhrev_IB.docx
Binary file not shown.
9,592 changes: 9,592 additions & 0 deletions VihrevIB/lab1/gtest/gtest-all.cc

Large diffs are not rendered by default.

20,063 changes: 20,063 additions & 0 deletions VihrevIB/lab1/gtest/gtest.h

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions VihrevIB/lab1/include/desktop.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ViewState]
Mode=
Vid=
FolderType=Generic
142 changes: 142 additions & 0 deletions VihrevIB/lab1/include/list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#pragma once
#include "Node.h"
// ����������� ������ � ������� //

template<typename T>
class Rlist
{
protected:
Node<T>* head;
Node<T>* current;
public:
//������������ � ����������
Rlist();
Rlist(const Rlist<T>& ListToCopy);
~Rlist();

//������
Rlist<T>& operator=(const Rlist<T>& ListToCopy);
void InsertAfter(Node<T>* N, T Data);
void OrderedInsert(T Data); // ������� � ������������� ������
void Clean(); // ������� ������

// ������ ���������
Node<T>* GetCurr() const { return current; } // �������� ��������� �� �������
void SetNext() { current = current->next; }// ����������� ��������� �� ���������
void Reset() { current = head->next; } // ����������� ��������� � ������
bool IsEnd() const { return current == head; } // �������� �� �����

//��������� ���������
bool operator==(const Rlist<T>& RLst) const;
bool operator!=(const Rlist<T>& RLst) const { return !(*this == RLst); }


};

// ............................................................................
template <typename T>
Rlist<T>::Rlist()
{
head = new Node<T>;
head->data = NULL;
head->next = head;
current = head;
}
// ............................................................................
template <typename T>
Rlist<T>::Rlist(const Rlist<T>& ListToCopy)
{
Node<T>* TempCurr = ListToCopy.head;
head = new Node<T>(TempCurr->data);
head->next = head;
current = head;
while (TempCurr->next != ListToCopy.head)
{
TempCurr= TempCurr->next;
current->next = new Node<T>(TempCurr->data);
SetNext();
}
current->next = head;
}
// ............................................................................
template <class T>
Rlist<T>::~Rlist()
{
Clean();
delete head;
}

template <class T>
Rlist<T>& Rlist<T>::operator=(const Rlist<T>& ListToCopy)
{
Clean();
Node<T>* TempCurr1 = ListToCopy.head;
Node<T>* TempCurr2 = head;

while (TempCurr1->next != ListToCopy.head)
{
TempCurr1 = TempCurr1->next;
TempCurr2->next = new Node<T>(TempCurr1->data);
TempCurr2 = TempCurr2->next;
}
TempCurr2->next = head;
current = head;
return *this;
}
// ............................................................................
template <class T>
void Rlist<T>::InsertAfter(Node<T>* N, T Data)
{
Node<T>* temp = N->next;
N->next = new Node<T>(Data);
N->next->next = temp;
}
// ............................................................................
template <class T>
void Rlist<T>::OrderedInsert(T Data)
{
Node<T>* Temp;
current = head;

while ( (current->next->data > Data) && current->next != head)
SetNext();

Temp = current->next;
current->next = new Node<T>(Data);
current->next->next = Temp;
}
// ............................................................................
template <class T>
void Rlist<T>::Clean()
{
Node<T>* TempCurr = head->next;
Node<T>* Temp;
while (TempCurr != head)
{
Temp = TempCurr->next;
delete TempCurr;
TempCurr = Temp;
}
head->next = head;
}
// ............................................................................
template<class T>
bool Rlist<T>::operator==(const Rlist<T>& RLst) const
{
bool flag = true;
if (this != &RLst)
{
Node<T>* temp1 = head->next;
Node<T>* temp2 = RLst.head->next;

while (temp1 != head && temp2 != RLst.head && temp1->data == temp2->data)
{
temp1 = temp1->next;
temp2 = temp2->next;
}
if (temp1 != head || temp2 != RLst.head)
flag = false;
}
return flag;
}
// ............................................................................
19 changes: 19 additions & 0 deletions VihrevIB/lab1/include/monom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
// �����
class Monom
{
public:
double coeff; //�����������
unsigned int abc; // �������

//�����������
Monom(double COEFF = 0 , unsigned int ABC = 0) { coeff = COEFF; abc = ABC;}

//���������
bool operator< (const Monom& m) const { return (abc<m.abc); }
bool operator> (const Monom& m) const { return (abc>m.abc); }
bool operator==(const Monom& m) const { return (abc == m.abc && coeff == m.coeff); } //
bool operator!=(const Monom& m) const { return !(*this == m); }

Monom& operator=(const Monom& m) { coeff = m.coeff; abc = m.abc; return *this; }
};
19 changes: 19 additions & 0 deletions VihrevIB/lab1/include/node.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include <iostream>

template <typename T>

class Node
{
public:
T data;
Node<T>* next;

Node(T DATA = NULL, Node<T>* NEXT = nullptr) { data = DATA; next = NEXT; }
Node(Node<T> &Node2) { data = node2.data; next = nullptr; }
//��������� ���������
bool operator< (const Node<T>& N) const { return (data<N.data); }
bool operator> (const Node<T>& N) const { return (data>N.data); }
bool operator!= (const Node<T>& N) const { return !(*this == N); }
bool operator==(const Node<T>& N) const { return (data == N.data && next == N.next); }
};
45 changes: 45 additions & 0 deletions VihrevIB/lab1/include/polinom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <iostream>
#include <string>
#include <algorithm>
#include "Monom.h"
#include "list.h"


using std::string;
using std::ostream;
using std::cout;
using std::cin;
using std::endl;

class Polinom {

protected:

Rlist<Monom> Monoms;
string name;
//��������������� ������
Rlist <Monom> Simplify(Rlist <Monom> POL); // �������� �������� ���������
Rlist<Monom> Parsing(const string Line);// �������� ������ �� ������

public:

//������������
Polinom(const string Line = "" ); // ����������� �� ������
Polinom(const Monom m) { Monoms.InsertAfter(Monoms.GetCurr(),m); }// ����������� �������������� ����: �� ������
Polinom(const Rlist<Monom> &P2) : Monoms(P2) {}; // ����������� �������������� ����: �� ������
Polinom(const Polinom& POL) : Monoms(POL.Monoms) {}; //����������� �����������

//���������
Polinom operator+ (const Polinom&) const;
Polinom operator- (const Polinom& POL) const { return (*this + POL*(-1.0)); }
Polinom operator* (const Polinom& POL) const;// ��������� �������� �� �������
Polinom operator* (const double c) const; // ��������� �������� �� ��������� ������

bool operator== (const Polinom& POL) const { return Monoms == POL.Monoms; }
bool operator!= (const Polinom& POL) const { return Monoms != POL.Monoms; }

friend Polinom operator* (const double C , const Polinom& POL) { return POL*C; } // ��������� �������� �� ��������� �����
friend ostream& operator<< (ostream& os, const Polinom&);
};
48 changes: 48 additions & 0 deletions VihrevIB/lab1/samples/main_polinom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "polinom.h"
#include <conio.h>
#include <Windows.h>
int main()
{
char ch = 0;
string exp1;
string exp2;
system("color F0");

cout << "Use only: " << endl << " letters x,y,z" << endl << " numbers 0...9" << endl << " symblols . ,^ , +, -" << endl ;

while (ch != 27)
{
cout << "Enter first polinom: " << endl;
cin >> exp1;
Polinom A(exp1);
cout << "A = " <<A << endl;

cout << "Enter second polinom: " << endl;
cin >> exp2;
Polinom B(exp2);
cout <<"B = " << B << endl << "-----------------------------------------------------------------------------" << endl;
Polinom res = A + B;
cout << " A + B = ";
cout << res << endl;

res = A - B;
cout << " A - B = ";
cout << res << endl;

res = B - A;
cout << " B - A = ";
cout << res << endl;

res = A * B;
cout << " A * B = ";
cout << res << endl;
cout << "-----------------------------------------------------------------------------" << endl;
cout << "Esc to exit " << endl;

ch = _getch();
}



return 0;
}
68 changes: 68 additions & 0 deletions VihrevIB/lab1/sln/polinom/polinom.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.15
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest", "polinom\polinom.vcxproj", "{75848823-0704-4D2D-94B3-8B8D8DB87437}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample_polinom", "sample_polinom\sample_polinom.vcxproj", "{33024D8B-923D-4484-8B91-233E6E4BC0F5}"
ProjectSection(ProjectDependencies) = postProject
{00CE2F8E-573C-4585-94C4-33994370ADD1} = {00CE2F8E-573C-4585-94C4-33994370ADD1}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "polinom_test", "polinom_test\polinom_test.vcxproj", "{42132143-D3D7-4E74-9A86-AEBFE1CF9B3D}"
ProjectSection(ProjectDependencies) = postProject
{75848823-0704-4D2D-94B3-8B8D8DB87437} = {75848823-0704-4D2D-94B3-8B8D8DB87437}
{00CE2F8E-573C-4585-94C4-33994370ADD1} = {00CE2F8E-573C-4585-94C4-33994370ADD1}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "polinoms_lib", "polinoms_lib\polinoms_lib.vcxproj", "{00CE2F8E-573C-4585-94C4-33994370ADD1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{75848823-0704-4D2D-94B3-8B8D8DB87437}.Debug|x64.ActiveCfg = Debug|x64
{75848823-0704-4D2D-94B3-8B8D8DB87437}.Debug|x64.Build.0 = Debug|x64
{75848823-0704-4D2D-94B3-8B8D8DB87437}.Debug|x86.ActiveCfg = Debug|Win32
{75848823-0704-4D2D-94B3-8B8D8DB87437}.Debug|x86.Build.0 = Debug|Win32
{75848823-0704-4D2D-94B3-8B8D8DB87437}.Release|x64.ActiveCfg = Release|x64
{75848823-0704-4D2D-94B3-8B8D8DB87437}.Release|x64.Build.0 = Release|x64
{75848823-0704-4D2D-94B3-8B8D8DB87437}.Release|x86.ActiveCfg = Release|Win32
{75848823-0704-4D2D-94B3-8B8D8DB87437}.Release|x86.Build.0 = Release|Win32
{33024D8B-923D-4484-8B91-233E6E4BC0F5}.Debug|x64.ActiveCfg = Debug|x64
{33024D8B-923D-4484-8B91-233E6E4BC0F5}.Debug|x64.Build.0 = Debug|x64
{33024D8B-923D-4484-8B91-233E6E4BC0F5}.Debug|x86.ActiveCfg = Debug|Win32
{33024D8B-923D-4484-8B91-233E6E4BC0F5}.Debug|x86.Build.0 = Debug|Win32
{33024D8B-923D-4484-8B91-233E6E4BC0F5}.Release|x64.ActiveCfg = Release|x64
{33024D8B-923D-4484-8B91-233E6E4BC0F5}.Release|x64.Build.0 = Release|x64
{33024D8B-923D-4484-8B91-233E6E4BC0F5}.Release|x86.ActiveCfg = Release|Win32
{33024D8B-923D-4484-8B91-233E6E4BC0F5}.Release|x86.Build.0 = Release|Win32
{42132143-D3D7-4E74-9A86-AEBFE1CF9B3D}.Debug|x64.ActiveCfg = Debug|x64
{42132143-D3D7-4E74-9A86-AEBFE1CF9B3D}.Debug|x64.Build.0 = Debug|x64
{42132143-D3D7-4E74-9A86-AEBFE1CF9B3D}.Debug|x86.ActiveCfg = Debug|Win32
{42132143-D3D7-4E74-9A86-AEBFE1CF9B3D}.Debug|x86.Build.0 = Debug|Win32
{42132143-D3D7-4E74-9A86-AEBFE1CF9B3D}.Release|x64.ActiveCfg = Release|x64
{42132143-D3D7-4E74-9A86-AEBFE1CF9B3D}.Release|x64.Build.0 = Release|x64
{42132143-D3D7-4E74-9A86-AEBFE1CF9B3D}.Release|x86.ActiveCfg = Release|Win32
{42132143-D3D7-4E74-9A86-AEBFE1CF9B3D}.Release|x86.Build.0 = Release|Win32
{00CE2F8E-573C-4585-94C4-33994370ADD1}.Debug|x64.ActiveCfg = Debug|x64
{00CE2F8E-573C-4585-94C4-33994370ADD1}.Debug|x64.Build.0 = Debug|x64
{00CE2F8E-573C-4585-94C4-33994370ADD1}.Debug|x86.ActiveCfg = Debug|Win32
{00CE2F8E-573C-4585-94C4-33994370ADD1}.Debug|x86.Build.0 = Debug|Win32
{00CE2F8E-573C-4585-94C4-33994370ADD1}.Release|x64.ActiveCfg = Release|x64
{00CE2F8E-573C-4585-94C4-33994370ADD1}.Release|x64.Build.0 = Release|x64
{00CE2F8E-573C-4585-94C4-33994370ADD1}.Release|x86.ActiveCfg = Release|Win32
{00CE2F8E-573C-4585-94C4-33994370ADD1}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {49BC6E49-ED2A-45D4-9C34-FEA4E6E0659C}
EndGlobalSection
EndGlobal
Loading