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

coordinates #41

Open
wants to merge 1 commit 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
68 changes: 68 additions & 0 deletions Students/Nosov.AA/coordinates/coor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "headers.h"

ostream& operator<<(ostream& os, const CoordDecart& dec)
{
os <<"x: " << dec.m_x << " y: " << dec.m_y;
return os;
}

istream& operator>>(istream& is, CoordDecart& dec)
{
is >> dec.m_x >> dec.m_y;
return is;
}
CoordDecart::CoordDecart(double x, double y) {
Set(x, y);
}
void CoordDecart::Set(double x, double y) {
m_x = x;
m_y = y;
}

double CoordDecart::GetX() {
return m_x;
}
double CoordDecart::GetY() {
return m_y;
}

CoordPolar CoordDecart::ToPolar() {
return CoordPolar(sqrt(m_x*m_x + m_y*m_y), atan(m_y / m_x));
}

///////////////////////////////////////////////////////////////////////////////

ostream& operator<<(ostream& os, const CoordPolar& pol)
{
os <<"r: "<< pol.m_r << " ang: " << pol.m_ang;
return os;
}
istream& operator>>(istream& is, CoordPolar& pol)
{
is >> pol.m_r >> pol.m_ang;
return is;
}
CoordPolar::CoordPolar(double r, double ang) {
Set(r, ang);

}

CoordDecart CoordPolar::ToDecart() {
return CoordDecart(m_r*cos(m_ang), m_r*sin(m_ang));
}


void CoordPolar::Set(double r, double ang) {
if ((ang >= 0) && (ang <= 360)) {
m_ang = ang;
m_r = r;
}
else
throw "incorrect values";
}
double CoordPolar::GetX() {
return m_r;
}
double CoordPolar::GetY() {
return m_ang;
}
88 changes: 88 additions & 0 deletions Students/Nosov.AA/coordinates/coordinates.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" 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>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{922A6676-E951-4D80-B2B9-4E6D1705CB0C}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>coordinates</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</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>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="headers.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="coor.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
51 changes: 51 additions & 0 deletions Students/Nosov.AA/coordinates/headers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once
#include <iostream>
#include <cmath>
using namespace std;

class ICoord {
public:
virtual void Set(double num1, double num2) = 0;
virtual double GetX() = 0;
virtual double GetY() = 0;
virtual ~ICoord(){}

};

class CoordPolar;

class CoordDecart :public ICoord {
private:
double m_x, m_y;
public:
void Set(double x, double y) override;
double GetX() override;
double GetY() override;
CoordPolar ToPolar();
CoordDecart(double x, double y);
~CoordDecart(){}
friend ostream& operator<<(ostream& os, const CoordDecart& dec);
friend istream& operator>>(istream& is, CoordDecart& dec);

};



class CoordPolar :public ICoord {
private:
double m_r, m_ang;
public:
void Set(double r, double ang) override;
double GetX() override;
double GetY() override;
CoordDecart ToDecart();
CoordPolar(double r, double ang);
~CoordPolar(){}
friend ostream& operator<<(ostream& os, const CoordPolar& pol);
friend istream& operator>>(istream& is, CoordPolar& pol);
};





23 changes: 23 additions & 0 deletions Students/Nosov.AA/coordinates/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "headers.h"



int main(){
CoordDecart a(1, 0);
cout << a << endl;
a.Set(0, 1);
cout << a << endl;
cout << "_______________________" << endl;

CoordPolar b(2, 30);
cout << b << endl;
b.Set(3, 45);
cout << b << endl;
cout << "_______________________" << endl;

ICoord *someCoord = new CoordDecart(5, 3);
cout << "ICoord" << endl << "x: " << someCoord->GetX() << " y: " << someCoord->GetY() << endl;
someCoord->Set(1, 1);
cout << "ICoord" << endl << "x: " << someCoord->GetX() << " y: " << someCoord->GetY() << endl;
delete someCoord;
}