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

Арифметические выражения #11

Open
wants to merge 5 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
63 changes: 62 additions & 1 deletion include/arithmetic.h
Original file line number Diff line number Diff line change
@@ -1 +1,62 @@
// ���������� ������� � ������� ��� ���������� �������������� ���������
// ���������� ������� � ������� ��� ���������� �������������� ���������
#include "stack.h"
#include <string>
#include <vector>
#include <iostream>

using namespace std;

struct lexema
{
string val;
int type;
double x;
lexema()
{
x = 0.0;
val = "\0";
type = -100;
}
lexema(string s, int t = -100)
{
x = 0.0;
val = s;
type = t;
}
lexema(char s, int t = -100)
{
x = 0.0;
val = s;
type = t;
}
int operator==(const lexema& l)
{
return ((val == l.val) && (type == l.type));
}
};

class Arithmetic
{
string input;
double result;
vector<lexema> inp_lex;
vector<lexema> pol_lex;
int status;

public:
void enter();
void split();
bool check_bkt();
vector<int> check_symbols();
bool check_points();
bool check_operations();
bool isCorrect();
void converter();
void set_values();
void calculate();
void launch();
Arithmetic(string str = "");
vector<lexema> get_input_lex();
vector<lexema> get_polish_lex();
double get_result();
};
78 changes: 73 additions & 5 deletions include/stack.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,77 @@
// ���������� � ���������� ���������� �����
// ���� ������������ ��������:
// - ������� ��������,
// - ���������� ��������,
// ���� ������������ ��������:
// - ������� ��������,
// - ���������� ��������,
// - �������� �������� �������� (��� ��������)
// - �������� �� �������,
// - �������� �� �������,
// - ��������� ���������� ��������� � �����
// - ������� �����
// ��� ������� � ������ ���� ������ �������������� ������
// ��� ������� � ������ ���� ������ �������������� ������

constexpr int memsize = 25;

template <typename T>
class Stack
{
private:
T* pMem;
int MemSize;
int Hi;
//virtual int GetNextIndex(int index);
public:
Stack(int size = memsize)
{
if (size <= 0)
throw std::exception("Size must be greater than null!");
pMem = new T[size];
MemSize = size;
Hi = -1;
}

~Stack()
{
delete[] pMem;
}

void Put(const T& val)
{
if (Hi == (MemSize - 1))
{
T* tmp = new T[++MemSize];
for (size_t i = 0; i < MemSize; i++)
tmp[i] = pMem[i];
delete[] pMem;
pMem = tmp;
}
pMem[++Hi] = val;
}

T& Get()
{
if (IsEmpty())
throw std::exception("Stack is empty!");
return pMem[Hi--];
}

T View() const
{
if (IsEmpty())
throw std::exception("Stack is empty!");
return pMem[Hi];
}

int IsEmpty() const
{
return Hi == -1;
}

int GetDataCount() const
{
return Hi + 1;
}

void Clear()
{
Hi = -1;
}
};
8 changes: 6 additions & 2 deletions samples/main_arithmetic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// реализация пользовательского приложения
#include "arithmetic.h"

int main()
{
return 0;
}
Arithmetic A;
A.launch();

return 0;
}
4 changes: 2 additions & 2 deletions sln/vc12/arithmetic/arithmetic.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
4 changes: 2 additions & 2 deletions sln/vc12/gtest/gtest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
4 changes: 2 additions & 2 deletions sln/vc12/sample/sample.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
4 changes: 2 additions & 2 deletions sln/vc12/tests/tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
Loading