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 {
- protected:
- float real;
- float imaginary;
- public:
- //konst
- ComplexNumber() {}
- //konst so parametri
- ComplexNumber(float real,float imaginary) {
- this->real=real;
- this->imaginary=imaginary;
- }
- //formula
- double module() {
- return sqrt((pow(real,2)+pow(imaginary,2)));
- }
- //preoptovaruvanje na =
- ComplexNumber&operator=(const ComplexNumber &n) {
- if(this!=&n) {
- this->real=n.real;
- this->imaginary=n.imaginary;
- }
- return *this;
- }
- //preoptovaruvanje na <<
- friend ostream &operator<< (ostream &output, const ComplexNumber & n) {
- return output << n.real << "+" << n.imaginary<<"i"<<endl;
- }
- //preoptovaruvanje na +
- ComplexNumber operator + ( const ComplexNumber &n) {
- class ComplexNumber res;
- res.real = real + n.real;
- res.imaginary = imaginary + n.imaginary;
- return res;
- }
- //preoptovaruvanje na -
- ComplexNumber operator - ( const ComplexNumber &n) {
- class ComplexNumber sub;
- sub.real = real - n.real;
- sub.imaginary = imaginary - n.imaginary;
- return sub;
- }
- //preoptovaruvanje na *
- ComplexNumber operator * ( const ComplexNumber &n) {
- class ComplexNumber mul;
- mul.real = this->real*n.real ;
- mul.imaginary = this->imaginary * n.imaginary;
- return mul;
- }
- //preoptovaruvanje na /
- ComplexNumber operator / ( const ComplexNumber &n) {
- class ComplexNumber dev;
- dev.real = this->real/n.real ;
- dev.imaginary = this->imaginary / n.imaginary;
- return dev;
- }
- //preoptovaruvanje na ==
- bool operator==(const ComplexNumber &n) {
- if((this->real==n.real)&&(this->imaginary==n.imaginary)) {
- return true;
- } else {
- return false;
- }
- }
- //preoptovaruvanje na <
- bool operator <(const ComplexNumber &n) {
- if(this->imaginary<n.imaginary&&(this->imaginary<n.imaginary)){
- return true;}
- else {
- return false;
- }
- }
- //preoptovaruvanje na >
- 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 &c){
- ComplexNumber *temp=new ComplexNumber[n+1];
- for(int i=0;i<strlen(c);++i){
- while(*znaci!= '='){
- class ComplexNumber nova;
- is>>nova.real>>nova.imaginary;
- temp[i].real=nova.real;
- temp[i].imaginary=nova.imaginary;
- }
- }
- delete [] c;
- c=temp;
- return is;
- }
- double sumModules(){
- double sum=0.0
- for(int i=0;i<strlen(c);++i){
- sum+=s[i].module();
- }
- return sum;
- }
- };
- */
- //----------------------------------------------------------------------------------------------------
- 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;
- }
- //za ova samo 5 poeni ce dobiete fala.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement