SHARE
TWEET

Untitled

a guest Apr 18th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<cmath>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. class ComplexNumber {
  7.  
  8. private:
  9.     double real;
  10.     double imaginary;
  11.  
  12. public:
  13.  
  14.     ComplexNumber() {}
  15.     ComplexNumber(double real, double imaginary)
  16.  
  17.     {
  18.         this->real=real;
  19.         this->imaginary=imaginary;
  20.  
  21.     }
  22.     double module() {
  23.         return    sqrt((pow(real,2)+pow(imaginary,2)));
  24.     }
  25.     ComplexNumber &operator=(const ComplexNumber &n) {
  26.         if(this!=&n) {
  27.             this->real=n.real;
  28.             this->imaginary=n.imaginary;
  29.         }
  30.  
  31.         return *this;
  32.     }
  33.     friend ostream &operator<<(ostream &output, const ComplexNumber &n) {
  34.         return output << n.real << "+" << n.imaginary<<"i"<<endl;
  35.     }
  36.  
  37.     ComplexNumber operator + ( const ComplexNumber &n) {
  38.         ComplexNumber res;
  39.         res.real = real + n.real;
  40.         res.imaginary = imaginary + n.imaginary;
  41.         return res;
  42.     }
  43.     ComplexNumber operator - (const ComplexNumber &n) {
  44.         class ComplexNumber sub;
  45.         sub.real = real - n.real;
  46.         sub.imaginary = imaginary - n.imaginary;
  47.         return sub;
  48.  
  49.     }
  50.  
  51.     ComplexNumber operator * (const ComplexNumber &n) {
  52.         ComplexNumber mul;
  53.         mul.real=this->real*n.real;
  54.         mul.imaginary=this->imaginary*n.imaginary;
  55.         return mul;
  56.  
  57.     }
  58.     ComplexNumber operator / (const ComplexNumber &n) {
  59.         ComplexNumber dev;
  60.         dev.real=this->real/n.real;
  61.         dev.imaginary=this->imaginary/n.imaginary;
  62.         return dev;
  63.  
  64.  
  65.     }
  66.  
  67.     bool operator==(const ComplexNumber &n) {
  68.         if((this->real==n.real)&&(this->imaginary==n.imaginary)) {
  69.             return true;
  70.         } else {
  71.             return false;
  72.         }
  73.  
  74.     }
  75.  
  76.     bool operator <(const ComplexNumber &n) {
  77.         if(this->imaginary<n.imaginary) {
  78.             return true;
  79.  
  80.         } else {
  81.             return false;
  82.         }
  83.  
  84.     }
  85.  
  86.     bool operator >(const ComplexNumber &n) {
  87.         if((this->real>n.real)&&(this->imaginary>n.imaginary)) {
  88.             return true;
  89.         }
  90.  
  91.         else {
  92.             return false;
  93.         }
  94.     }
  95.  
  96.  
  97.  
  98. };
  99. /*
  100. class Equation {
  101. private:
  102.     ComplexNumber *c;
  103.     int n;
  104.     char *znaci;
  105. public:
  106.     Equation() {
  107.         c=new ComplexNumber[0];
  108.         znaci=new char[0];
  109.         n=0;
  110.     }
  111.     friend istream& operator>> (istream& is, Equation &n) {
  112.         ComplexNumber *temp=new ComplexNumber[n+1];
  113.         for(int i=0; i<strlen(c); ++i) {
  114.             while(*znaci!= '=') {
  115.                 ComplexNumber nova;
  116.                 is>>nova.real>>nova.imaginary;
  117.                 temp[i].real=nova.real;
  118.                 temp[i].imaginary=nova.imaginary;
  119.  
  120.             }
  121.         }
  122.         delete [] c;
  123.         c=temp;
  124.         return is;
  125.     }
  126.  
  127.  
  128. */
  129.  
  130. // Не го менувајте main методот.
  131.  
  132. int main() {
  133.     int testCase;
  134.     double real, imaginary;
  135.     ComplexNumber first, second, result;
  136.  
  137.     cin >> testCase;
  138.  
  139.     if (testCase <= 8) {
  140.         cin >> real;
  141.         cin >> imaginary;
  142.         first = ComplexNumber(real, imaginary);
  143.         cin >> real;
  144.         cin >> imaginary;
  145.         second = ComplexNumber(real, imaginary);
  146.     }
  147.  
  148.     if (testCase == 1) {
  149.         cout << "===== OPERATOR + =====" << endl;
  150.         result = first + second;
  151.         cout << result;
  152.     } else if (testCase == 2) {
  153.         cout << "===== OPERATOR - =====" << endl;
  154.         result = first - second;
  155.         cout << result;
  156.     } else if (testCase == 3) {
  157.         cout << "===== OPERATOR * =====" << endl;
  158.         result = first * second;
  159.         cout << result;
  160.     } else if (testCase == 4) {
  161.         cout << "===== OPERATOR / =====" << endl;
  162.         result = first / second;
  163.         cout << result;
  164.     } else if (testCase == 5) {
  165.         cout << "===== OPERATOR == =====" << endl;
  166.         cout << first;
  167.         cout << second;
  168.         if (first == second)
  169.             cout << "EQUAL" << endl;
  170.         else
  171.             cout << "NOT EQUAL" << endl;
  172.     } else if (testCase == 6) {
  173.         cout << "===== OPERATOR > =====" << endl;
  174.         cout << first;
  175.         cout << second;
  176.         if (first > second)
  177.             cout << "FIRST GREATER THAN SECOND" << endl;
  178.         else
  179.             cout << "FIRST LESSER THAN SECOND" << endl;
  180.     } else if (testCase == 7) {
  181.         cout << "===== OPERATOR < =====" << endl;
  182.         cout << first;
  183.         cout << second;
  184.         if (first < second)
  185.             cout << "FIRST LESSER THAN SECOND" << endl;
  186.         else
  187.             cout << "FIRST GREATER THAN SECOND" << endl;
  188.     }/* else if (testCase == 8) {
  189.         cout << "===== MODULE =====" << endl;
  190.         double module = first.module();
  191.         cout << first;
  192.         cout << "Module: " << module << endl;
  193.         cout << second;
  194.         module = second.module();
  195.         cout << "Module: " << module << endl;
  196.     } else if (testCase == 9) {
  197.         cout << "===== OPERATOR >> & SUM OF MODULES =====" << endl;
  198.         Equation equation;
  199.         cin >> equation;
  200.         cout << equation.sumModules();
  201.     } else if (testCase == 10) {
  202.         cout << "===== EQUATION RESULT =====" << endl;
  203.         Equation equation;
  204.         cin >> equation;
  205.         result = equation.result();
  206.         cout << result;
  207.     }*/
  208.     return 0;
  209. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top