Guest User

Untitled

a guest
Jun 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. // lab2.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <stdlib.h>
  7.  
  8. class complex {
  9.  
  10. float re,im;
  11.  
  12. public:
  13.  
  14. complex(): re(0), im(0){}
  15. complex(float r, float i): re(r), im(i){}
  16.  
  17. float get_real() {
  18. return re;
  19. }
  20.  
  21. float get_imaginar() {
  22. return im;
  23. }
  24.  
  25. complex add(complex x){
  26. complex ret;
  27. ret.re = re + x.re;
  28. ret.im = im + x.im;
  29. return ret;
  30. }
  31.  
  32. complex add1(complex x) {
  33. return complex(re + x.re, im + x.im);
  34. }
  35.  
  36. complex inmultire(complex x){
  37. complex ret;
  38. ret.re = re * x.re - im * x.im;
  39. ret.im = re * x.im + im * x.re;
  40. return ret;
  41. }
  42.  
  43. void print(){
  44. std::cout << re << "+i" << im << std::endl;
  45. }
  46. };
  47.  
  48. class vector {
  49.  
  50. float info[3];
  51.  
  52. public:
  53.  
  54. vector () {
  55. for(int i = 0; i < 3; i++)
  56. info[i] = 0.0f;
  57. }
  58.  
  59. vector add(vector a){
  60. vector b;
  61.  
  62. for(int i = 0; i < 3; i++)
  63. b.info[i] = a.info[i] + info[i];
  64.  
  65. return b;
  66. }
  67.  
  68. vector add(int a){
  69. vector b;
  70.  
  71. for(int i = 0; i < 3; i++)
  72. b.info[i] = a + info[i];
  73.  
  74. return b;
  75. }
  76.  
  77. vector add(float a){
  78. vector b;
  79.  
  80. for(int i = 0; i < 3; i++)
  81. b.info[i] = a + info[i];
  82.  
  83. return b;
  84. }
  85.  
  86. void print(){
  87. for(int i = 0; i < 3; i++)
  88. std::cout << info[i] << " ";
  89.  
  90. std::cout << std::endl;
  91. }
  92. };
  93.  
  94. float add(float a, float b){
  95. return a + b;
  96. }
  97.  
  98. complex add(complex a, complex b){
  99. return a.add1(b);
  100. }
  101.  
  102. complex add(complex a, float b) {
  103. return complex(a.get_real() + b, a.get_imaginar());
  104. }
  105.  
  106. int _tmain(int argc, _TCHAR* argv[]) {
  107.  
  108. vector b, c;
  109.  
  110. b = c.add(1);
  111.  
  112. c = c.add(3.2f);
  113.  
  114. b.print();
  115. c.print();
  116.  
  117. c = b.add(c);
  118. c.print();
  119.  
  120. std::cout << "=========================================" << std::endl;
  121.  
  122. complex x(3.4f, 1.1f);
  123. complex y(2.6f, 7.9f);
  124. complex z;
  125.  
  126. int f = 4, g = 7;
  127. double k = 4.5, l = 7.8;
  128.  
  129. float m = 4.5f, n = 3.6f, p;
  130.  
  131. z = add(x, y);
  132. z.print();
  133.  
  134. z = add(x, m);
  135. z.print();
  136.  
  137. z = add(m, x);
  138. z.print();
  139.  
  140. p = add(m, n);
  141. std::cout << p << std::endl;
  142.  
  143. f = add(f, g);
  144. std::cout << f << std::endl;
  145.  
  146. k = add(k, l);
  147. std::cout << k << std::endl;
  148.  
  149. system("pause");
  150. return 0;
  151. }
Add Comment
Please, Sign In to add comment