Добавьте файлы проекта.
This commit is contained in:
parent
f2cf13f7ba
commit
e0e0ed92bb
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32922.545
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OOP_zadanie2", "OOP_zadanie2\OOP_zadanie2.vcxproj", "{F1EE78B0-3E12-496C-8532-C6C16A090AEE}"
|
||||
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
|
||||
{F1EE78B0-3E12-496C-8532-C6C16A090AEE}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{F1EE78B0-3E12-496C-8532-C6C16A090AEE}.Debug|x64.Build.0 = Debug|x64
|
||||
{F1EE78B0-3E12-496C-8532-C6C16A090AEE}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{F1EE78B0-3E12-496C-8532-C6C16A090AEE}.Debug|x86.Build.0 = Debug|Win32
|
||||
{F1EE78B0-3E12-496C-8532-C6C16A090AEE}.Release|x64.ActiveCfg = Release|x64
|
||||
{F1EE78B0-3E12-496C-8532-C6C16A090AEE}.Release|x64.Build.0 = Release|x64
|
||||
{F1EE78B0-3E12-496C-8532-C6C16A090AEE}.Release|x86.ActiveCfg = Release|Win32
|
||||
{F1EE78B0-3E12-496C-8532-C6C16A090AEE}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {19247390-9641-4A6D-B47D-CB3ECF34D880}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Triangle.h"
|
||||
#include "UserInput.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
UserInteraction userInteraction;
|
||||
userInteraction.interaction();
|
||||
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
<?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>{f1ee78b0-3e12-496c-8532-c6c16a090aee}</ProjectGuid>
|
||||
<RootNamespace>OOPzadanie2</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>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</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" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</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>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
</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>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Main.cpp" />
|
||||
<ClCompile Include="Triangle.cpp" />
|
||||
<ClCompile Include="UserInput.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Triangle.h" />
|
||||
<ClInclude Include="UserInput.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Исходные файлы">
|
||||
<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="Файлы заголовков">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Файлы ресурсов">
|
||||
<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="Main.cpp">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Triangle.cpp">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="UserInput.cpp">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Triangle.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="UserInput.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1 @@
|
|||
#include "Triangle.h"
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Triangle
|
||||
{
|
||||
private:
|
||||
double a, b, c;
|
||||
|
||||
public:
|
||||
Triangle() {
|
||||
this->a = 0;
|
||||
this->b = 0;
|
||||
this->c = 0;
|
||||
}
|
||||
Triangle(double a, double b, double c) {
|
||||
this->a = a;
|
||||
this->b = b;
|
||||
this->c = c;
|
||||
}
|
||||
~Triangle() {}
|
||||
|
||||
double getA() {
|
||||
return this->a;
|
||||
}
|
||||
double getB() {
|
||||
return this->b;
|
||||
}
|
||||
double getC() {
|
||||
return this->c;
|
||||
}
|
||||
|
||||
void setA(double a) {
|
||||
this->a = a;
|
||||
}
|
||||
void setB(double b) {
|
||||
this->b = b;
|
||||
}
|
||||
void setC(double c) {
|
||||
this->c = c;
|
||||
}
|
||||
|
||||
vector<double> increaseSidesInGivenTimes(double multiplier) {
|
||||
this->setA(this->a * multiplier);
|
||||
this->setB(this->b * multiplier);
|
||||
this->setC(this->c * multiplier);
|
||||
return vector<double> {
|
||||
this->a,
|
||||
this->b,
|
||||
this->c,
|
||||
};
|
||||
}
|
||||
|
||||
vector<double> decreaseSidesInGivenTimes(double divisor) {
|
||||
this->setA(this->a / divisor);
|
||||
this->setB(this->b / divisor);
|
||||
this->setC(this->c / divisor);
|
||||
return vector<double> {
|
||||
this->a,
|
||||
this->b,
|
||||
this->c,
|
||||
};
|
||||
}
|
||||
|
||||
double getPerimeter() {
|
||||
return (
|
||||
this->a + \
|
||||
this->b + \
|
||||
this->c
|
||||
);
|
||||
}
|
||||
|
||||
//Heron's formula
|
||||
double getArea() {
|
||||
|
||||
double semiperimeter = (this->getPerimeter() / 2);
|
||||
|
||||
return (
|
||||
sqrt(
|
||||
semiperimeter * \
|
||||
(semiperimeter - this->a) * \
|
||||
(semiperimeter - this->b) * \
|
||||
(semiperimeter - this->c)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
vector<double> getAngles() {
|
||||
|
||||
double angleBetween_a_and_c = acos(
|
||||
(
|
||||
pow(this->a, 2) + \
|
||||
pow(this->c, 2) - \
|
||||
pow(this->b, 2)
|
||||
) / (2 * this->a * this->c)
|
||||
) * (180.0 / 3.141592653589793238463);
|
||||
|
||||
double angleBetween_a_and_b = acos(
|
||||
(
|
||||
pow(this->a, 2) + \
|
||||
pow(this->b, 2) - \
|
||||
pow(this->c, 2)
|
||||
) / (2 * this->a * this->b)
|
||||
) * (180.0 / 3.141592653589793238463);
|
||||
|
||||
double angleBetween_b_and_c = acos(
|
||||
(
|
||||
pow(this->b, 2) + \
|
||||
pow(this->c, 2) - \
|
||||
pow(this->a, 2)
|
||||
) / (2 * this->c * this->b)
|
||||
) * (180.0 / 3.141592653589793238463);
|
||||
|
||||
return vector<double> {
|
||||
angleBetween_a_and_c,
|
||||
angleBetween_a_and_b,
|
||||
angleBetween_b_and_c,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
#include "UserInput.h"
|
||||
|
|
@ -0,0 +1,146 @@
|
|||
#pragma once
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "Triangle.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class UserInteraction
|
||||
{
|
||||
private:
|
||||
Triangle* triangle_ptr;
|
||||
|
||||
vector<double> triangleSideValueList = {};
|
||||
vector<string> triangleSideNameList = { "a","b","c" };
|
||||
string input;
|
||||
|
||||
void printCurrentTriangleSides() {
|
||||
cout << "\nTriangle sides are:\n" << \
|
||||
"a = " + to_string(triangle_ptr->getA()) + "\n" << \
|
||||
"b = " + to_string(triangle_ptr->getB()) + "\n" << \
|
||||
"c = " + to_string(triangle_ptr->getC()) + "\n\n";
|
||||
};
|
||||
|
||||
void inputTriangleSides() {
|
||||
|
||||
for (size_t i = 0; i < triangleSideNameList.size(); i++)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
cout << "Enter triangle's side " << triangleSideNameList[i] << ":" << endl;
|
||||
cin >> this->input;
|
||||
if (validateInput(this->input, triangleSideNameList[i])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
triangle_ptr = new Triangle(
|
||||
triangleSideValueList[0],
|
||||
triangleSideValueList[1],
|
||||
triangleSideValueList[2]
|
||||
);
|
||||
}
|
||||
|
||||
bool validateInput(string input, string sideName) {
|
||||
try
|
||||
{
|
||||
double tmp = stod(input);
|
||||
|
||||
if (sideName == "c") {
|
||||
double sumOfSides_a_And_b = this->triangleSideValueList[0] + this->triangleSideValueList[1];
|
||||
auto smallestSide = *min_element(triangleSideValueList.begin(), triangleSideValueList.end());
|
||||
if (
|
||||
tmp < sumOfSides_a_And_b && \
|
||||
tmp > smallestSide
|
||||
) {
|
||||
triangleSideValueList.push_back(tmp);
|
||||
return true;
|
||||
}
|
||||
string const exceptionMsg = "Side 'c' must be more than " + to_string(smallestSide) + " and less than " + to_string(sumOfSides_a_And_b);
|
||||
throw runtime_error(exceptionMsg);
|
||||
}
|
||||
if (tmp > 0) {
|
||||
triangleSideValueList.push_back(tmp);
|
||||
return true;
|
||||
}
|
||||
throw exception("Triangle side must be positive number.\n");
|
||||
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
cout << e.what() << endl \
|
||||
<< "Enter a positive number: \n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void doOperations() {
|
||||
|
||||
string operationNumber;
|
||||
double multiplicator;
|
||||
|
||||
while (true) {
|
||||
cout << "Enter number to perform operations:\n" << \
|
||||
"1 - Increase triangle sides in given times\n" << \
|
||||
"2 - Decrease triangle sides in given times\n" << \
|
||||
"3 - Calculate trianle's perimeter\n" << \
|
||||
"4 - Calculate trianle's area\n" << \
|
||||
"5 - Calculate trianle's angles\n" << \
|
||||
"Operation number:";
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
cin >> operationNumber;
|
||||
switch (stoi(operationNumber))
|
||||
{
|
||||
case 1:
|
||||
cout << "\nEnter multiplicator: " << endl;
|
||||
cin >> multiplicator;
|
||||
triangle_ptr->increaseSidesInGivenTimes(multiplicator);
|
||||
printCurrentTriangleSides();
|
||||
break;
|
||||
case 2:
|
||||
cout << "\nEnter divisor: " << endl;
|
||||
cin >> multiplicator;
|
||||
triangle_ptr->decreaseSidesInGivenTimes(multiplicator);
|
||||
printCurrentTriangleSides();
|
||||
break;
|
||||
case 3:
|
||||
cout << "\nTriangle's perimeter = " << triangle_ptr->getPerimeter() << endl << endl;
|
||||
break;
|
||||
case 4:
|
||||
cout << "\nTriangle's area = " << triangle_ptr->getArea() << endl << endl;
|
||||
break;
|
||||
case 5:
|
||||
cout << endl;
|
||||
for (size_t i = 0; i < triangle_ptr->getAngles().size(); i++)
|
||||
{
|
||||
cout << "Triangle's angle = " << triangle_ptr->getAngles()[i] << "\n";
|
||||
}
|
||||
cout << endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
public:
|
||||
void interaction() {
|
||||
while (true)
|
||||
{
|
||||
inputTriangleSides();
|
||||
printCurrentTriangleSides();
|
||||
doOperations();
|
||||
}
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue