Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 08.10.2019.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- using namespace std;
- class complex{
- float a,b;
- public:
- complex::complex(const complex&);
- complex::complex(float x=0, float y=0);
- complex complex::operator = (const complex&);
- complex complex::operator + (const complex&);
- complex complex::operator - (const complex&);
- complex complex::operator * (const complex&);
- bool complex::operator > (complex&);
- bool complex::operator == (complex&);
- bool complex::operator != (complex&);
- void print();
- float mod();
- };
- int _tmain(int argc, _TCHAR* argv[])
- {
- complex c1,c2(5),c3(15,25),c4(-15,-15);
- c1.print();
- c2.print();
- c3.print();
- c4.print();
- complex c5=c4;
- c5.print();
- c1=c5;
- c1.print();
- return 0;
- }
- complex::complex(const complex&t){
- cout << "Copy \n";
- a=t.a;
- b=t.b;
- }
- complex::complex(float x, float y){
- cout << "constructor:\n";
- a=x;
- b=y;
- }
- complex complex::operator = (const complex&t){
- cout << "operator =\n";
- a=t.a;
- b=t.b;
- return *this;
- }
- complex complex::operator + (const complex&t){
- complex temp;
- temp.a=a+t.a;
- temp.b=b+t.b;
- return temp;
- }
- complex complex::operator - (const complex&t){
- complex temp;
- temp.a=a-t.a;
- temp.b=b-t.b;
- return temp;
- }
- complex complex::operator * (const complex&t){
- complex temp;
- temp.a=a*t.a-b*t.b;
- temp.b=a*t.b+b*t.a;
- return temp;
- }
- bool complex::operator > (complex&t){
- if (mod() > t.mod()) return true;
- else return false;
- }
- bool complex::operator == (complex&t){
- if (mod() == t.mod()) return true;
- else return false;
- }
- bool complex::operator != (complex&t){
- if (mod() != t.mod()) return true;
- else return false;
- }
- void complex::print(){
- if (b>=0) cout << a << "+" << b << "*i" << endl;
- else cout << a << b << "*i" << endl;
- }
- float complex::mod(){
- return sqrt(a*a+b*b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement