Advertisement
sheredega

C++ / Class

Oct 17th, 2022 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. class EcPatr {
  6.     private:
  7.         char Nume[20];
  8.         float a;
  9.         float b;
  10.         float c;
  11.     public:
  12.         EcPatr() {
  13.             strcpy(Nume, "-");
  14.             a = 0;
  15.             b = 0;
  16.             c = 0;
  17.         } // Конструктор по умолчанию
  18.         EcPatr(char const* n, float aa, float bb, float cc) {
  19.             strcpy(Nume, n);
  20.             a = aa;
  21.             b = bb;
  22.             c = cc;
  23.         } // Конструктор 1
  24.         EcPatr(char const* n) {
  25.             strcpy(Nume, n);
  26.         } // Конструктор 2
  27.         EcPatr(float aa, float bb) {
  28.             a = aa;
  29.             b = bb;
  30.         } // Конструктор 3
  31.         EcPatr(const EcPatr & ecPatr) {
  32.             strcpy(Nume, ecPatr.Nume);
  33.             a = ecPatr.a;
  34.             b = ecPatr.b;
  35.             c = ecPatr.c;
  36.         } // Конструктор копирования
  37.         ~EcPatr() {
  38.             cout<<" \nec_patr "<<Nume<<" a fost distrusa"<< endl;
  39.         } // Деструктор
  40.         void show() {
  41.             cout << "Our function " << Nume << ": " << a << "*x*x + " << b << "*x + " << c << " = 0" << endl;
  42.             cout << "Discriminant: " << disc(a, b, c) << endl;
  43.             if (disc(a,b,c) != 0) {
  44.                 if (disc_root(a, b, c) == true) {
  45.                     cout << "This equations has " << disc_many_roots(a, b, c) << " roots";
  46.                 }
  47.                 else {
  48.                     cout << "This equation hasn`t roots" << endl;
  49.                 }
  50.                 if (disc_graph(a) == true) {
  51.                     cout << "This graph is pointing up" << endl;
  52.                 }
  53.                 else {
  54.                     cout << "This graph is pointin down" << endl;
  55.                 }
  56.             }
  57.  
  58.         } // Показывает результаты
  59.         float disc(float a, float b, float c) {
  60.             return ((b * b) - (4 * a * c));
  61.         } // Считает дискриминант
  62.         bool disc_root(float a, float b, float c) {
  63.             if (disc(a, b, c) >= 0) {
  64.                 return true;
  65.             }
  66.             else {
  67.                 return false;
  68.             }
  69.         } // Есть корни или нет
  70.         bool disc_graph(float a) {
  71.             if (a > 0) {
  72.                 return true;
  73.             }
  74.             else {
  75.                 return false;
  76.             }
  77.         } // disc_graph
  78.         int disc_many_roots(float a, float b, float c) {
  79.             if (disc(a, b, c) == 0) {
  80.                 return 1;
  81.             }
  82.             else {
  83.                 return 2;
  84.             }
  85.         } // How many roots
  86. };
  87.  
  88. int main()
  89. {
  90.     EcPatr test;
  91.     test.show();
  92.     EcPatr tester("test", 10, 5, 4);
  93.     tester.show();
  94.  
  95.     return 0;
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement