Advertisement
SeriousVenom

08.10.2019

Oct 8th, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. // 08.10.2019.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <math.h>
  7.  
  8. using namespace std;
  9.  
  10. class complex{
  11.     float a,b;
  12. public:
  13.     complex::complex(const complex&);
  14.     complex::complex(float x=0, float y=0);
  15. complex complex::operator = (const complex&);
  16. complex complex::operator + (const complex&);
  17. complex complex::operator - (const complex&);
  18. complex complex::operator * (const complex&);
  19.     bool complex::operator > (complex&);
  20.     bool complex::operator == (complex&);
  21.     bool complex::operator != (complex&);
  22.     void print();
  23.     float mod();
  24.  
  25. };
  26.  
  27. int _tmain(int argc, _TCHAR* argv[])
  28. {
  29.     complex c1,c2(5),c3(15,25),c4(-15,-15);
  30.     c1.print();
  31.     c2.print();
  32.     c3.print();
  33.     c4.print();
  34.     complex c5=c4;
  35.     c5.print();
  36.     c1=c5;
  37.     c1.print();
  38.  
  39.     return 0;
  40. }
  41.  
  42. complex::complex(const complex&t){
  43.     cout << "Copy \n";
  44.     a=t.a;
  45.     b=t.b;
  46. }
  47. complex::complex(float x, float y){
  48.     cout << "constructor:\n";
  49.     a=x;
  50.     b=y;
  51. }
  52. complex complex::operator = (const complex&t){
  53.     cout << "operator =\n";
  54.     a=t.a;
  55.     b=t.b;
  56.     return *this;
  57. }
  58. complex complex::operator + (const complex&t){
  59.     complex temp;
  60.     temp.a=a+t.a;
  61.     temp.b=b+t.b;
  62. return temp;
  63. }
  64. complex complex::operator - (const complex&t){
  65. complex temp;
  66.     temp.a=a-t.a;
  67.     temp.b=b-t.b;
  68. return temp;
  69. }
  70. complex complex::operator * (const complex&t){
  71.     complex temp;
  72.     temp.a=a*t.a-b*t.b;
  73.     temp.b=a*t.b+b*t.a;
  74.     return temp;
  75. }
  76. bool complex::operator > (complex&t){
  77.     if (mod() > t.mod()) return true;
  78.     else return false;
  79. }
  80. bool complex::operator == (complex&t){
  81. if (mod() == t.mod()) return true;
  82.     else return false;
  83. }
  84. bool complex::operator != (complex&t){
  85. if (mod() != t.mod()) return true;
  86.     else return false;
  87. }
  88. void complex::print(){
  89.     if (b>=0) cout << a << "+" << b << "*i" << endl;
  90.     else cout << a << b << "*i" << endl;
  91. }
  92.  
  93.     float complex::mod(){
  94.     return sqrt(a*a+b*b);
  95.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement