Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class EcPatr {
- private:
- char Nume[20];
- float a;
- float b;
- float c;
- public:
- EcPatr() {
- strcpy(Nume, "-");
- a = 0;
- b = 0;
- c = 0;
- } // Конструктор по умолчанию
- EcPatr(char const* n, float aa, float bb, float cc) {
- strcpy(Nume, n);
- a = aa;
- b = bb;
- c = cc;
- } // Конструктор 1
- EcPatr(char const* n) {
- strcpy(Nume, n);
- } // Конструктор 2
- EcPatr(float aa, float bb) {
- a = aa;
- b = bb;
- } // Конструктор 3
- EcPatr(const EcPatr & ecPatr) {
- strcpy(Nume, ecPatr.Nume);
- a = ecPatr.a;
- b = ecPatr.b;
- c = ecPatr.c;
- } // Конструктор копирования
- ~EcPatr() {
- cout<<" \nec_patr "<<Nume<<" a fost distrusa"<< endl;
- } // Деструктор
- void show() {
- cout << "Our function " << Nume << ": " << a << "*x*x + " << b << "*x + " << c << " = 0" << endl;
- cout << "Discriminant: " << disc(a, b, c) << endl;
- if (disc(a,b,c) != 0) {
- if (disc_root(a, b, c) == true) {
- cout << "This equations has " << disc_many_roots(a, b, c) << " roots";
- }
- else {
- cout << "This equation hasn`t roots" << endl;
- }
- if (disc_graph(a) == true) {
- cout << "This graph is pointing up" << endl;
- }
- else {
- cout << "This graph is pointin down" << endl;
- }
- }
- } // Показывает результаты
- float disc(float a, float b, float c) {
- return ((b * b) - (4 * a * c));
- } // Считает дискриминант
- bool disc_root(float a, float b, float c) {
- if (disc(a, b, c) >= 0) {
- return true;
- }
- else {
- return false;
- }
- } // Есть корни или нет
- bool disc_graph(float a) {
- if (a > 0) {
- return true;
- }
- else {
- return false;
- }
- } // disc_graph
- int disc_many_roots(float a, float b, float c) {
- if (disc(a, b, c) == 0) {
- return 1;
- }
- else {
- return 2;
- }
- } // How many roots
- };
- int main()
- {
- EcPatr test;
- test.show();
- EcPatr tester("test", 10, 5, 4);
- tester.show();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement