- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
#include <iostream>
#include <cmath>
#include <iomanip>
#include "govno.h"
using namespace std;
void prnt_msg_start() {
cout << endl << "Программа решения квадратного уравнения по формуле: ";
cout << "aX^2 + bX + c = 0" << endl;
cout << setprecision(69) << endl; }
long double ks[] = {1, 2, 1, 3, 10, 2};
class SqrtQual {
const string msg_not_roots = "Нет корней!\n",
msg_any_number = "X -- любое число.\n",
msg_special_event = "Решение частного случая (bX + c = 0):\n",
msg_discrim = "Дискриминант = ";
long double A, B, C, D, X1, X2;
bool flag_roots = true, flag_equal_zero, flag_special_event, flag_not_equal_zero,
flag_any_number, flag_input = true, flag_abs_roots, flag_cubes_roots;
void init_fields();
string answer();
bool to_decide();
void to_start();
public:
SqrtQual ();
SqrtQual (int z);
SqrtQual (long double a, long double b, long double c);
};
void variation_task(int variant) {
if (!variant) SqrtQual obj;
else {
for (int i = 0, j = 0; i < 2; i++, j += 3) {
if (variant < 2) SqrtQual obj(ks[j], ks[j+1], ks[j+2]);
else SqrtQual obj(i);
}
}
}
int main() {
prnt_msg_start();
for (int i = 1; i < 3; i++) variation_task(i);
}
SqrtQual::SqrtQual(int z) {
if (z) flag_abs_roots = true;
else flag_cubes_roots = true;
to_start(); }
SqrtQual::SqrtQual() {
to_start(); }
SqrtQual::SqrtQual(long double a, long double b, long double c) {
A = a;
B = b;
C = c;
flag_input = false;
to_start(); }
void SqrtQual::to_start() {
cout << endl;
if (flag_input) Govnokod l_obj(A, B, C);
init_fields();
cout << answer(); }
void SqrtQual::init_fields() {
flag_any_number = ((A == 0) && (B == 0) && (C == 0));
flag_not_equal_zero = ((A == 0) && (B == 0) && (C != 0));
flag_special_event = ((A == 0) && (B != 0) && (C != 0));
bool equal_zero_v1 = ((A == 0) && (B != 0) && (C == 0));
bool equal_zero_v2 = ((A != 0) && (B == 0) && (C == 0));
flag_equal_zero = equal_zero_v1 || equal_zero_v2;
D = B*B - 4*A*C;
if ((D < 0) || flag_not_equal_zero)
flag_roots = false; }
string SqrtQual::answer() {
string tmp = msg_discrim + to_string(D) + "\n";
if (flag_special_event)
tmp = msg_special_event + tmp;
if (flag_any_number)
return msg_any_number;
else if (not flag_roots)
return msg_not_roots;
else {
bool flag_args = to_decide();
string root1("X = "), root2("X2 = ");
if (flag_abs_roots) {
root1 = "| X | = ", root2 = "| X2 | = ";
X1 = abs(X1), X2 = abs(X2);
}
else if (flag_cubes_roots) {
root1 = "X ^3 = ", root2 = "X2 ^3 = ";
X1 = pow(X1, 3), X2 = pow(X2, 3);
}
tmp += root1 + to_string(X1) + "\n";
if (flag_args)
tmp += root2 + to_string(X2) + "\n";
}
return tmp;
}
bool SqrtQual::to_decide() /* if true then two roots else one root */ {
if (flag_equal_zero) X1 = 0;
else if (flag_special_event) X1 = (-C/B); // special event
else if (D == 0) X1 = (-B/2*A);
else {
X1 = ((-B + sqrt(D)) / 2*A), X2 = ((-B - sqrt(D)) / 2*A);
return true; }
return false; }
Немного расширил функционал говнокода с учётом замечаний (в том числе и по архитектуре).