Skip to content
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
Binary file added Equel/.vs/Equel/v15/.suo
Binary file not shown.
Binary file added Equel/.vs/Equel/v16/.suo
Binary file not shown.
Binary file added Equel/.vs/Equel/v16/Browse.VC.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions Equel/.vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": "No Configurations"
}
7 changes: 7 additions & 0 deletions Equel/.vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\Equel.sln",
"PreviewInSolutionExplorer": false
}
Binary file added Equel/.vs/slnx.sqlite
Binary file not shown.
Binary file added Equel/Debug/Equel.ilk
Binary file not shown.
Binary file added Equel/Debug/Equel.pdb
Binary file not shown.
31 changes: 31 additions & 0 deletions Equel/Equel.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2043
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Equel", "Equel\Equel.vcxproj", "{FE06C801-59C7-4732-80E8-C2FF84675DD8}"
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
{FE06C801-59C7-4732-80E8-C2FF84675DD8}.Debug|x64.ActiveCfg = Debug|x64
{FE06C801-59C7-4732-80E8-C2FF84675DD8}.Debug|x64.Build.0 = Debug|x64
{FE06C801-59C7-4732-80E8-C2FF84675DD8}.Debug|x86.ActiveCfg = Debug|Win32
{FE06C801-59C7-4732-80E8-C2FF84675DD8}.Debug|x86.Build.0 = Debug|Win32
{FE06C801-59C7-4732-80E8-C2FF84675DD8}.Release|x64.ActiveCfg = Release|x64
{FE06C801-59C7-4732-80E8-C2FF84675DD8}.Release|x64.Build.0 = Release|x64
{FE06C801-59C7-4732-80E8-C2FF84675DD8}.Release|x86.ActiveCfg = Release|Win32
{FE06C801-59C7-4732-80E8-C2FF84675DD8}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {44F85693-50C9-45A3-B804-D03B0A2F2B8A}
EndGlobalSection
EndGlobal
231 changes: 231 additions & 0 deletions Equel/Equel/CubEq.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
#include "CubEq.h"
#include <fstream>


CubEq::CubEq()
{
inputCoef();

Zmist();

compSQR();

computeN();

if (n != 0 || n != 255)
{
x = new double[n];
}

solve();
}


CubEq::CubEq(double const a, double const b, double const c, double const d)
{
this->a = a;
this->b = b;
this->c = c;
this->d = d;

Zmist();

compSQR();

computeN();

if (n != 0 || n != 255)
{
x = new double[n];
}

solve();
}



CubEq::~CubEq()
{
delete[] x;
x = nullptr;
}


void CubEq::compSQR()
{
Q = (b*b - 3*c)/9;
R = (2*b*b*b - 9*b*c + 27*d)/54;
S = Q * Q * Q - R * R;
//std::cout << S << std::endl;
//std::cout << Q << std::endl;
//std::cout << R << std::endl;
}


void CubEq::Zmist()
{
if (a != 0)
{
b = b / a;
c = c / a;
d = d / a;
a = 1;
}
}


void CubEq::computeN()
{
if (a != 0)
{
if (S >= 0)
{
n = 3;
}
else
{
n = 1;
}
}
else
{
SquareEq* sq = new SquareEq(b, c, d);
n = sq->GetN();

}
}


void CubEq::solve()
{
//std::cout << "\n\tStart solve!" << std::endl;

if (a == 0)
{
if (b == 0)
{
LinearEq* linear = new LinearEq(c, d);

x[0] = linear->getX();
n = linear->getN();
//std::cout << "We are in cycle " << x[0];

}
else
{

SquareEq* sq = new SquareEq(b, c, d);

x = sq->GetX();
}
}
else
{
if (S > 0)
{
double fi;
//std::cout << "fi_under = " << R / sqrt(Q * Q * Q) << std::endl;
//std::cout << "acos = " << acos(-0.7638) << std::endl;
fi = acos(R / sqrt(Q * Q * Q))/3;
//std::cout << "fi = " << fi << std::endl;
x[0] = -2 * sqrt(Q) * cos(fi) - b / 3;
//std::cout << "x[0] = " << x[0];
x[1] = -2 * sqrt(Q) * cos(fi - 2*M_PI/3) - b / 3;
x[2] = -2 * sqrt(Q) * cos(fi + 2*M_PI/3) - b / 3;
}
else if (S == 0)
{
//std::cout << "We are in cycle " << x[0];
x[0] = -2*cbrt(R) - b / 3;
x[1] = cbrt(R) - b / 3;
x[2] = cbrt(R) - b / 3;
}
else
{
//std::cout << "We are in cycle " << x[0];
if (Q > 0)
{
double fi;
fi = acosh(abs(R) / sqrt(Q * Q * Q)) / 3;
x[0] = -2 * R / abs(R) * sqrt(Q) * cosh(fi) - b / 3;
}
else if (Q < 0)
{
//std::cout << "We are in cycle " << x[0];
double fi;
fi = asinh(abs(R) / sqrt(abs(Q * Q * Q))) / 3;
x[0] = -2 * R / abs(R) * sqrt(abs(Q)) * sinh(fi) - b / 3;
}
else
{
x[0] = -cbrt(d - b * b * b / 27) - b / 3;
}
}
}
}


void CubEq::showX()
{
if (n == 255)
{
std::cout << "\t\t-We have to many solves!" << std::endl;
}
else if (n == 0)
{
std::cout << "\t\t-We have no solves!" << std::endl;
}
else
{
std::cout << "\t\t-Our solves are:\n";
for (int i = 0; i < n; i++)
{
std::cout << "\t\t\tx[" << i << "] = " << x[i] << std::endl;
}
}
}

double* CubEq::GetX()
{
return x;
}


void CubEq::inputCoef()
{
std::cout << "\tPlease, input a = ?\b";
while (!(std::cin >> a))
{
std::cin.clear();

std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "\t\t-Invalid input. Try aganin: ";
}

std::cout << "\tPlease, input b = ?\b";
while (!(std::cin >> b))
{
std::cin.clear();

std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "\t\t-Invalid input. Try aganin: ";
}

std::cout << "\tPlease, input c = ?\b";
while (!(std::cin >> c))
{
std::cin.clear();

std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "\t\t-Invalid input. Try aganin: ";
}

std::cout << "\tPlease, input d = ?\b";
while (!(std::cin >> d))
{
std::cin.clear();

std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "\t\t-Invalid input. Try aganin: ";
}
}
29 changes: 29 additions & 0 deletions Equel/Equel/CubEq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include "Equation.h"
#include "LinearEq.h"
#include "SquareEq.h"
#include <iostream>
#include <cmath>
#define _USE_MATH_DEFINES
#include <math.h>

class CubEq : public Equation
{
public:
CubEq();
CubEq(double const, double const, double const, double const);
~CubEq();

void showX() override;

double* GetX();

private:
double a, b, c, d, S, Q, R;
void solve() override;
void computeN() override;
void inputCoef() override;
void compSQR();
void Zmist();

};
12 changes: 12 additions & 0 deletions Equel/Equel/CubEquation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "CubEquation.h"



CubEquation::CubEquation()
{
}


CubEquation::~CubEquation()
{
}
2 changes: 2 additions & 0 deletions Equel/Equel/CubEquation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


5 changes: 5 additions & 0 deletions Equel/Equel/Debug/Equel.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
 LinearEq.cpp
Source.cpp
SquareEq.cpp
Generating Code...
Equel.vcxproj -> c:\Users\Roman\source\repos\Equel\Debug\Equel.exe
Binary file added Equel/Equel/Debug/Equel.tlog/CL.command.1.tlog
Binary file not shown.
Binary file added Equel/Equel/Debug/Equel.tlog/CL.read.1.tlog
Binary file not shown.
Binary file added Equel/Equel/Debug/Equel.tlog/CL.write.1.tlog
Binary file not shown.
2 changes: 2 additions & 0 deletions Equel/Equel/Debug/Equel.tlog/Equel.lastbuildstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.16299.0
Debug|Win32|c:\Users\Roman\source\repos\Equel\|
Binary file added Equel/Equel/Debug/Equel.tlog/link.command.1.tlog
Binary file not shown.
Binary file added Equel/Equel/Debug/Equel.tlog/link.read.1.tlog
Binary file not shown.
Binary file added Equel/Equel/Debug/Equel.tlog/link.write.1.tlog
Binary file not shown.
Binary file added Equel/Equel/Debug/vc141.idb
Binary file not shown.
Binary file added Equel/Equel/Debug/vc141.pdb
Binary file not shown.
16 changes: 16 additions & 0 deletions Equel/Equel/Equation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include <iostream>
class Equation
{
public:
virtual void showX() = 0;
int getN() { return n; }

protected:
int n;
double *x;

virtual void solve() = 0;
virtual void computeN() = 0;
virtual void inputCoef() = 0;
};
Loading