-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
863 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29926.136 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Complex", "Complex\Complex.vcxproj", "{C24F982D-5F7D-459D-8025-6B57E59B41DA}" | ||
EndProject | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Complex_Tests", "..\Complex_Tests\Complex_Tests.vcxproj", "{4681918E-6C97-450A-B927-C4B4D457FC95}" | ||
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 | ||
{C24F982D-5F7D-459D-8025-6B57E59B41DA}.Debug|x64.ActiveCfg = Debug|x64 | ||
{C24F982D-5F7D-459D-8025-6B57E59B41DA}.Debug|x64.Build.0 = Debug|x64 | ||
{C24F982D-5F7D-459D-8025-6B57E59B41DA}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{C24F982D-5F7D-459D-8025-6B57E59B41DA}.Debug|x86.Build.0 = Debug|Win32 | ||
{C24F982D-5F7D-459D-8025-6B57E59B41DA}.Release|x64.ActiveCfg = Release|x64 | ||
{C24F982D-5F7D-459D-8025-6B57E59B41DA}.Release|x64.Build.0 = Release|x64 | ||
{C24F982D-5F7D-459D-8025-6B57E59B41DA}.Release|x86.ActiveCfg = Release|Win32 | ||
{C24F982D-5F7D-459D-8025-6B57E59B41DA}.Release|x86.Build.0 = Release|Win32 | ||
{4681918E-6C97-450A-B927-C4B4D457FC95}.Debug|x64.ActiveCfg = Debug|x64 | ||
{4681918E-6C97-450A-B927-C4B4D457FC95}.Debug|x64.Build.0 = Debug|x64 | ||
{4681918E-6C97-450A-B927-C4B4D457FC95}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{4681918E-6C97-450A-B927-C4B4D457FC95}.Debug|x86.Build.0 = Debug|Win32 | ||
{4681918E-6C97-450A-B927-C4B4D457FC95}.Release|x64.ActiveCfg = Release|x64 | ||
{4681918E-6C97-450A-B927-C4B4D457FC95}.Release|x64.Build.0 = Release|x64 | ||
{4681918E-6C97-450A-B927-C4B4D457FC95}.Release|x86.ActiveCfg = Release|Win32 | ||
{4681918E-6C97-450A-B927-C4B4D457FC95}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {A598DE0F-34B7-4175-990B-D4B7179FDCE9} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#include "CComplex.h" | ||
|
||
CComplex::CComplex(double real, double image) | ||
: m_real(real), m_image(image) | ||
{ | ||
} | ||
|
||
double CComplex::Re() const | ||
{ | ||
return m_real; | ||
} | ||
|
||
double CComplex::Im() const | ||
{ | ||
return m_image; | ||
} | ||
|
||
double CComplex::GetMagnitude() const | ||
{ | ||
return sqrt(pow(Re(), 2) + pow(Im(), 2)); | ||
} | ||
|
||
double CComplex::GetArgument() const | ||
{ | ||
return atan(Im() / Re()); | ||
} | ||
|
||
CComplex const operator+(const CComplex& first, const CComplex& second) | ||
{ | ||
return CComplex(first.Re() + second.Re(), first.Im() + second.Im()); | ||
} | ||
|
||
CComplex const operator-(const CComplex& first, const CComplex& second) | ||
{ | ||
return CComplex(first.Re() - second.Re(), first.Im() - second.Im()); | ||
} | ||
|
||
CComplex const operator*(const CComplex& first, const CComplex& second) | ||
{ | ||
double real = first.Re() * second.Re() - first.Im() * second.Im(); | ||
double image = first.Re() * second.Im() + first.Im() * second.Re(); | ||
return CComplex(real, image); | ||
} | ||
|
||
CComplex const operator/(const CComplex& first, const CComplex& second) | ||
{ | ||
if (second.Re() == 0 && second.Im() == 0) | ||
{ | ||
throw std::invalid_argument("Division by 0"); | ||
} | ||
|
||
double real = (first.Re() * second.Re() + first.Im() * second.Im()) / (pow(second.Re(), 2) + pow(second.Im(), 2)); | ||
double image = (second.Re() * first.Im() - first.Re() * second.Im()) / (pow(second.Re(), 2) + pow(second.Im(), 2)); | ||
return CComplex(real, image); | ||
} | ||
|
||
CComplex const CComplex::operator +() const | ||
{ | ||
return *this; | ||
} | ||
|
||
CComplex const CComplex::operator -() const | ||
{ | ||
return CComplex(-m_real, -m_image); | ||
} | ||
|
||
CComplex& CComplex::operator+=(const CComplex& first) | ||
{ | ||
*this = *this + first; | ||
return *this; | ||
} | ||
|
||
CComplex& CComplex::operator-=(const CComplex& first) | ||
{ | ||
*this = *this - first; | ||
return *this; | ||
} | ||
|
||
CComplex& CComplex::operator*=(const CComplex& first) | ||
{ | ||
*this = *this * first; | ||
return *this; | ||
} | ||
|
||
CComplex& CComplex::operator/=(const CComplex& first) | ||
{ | ||
*this = *this / first; | ||
return *this; | ||
} | ||
|
||
bool CComplex::operator==(const CComplex& first) const | ||
{ | ||
return ((fabs(Re() - first.Re()) < DBL_MIN) && (fabs(Im() - first.Im()) < DBL_MIN)); | ||
} | ||
|
||
bool CComplex::operator!=(const CComplex& first) const | ||
{ | ||
return !(*this == first); | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, const CComplex& complex) | ||
{ | ||
os << complex.Re(); | ||
if (complex.Im() >= 0) | ||
{ | ||
os << "+"; | ||
} | ||
os << complex.Im() << "i"; | ||
|
||
return os; | ||
} | ||
|
||
std::istream& operator>>(std::istream& is, CComplex& complex) | ||
{ | ||
double real, image; | ||
|
||
if ((is >> real) && (is >> image) && (is.get() == 'i')) | ||
{ | ||
complex = CComplex(real, image); | ||
} | ||
else | ||
{ | ||
is.setstate(std::ios_base::failbit); | ||
} | ||
|
||
return is; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
#include <cmath> | ||
#include "math.h" | ||
#include "float.h" | ||
#include <fstream> | ||
|
||
class CComplex | ||
{ | ||
public: | ||
CComplex(double real = 0, double image = 0); | ||
double Re() const; | ||
double Im() const; | ||
double GetMagnitude() const; | ||
double GetArgument() const; | ||
|
||
CComplex const operator +()const; | ||
CComplex const operator -()const; | ||
|
||
CComplex& operator+=(const CComplex& first); | ||
CComplex& operator-=(const CComplex& first); | ||
CComplex& operator*=(const CComplex& first); | ||
CComplex& operator/=(const CComplex& first); | ||
|
||
bool operator==(const CComplex& first) const; | ||
bool operator!=(const CComplex& first) const; | ||
private: | ||
double m_real; | ||
double m_image; | ||
}; | ||
|
||
CComplex const operator+(const CComplex& first, const CComplex& second); | ||
CComplex const operator-(const CComplex& first, const CComplex& second); | ||
CComplex const operator*(const CComplex& first, const CComplex& second); | ||
CComplex const operator/(const CComplex& first, const CComplex& second); | ||
|
||
std::ostream& operator<<(std::ostream& os, const CComplex& complex); | ||
std::istream& operator>>(std::istream& is, CComplex& complex); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <iostream> | ||
#include <sstream> | ||
#include "CComplex.h" | ||
|
||
int main() | ||
{ | ||
std::string line; | ||
|
||
while (getline(std::cin, line)) | ||
{ | ||
std::istringstream ss(line); | ||
CComplex complex; | ||
|
||
ss >> complex; | ||
std::cout << complex << std::endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> | ||
<ProjectGuid>{C24F982D-5F7D-459D-8025-6B57E59B41DA}</ProjectGuid> | ||
<Keyword>Win32Proj</Keyword> | ||
<RootNamespace>Complex</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)'=='Debug|x64'"> | ||
<LinkIncremental>true</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
</PropertyGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<PrecompiledHeader> | ||
</PrecompiledHeader> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<LanguageStandard>stdcpp17</LanguageStandard> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<PrecompiledHeader> | ||
</PrecompiledHeader> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<LanguageStandard>stdcpp17</LanguageStandard> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<PrecompiledHeader> | ||
</PrecompiledHeader> | ||
<WarningLevel>Level3</WarningLevel> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<LanguageStandard>stdcpp17</LanguageStandard> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<PrecompiledHeader> | ||
</PrecompiledHeader> | ||
<WarningLevel>Level3</WarningLevel> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<LanguageStandard>stdcpp17</LanguageStandard> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClCompile Include="CComplex.cpp" /> | ||
<ClCompile Include="Complex.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="CComplex.h" /> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
Oops, something went wrong.