Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- #include <cstring>
- using namespace std;
- class ComplexNumber {
- private:
- double real;
- double imaginary;
- public:
- ComplexNumber() {}
- ComplexNumber(double real, double imaginary)
- {
- this->real=real;
- this->imaginary=imaginary;
- }
- double module() {
- return sqrt((pow(real,2)+pow(imaginary,2)));
- }
- ComplexNumber &operator=(const ComplexNumber &n) {
- if(this!=&n) {
- this->real=n.real;
- this->imaginary=n.imaginary;
- }
- return *this;
- }
- friend ostream &operator<<(ostream &output, const ComplexNumber &n) {
- return output << n.real << "+" << n.imaginary<<"i"<<endl;
- }
- ComplexNumber operator + ( const ComplexNumber &n) {
- ComplexNumber res;
- res.real = real + n.real;
- res.imaginary = imaginary + n.imaginary;
- return res;
- }
- ComplexNumber operator - (const ComplexNumber &n) {
- class ComplexNumber sub;
- sub.real = real - n.real;
- sub.imaginary = imaginary - n.imaginary;
- return sub;
- }
- ComplexNumber operator * (const ComplexNumber &n) {
- ComplexNumber mul;
- mul.real=this->real*n.real;
- mul.imaginary=this->imaginary*n.imaginary;
- return mul;
- }
- ComplexNumber operator / (const ComplexNumber &n) {
- ComplexNumber dev;
- dev.real=this->real/n.real;
- dev.imaginary=this->imaginary/n.imaginary;
- return dev;
- }
- bool operator==(const ComplexNumber &n) {
- if((this->real==n.real)&&(this->imaginary==n.imaginary)) {
- return true;
- } else {
- return false;
- }
- }
- bool operator <(const ComplexNumber &n) {
- if(this->imaginary<n.imaginary) {
- return true;
- } else {
- return false;
- }
- }
- bool operator >(const ComplexNumber &n) {
- if((this->real>n.real)&&(this->imaginary>n.imaginary)) {
- return true;
- }
- else {
- return false;
- }
- }
- };
- /*
- class Equation {
- private:
- ComplexNumber *c;
- int n;
- char *znaci;
- public:
- Equation() {
- c=new ComplexNumber[0];
- znaci=new char[0];
- n=0;
- }
- friend istream& operator>> (istream& is, Equation &n) {
- ComplexNumber *temp=new ComplexNumber[n+1];
- for(int i=0; i<strlen(c); ++i) {
- while(*znaci!= '=') {
- ComplexNumber nova;
- is>>nova.real>>nova.imaginary;
- temp[i].real=nova.real;
- temp[i].imaginary=nova.imaginary;
- }
- }
- delete [] c;
- c=temp;
- return is;
- }
- */
- // Не го менувајте main методот.
- int main() {
- int testCase;
- double real, imaginary;
- ComplexNumber first, second, result;
- cin >> testCase;
- if (testCase <= 8) {
- cin >> real;
- cin >> imaginary;
- first = ComplexNumber(real, imaginary);
- cin >> real;
- cin >> imaginary;
- second = ComplexNumber(real, imaginary);
- }
- if (testCase == 1) {
- cout << "===== OPERATOR + =====" << endl;
- result = first + second;
- cout << result;
- } else if (testCase == 2) {
- cout << "===== OPERATOR - =====" << endl;
- result = first - second;
- cout << result;
- } else if (testCase == 3) {
- cout << "===== OPERATOR * =====" << endl;
- result = first * second;
- cout << result;
- } else if (testCase == 4) {
- cout << "===== OPERATOR / =====" << endl;
- result = first / second;
- cout << result;
- } else if (testCase == 5) {
- cout << "===== OPERATOR == =====" << endl;
- cout << first;
- cout << second;
- if (first == second)
- cout << "EQUAL" << endl;
- else
- cout << "NOT EQUAL" << endl;
- } else if (testCase == 6) {
- cout << "===== OPERATOR > =====" << endl;
- cout << first;
- cout << second;
- if (first > second)
- cout << "FIRST GREATER THAN SECOND" << endl;
- else
- cout << "FIRST LESSER THAN SECOND" << endl;
- } else if (testCase == 7) {
- cout << "===== OPERATOR < =====" << endl;
- cout << first;
- cout << second;
- if (first < second)
- cout << "FIRST LESSER THAN SECOND" << endl;
- else
- cout << "FIRST GREATER THAN SECOND" << endl;
- }/* else if (testCase == 8) {
- cout << "===== MODULE =====" << endl;
- double module = first.module();
- cout << first;
- cout << "Module: " << module << endl;
- cout << second;
- module = second.module();
- cout << "Module: " << module << endl;
- } else if (testCase == 9) {
- cout << "===== OPERATOR >> & SUM OF MODULES =====" << endl;
- Equation equation;
- cin >> equation;
- cout << equation.sumModules();
- } else if (testCase == 10) {
- cout << "===== EQUATION RESULT =====" << endl;
- Equation equation;
- cin >> equation;
- result = equation.result();
- cout << result;
- }*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement