Add project files.
This commit is contained in:
31
Lab.sln
Normal file
31
Lab.sln
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 16
|
||||||
|
VisualStudioVersion = 16.0.33214.272
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lab", "Lab\Lab.vcxproj", "{A12EB4A7-1661-4043-AC3E-5E303447400C}"
|
||||||
|
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
|
||||||
|
{A12EB4A7-1661-4043-AC3E-5E303447400C}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{A12EB4A7-1661-4043-AC3E-5E303447400C}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{A12EB4A7-1661-4043-AC3E-5E303447400C}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{A12EB4A7-1661-4043-AC3E-5E303447400C}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{A12EB4A7-1661-4043-AC3E-5E303447400C}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{A12EB4A7-1661-4043-AC3E-5E303447400C}.Release|x64.Build.0 = Release|x64
|
||||||
|
{A12EB4A7-1661-4043-AC3E-5E303447400C}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{A12EB4A7-1661-4043-AC3E-5E303447400C}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {74D84430-7BDE-4C9E-AEFE-64042027E7C7}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
28
Lab/Lab.cpp
Normal file
28
Lab/Lab.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#include "triple.h"
|
||||||
|
#include "operations.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc,char* argv[]) {
|
||||||
|
triple number1, number2;
|
||||||
|
triple res;
|
||||||
|
char action;
|
||||||
|
//setPrecision(atoi(argv[3]));
|
||||||
|
cin >> number1 >> number2 >> action >> precision;
|
||||||
|
switch (action) {
|
||||||
|
case '+': res = number1 + number2;
|
||||||
|
break;
|
||||||
|
case '-': res = number1 - number2;
|
||||||
|
break;
|
||||||
|
case '*': res = number1 * number2;
|
||||||
|
break;
|
||||||
|
case '/': res = number1 / number2;
|
||||||
|
break;
|
||||||
|
default: cout << "No such operation retard!";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cout << res;
|
||||||
|
}
|
||||||
|
|
||||||
163
Lab/Lab.vcxproj
Normal file
163
Lab/Lab.vcxproj
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>16.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{a12eb4a7-1661-4043-ac3e-5e303447400c}</ProjectGuid>
|
||||||
|
<RootNamespace>Lab</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>C:\LIBS\boost_1_81_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>C:\LIBS\boost_1_81_0\libs;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>C:\LIBS\boost_1_81_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>C:\LIBS\boost_1_81_0\libs;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="global.cpp" />
|
||||||
|
<ClCompile Include="triple.cpp" />
|
||||||
|
<ClCompile Include="Lab.cpp" />
|
||||||
|
<ClCompile Include="operations.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="global.h" />
|
||||||
|
<ClInclude Include="triple.h" />
|
||||||
|
<ClInclude Include="operations.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
42
Lab/Lab.vcxproj.filters
Normal file
42
Lab/Lab.vcxproj.filters
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Source Files">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Header Files">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Resource Files">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Lab.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="operations.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="triple.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="global.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="triple.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="operations.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="global.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
3
Lab/global.cpp
Normal file
3
Lab/global.cpp
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#include "global.h"
|
||||||
|
|
||||||
|
int precision = 0;
|
||||||
6
Lab/global.h
Normal file
6
Lab/global.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef GLOBAL_H
|
||||||
|
#define GLOBAL_H
|
||||||
|
|
||||||
|
extern int precision;
|
||||||
|
#endif
|
||||||
258
Lab/operations.cpp
Normal file
258
Lab/operations.cpp
Normal file
@@ -0,0 +1,258 @@
|
|||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include "triple.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "operations.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
triple operations::add(triple& a, triple& b) {
|
||||||
|
if (a.negative && !b.negative) {
|
||||||
|
a.negative = false;
|
||||||
|
triple res = b - a;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
if (!a.negative && b.negative) {
|
||||||
|
b.negative = false;
|
||||||
|
triple res = a - b;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
if (a.negative && b.negative) {
|
||||||
|
a.negative = false;
|
||||||
|
b.negative = false;
|
||||||
|
triple res = a + b;
|
||||||
|
res.negative = true;
|
||||||
|
a.negative = true;
|
||||||
|
b.negative = true;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
triple res;
|
||||||
|
int next = 0;
|
||||||
|
int int_size = max(a.integer.size(), b.integer.size());
|
||||||
|
int float_size = max(a.floating.size(), b.floating.size());
|
||||||
|
vector<int> int_result;
|
||||||
|
vector<int> floating_result;
|
||||||
|
while (a.integer.size() < int_size)
|
||||||
|
a.integer.insert(a.integer.begin(), 0);
|
||||||
|
while (b.integer.size() < int_size)
|
||||||
|
b.integer.insert(b.integer.begin(), 0);
|
||||||
|
while (a.floating.size() < float_size)
|
||||||
|
a.floating.push_back(0);
|
||||||
|
while (b.floating.size() < float_size)
|
||||||
|
b.floating.push_back(0);
|
||||||
|
|
||||||
|
for (auto av = a.floating.rbegin(), bv = b.floating.rbegin(); av != a.floating.rend() && bv != b.floating.rend(); ++av, ++bv) {
|
||||||
|
int sum = *av + *bv + next;
|
||||||
|
floating_result.insert(floating_result.begin(), sum % 10);
|
||||||
|
next = sum / 10;
|
||||||
|
}
|
||||||
|
for (auto av = a.integer.rbegin(), bv = b.integer.rbegin(); av != a.integer.rend() && bv != b.integer.rend(); ++av, ++bv) {
|
||||||
|
int sum = *av + *bv + next;
|
||||||
|
int_result.insert(int_result.begin(), sum % 10);
|
||||||
|
next = sum / 10;
|
||||||
|
}
|
||||||
|
if (next != 0) int_result.insert(int_result.begin(), next);
|
||||||
|
res.integer = int_result;
|
||||||
|
res.floating = floating_result;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
triple operations::subtract(triple& a, triple& b) {
|
||||||
|
triple res;
|
||||||
|
int borrow = 0;
|
||||||
|
bool negative = false;
|
||||||
|
int int_size = max(a.integer.size(), b.integer.size());
|
||||||
|
int float_size = max(a.floating.size(), b.floating.size());
|
||||||
|
vector<int> int_result;
|
||||||
|
vector<int> floating_result;
|
||||||
|
while (a.integer.size() < int_size)
|
||||||
|
a.integer.insert(a.integer.begin(), 0);
|
||||||
|
while (b.integer.size() < int_size)
|
||||||
|
b.integer.insert(b.integer.begin(), 0);
|
||||||
|
while (a.floating.size() < float_size)
|
||||||
|
a.floating.push_back(0);
|
||||||
|
while (b.floating.size() < float_size)
|
||||||
|
b.floating.push_back(0);
|
||||||
|
|
||||||
|
if (a < b) {
|
||||||
|
swap(a, b);
|
||||||
|
negative = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.negative && !b.negative) {
|
||||||
|
res = a + b;
|
||||||
|
res.negative = true;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
else if (!a.negative && b.negative) {
|
||||||
|
res = a + b;
|
||||||
|
res.negative = false;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = float_size - 1, j = float_size - 1; i >= 0 || j >= 0; i--, j--) {
|
||||||
|
int digit1 = (i >= 0) ? a.floating[i] : 0;
|
||||||
|
int digit2 = (j >= 0) ? b.floating[j] : 0;
|
||||||
|
int diff = digit1 - digit2 - borrow;
|
||||||
|
if (diff < 0) {
|
||||||
|
diff += 10;
|
||||||
|
borrow = 1;
|
||||||
|
}
|
||||||
|
else borrow = 0;
|
||||||
|
floating_result.insert(floating_result.begin(), diff);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = int_size - 1, j = int_size - 1; i >= 0 || j >= 0; i--, j--) {
|
||||||
|
int digit1 = (i >= 0) ? a.integer[i] : 0;
|
||||||
|
int digit2 = (j >= 0) ? b.integer[j] : 0;
|
||||||
|
int diff = digit1 - digit2 - borrow;
|
||||||
|
if (diff < 0) {
|
||||||
|
diff += 10;
|
||||||
|
borrow = 1;
|
||||||
|
}
|
||||||
|
else borrow = 0;
|
||||||
|
int_result.insert(int_result.begin(), diff);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!int_result.empty() && int_result.front() == 0) int_result.erase(int_result.begin());
|
||||||
|
while (!floating_result.empty() && floating_result.back() == 0) floating_result.pop_back();
|
||||||
|
if (int_result.empty()) {
|
||||||
|
int_result.push_back(0);
|
||||||
|
}
|
||||||
|
res.negative = negative;
|
||||||
|
res.integer = int_result;
|
||||||
|
res.floating = floating_result;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
triple operations::multiply(triple& a, triple& b) {
|
||||||
|
triple res;
|
||||||
|
vector<int> int_result, floating_result;
|
||||||
|
vector<int> num1, num2;
|
||||||
|
int decimal = a.floating.size() + b.floating.size();
|
||||||
|
num1 = a.integer;
|
||||||
|
num2 = b.integer;
|
||||||
|
|
||||||
|
num1.insert(num1.end(), a.floating.begin(), a.floating.end());
|
||||||
|
num2.insert(num2.end(), b.floating.begin(), b.floating.end());
|
||||||
|
|
||||||
|
vector<int> result(num1.size() + num2.size());
|
||||||
|
|
||||||
|
if (a.negative && !b.negative || !a.negative && b.negative) res.negative = true;
|
||||||
|
|
||||||
|
for (int i = a.integer.size() + a.floating.size() - 1; i >= 0; i--) {
|
||||||
|
int carry = 0;
|
||||||
|
for (int j = b.integer.size() + b.floating.size() - 1; j >= 0; j--) {
|
||||||
|
int prod = num1[i] * num2[j] + result[i + j + 1] + carry;
|
||||||
|
result[i + j + 1] = prod % 10;
|
||||||
|
carry = prod / 10;
|
||||||
|
}
|
||||||
|
result[i] += carry;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (auto it = result.rbegin(); it != result.rend() && i < decimal; it++, i++)
|
||||||
|
floating_result.insert(floating_result.begin(), *it);
|
||||||
|
i = 0;
|
||||||
|
for (auto it = result.begin(); it != result.end() && i < result.size() - decimal; it++, i++)
|
||||||
|
int_result.push_back(*it);
|
||||||
|
|
||||||
|
while (!int_result.empty() && int_result.front() == 0) int_result.erase(int_result.begin());
|
||||||
|
while (!floating_result.empty() && floating_result.back() == 0) floating_result.pop_back();
|
||||||
|
res.integer = int_result;
|
||||||
|
res.floating = floating_result;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
triple operations::divide(triple& a, triple& b) {
|
||||||
|
vector<int> dividend;
|
||||||
|
vector<int> divisor;
|
||||||
|
for (auto i : a.integer) dividend.push_back(i);
|
||||||
|
for (auto i : a.floating) dividend.push_back(i);
|
||||||
|
for (auto i : b.integer) divisor.push_back(i);
|
||||||
|
for (auto i : b.floating) divisor.push_back(i);
|
||||||
|
if (a.floating.size() > b.floating.size()) {
|
||||||
|
int add = a.floating.size() - b.floating.size();
|
||||||
|
while (add--) divisor.push_back(0);
|
||||||
|
}
|
||||||
|
if (a.floating.size() < b.floating.size()) {
|
||||||
|
int add = b.floating.size() - a.floating.size();
|
||||||
|
while (add--) dividend.push_back(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
triple tempb;
|
||||||
|
int count = 0;
|
||||||
|
triple result;
|
||||||
|
result.integer = { 0 };
|
||||||
|
result.floating = {};
|
||||||
|
|
||||||
|
triple one;
|
||||||
|
triple ten;
|
||||||
|
triple zero;
|
||||||
|
zero.integer = { 0 };
|
||||||
|
zero.floating = { 0 };
|
||||||
|
ten.integer = { 1, 0 };
|
||||||
|
ten.floating = {};
|
||||||
|
one.integer = { 1 };
|
||||||
|
one.floating = { 0 };
|
||||||
|
|
||||||
|
triple res = a;
|
||||||
|
int currentPrecision = 0;
|
||||||
|
while (!(res < b)) {
|
||||||
|
tempb = b;
|
||||||
|
res = res - tempb;
|
||||||
|
if (!res.negative) result = result + one;
|
||||||
|
}
|
||||||
|
result.floating.clear();
|
||||||
|
bool first = false;
|
||||||
|
res.negative = false;
|
||||||
|
while (currentPrecision < precision) {
|
||||||
|
res.negative = false;
|
||||||
|
while (res < b && res != zero && res != b) {
|
||||||
|
if (res.integer.empty() && res.floating.empty() || (res.integer.size() == 1 && res.integer.at(0) == 0) && (res.floating.size() == 1 && res.floating.at(0) == 0)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (first) result.floating.push_back(0);
|
||||||
|
first = true;
|
||||||
|
res = res * ten;
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
count = 0;
|
||||||
|
while (!(res < b) && !(res == zero)) {
|
||||||
|
tempb = b;
|
||||||
|
res = res - tempb;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
res.negative = false;
|
||||||
|
if (count != 0) result.floating.push_back(count);
|
||||||
|
currentPrecision++;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
triple operator+(triple& a,triple& b) {
|
||||||
|
operations op;
|
||||||
|
triple res = op.add(a, b);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
triple operator-(triple& a, triple& b) {
|
||||||
|
operations op;
|
||||||
|
triple res = op.subtract(a, b);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
triple operator*(triple& a, triple& b) {
|
||||||
|
operations op;
|
||||||
|
triple res = op.multiply(a, b);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
triple operator/(triple& a, triple& b) {
|
||||||
|
operations op;
|
||||||
|
triple res = op.divide(a, b);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
14
Lab/operations.h
Normal file
14
Lab/operations.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
#include "triple.h"
|
||||||
|
|
||||||
|
class operations {
|
||||||
|
public:
|
||||||
|
triple add(triple& a, triple& b) ;
|
||||||
|
triple subtract(triple& a, triple& b);
|
||||||
|
triple multiply(triple& a, triple& b);
|
||||||
|
triple divide(triple& a, triple& b);
|
||||||
|
friend triple operator+(triple& a, triple& b);
|
||||||
|
friend triple operator-(triple& a, triple& b);
|
||||||
|
};
|
||||||
132
Lab/triple.cpp
Normal file
132
Lab/triple.cpp
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include "triple.h"
|
||||||
|
#include "operations.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool negative = false;
|
||||||
|
vector<int> integer;
|
||||||
|
vector<int> floating;
|
||||||
|
int decimal_pos = -1;
|
||||||
|
|
||||||
|
void triple::input() {
|
||||||
|
std::string line;
|
||||||
|
std::getline(std::cin, line);
|
||||||
|
|
||||||
|
bool negative = false;
|
||||||
|
if (line[0] == '-') {
|
||||||
|
negative = true;
|
||||||
|
line = line.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
decimal_pos = line.find('.');
|
||||||
|
if (decimal_pos != std::string::npos) {
|
||||||
|
std::transform(line.begin(), line.begin() + decimal_pos, std::back_inserter(integer),
|
||||||
|
[](char c) { return c - '0'; });
|
||||||
|
std::transform(line.begin() + decimal_pos + 1, line.end(), std::back_inserter(floating),
|
||||||
|
[](char c) { return c - '0'; });
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::transform(line.begin(), line.end(), std::back_inserter(integer),
|
||||||
|
[](char c) { return c - '0'; });
|
||||||
|
}
|
||||||
|
|
||||||
|
this->negative = negative;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void triple::print() {
|
||||||
|
if (negative) cout << '-';
|
||||||
|
for (int i : integer) cout << i;
|
||||||
|
if (floating.size() == 0) {
|
||||||
|
cout << ".0";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cout << '.';
|
||||||
|
for (int x : floating) cout << x;
|
||||||
|
}
|
||||||
|
cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
istream& operator>>(istream& in, triple& hf) {
|
||||||
|
hf.input();
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& out, triple& hf) {
|
||||||
|
hf.print();
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<(triple& a, triple& b) {
|
||||||
|
if (a.negative && !b.negative) return true;
|
||||||
|
if (!a.negative && b.negative) return false;
|
||||||
|
if (a.negative && b.negative) {
|
||||||
|
swap(a, b);
|
||||||
|
}
|
||||||
|
int int_size_a = a.integer.size();
|
||||||
|
int int_size_b = b.integer.size();
|
||||||
|
if (int_size_a != int_size_b) {
|
||||||
|
return int_size_a < int_size_b;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < int_size_a; ++i) {
|
||||||
|
if (a.integer[i] != b.integer[i]) {
|
||||||
|
return a.integer[i] < b.integer[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int float_size_a = a.floating.size();
|
||||||
|
int float_size_b = b.floating.size();
|
||||||
|
if (float_size_a != float_size_b) {
|
||||||
|
return float_size_a < float_size_b;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < float_size_a; ++i) {
|
||||||
|
if (a.floating[i] != b.floating[i]) {
|
||||||
|
return a.floating[i] < b.floating[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>(triple& a, triple& b) {
|
||||||
|
if (a.negative && !b.negative) return false;
|
||||||
|
if (!a.negative && b.negative) return true;
|
||||||
|
if (a.negative && b.negative) {
|
||||||
|
swap(a, b);
|
||||||
|
}
|
||||||
|
int int_size_a = a.integer.size();
|
||||||
|
int int_size_b = b.integer.size();
|
||||||
|
if (int_size_a != int_size_b) {
|
||||||
|
return int_size_a < int_size_b;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < int_size_a; ++i) {
|
||||||
|
if (a.integer[i] != b.integer[i]) {
|
||||||
|
return a.integer[i] > b.integer[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int float_size_a = a.floating.size();
|
||||||
|
int float_size_b = b.floating.size();
|
||||||
|
if (float_size_a != float_size_b) {
|
||||||
|
return float_size_a > float_size_b;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < float_size_a; ++i) {
|
||||||
|
if (a.floating[i] != b.floating[i]) {
|
||||||
|
return a.floating[i] > b.floating[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(triple& a, triple& b) {
|
||||||
|
if (a.integer == b.integer && a.floating == b.floating) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(triple& a, triple& b) {
|
||||||
|
if (a.integer == b.integer && a.floating == b.floating) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
31
Lab/triple.h
Normal file
31
Lab/triple.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef TRIPLE_H
|
||||||
|
#define TRIPLE_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class triple {
|
||||||
|
public:
|
||||||
|
bool negative;
|
||||||
|
std::vector<int> integer;
|
||||||
|
std::vector<int> floating;
|
||||||
|
int decimal_pos;
|
||||||
|
void input();
|
||||||
|
void print();
|
||||||
|
friend istream& operator>>(istream& in, triple& hf);
|
||||||
|
friend ostream& operator<<(ostream& out, triple& hf);
|
||||||
|
friend triple operator+(triple& a, triple& b);
|
||||||
|
friend triple operator-(triple& a, triple& b);
|
||||||
|
friend triple operator*(triple& a, triple& b);
|
||||||
|
friend triple operator/(triple& a, triple& b);
|
||||||
|
friend bool operator<(triple& a, triple& b);
|
||||||
|
friend bool operator>(triple& a, triple& b);
|
||||||
|
friend bool operator==(triple& a, triple& b);
|
||||||
|
friend bool operator!=(triple& a, triple& b);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user