Advertisement
maxrusmos

Untitled

Mar 7th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. using System;
  2. using FractionOp;
  3.  
  4. namespace ComplexNums {
  5. class ComplexNum {
  6. public Fraction r, i;
  7.  
  8. public ComplexNum() {
  9. this.r = new Fraction(1, 2);
  10. this.i = new Fraction(4, 5);
  11. }
  12.  
  13. public static ComplexNum Sum(ComplexNum a, ComplexNum b) {
  14. ComplexNum res = new ComplexNum();
  15. res.r = a.r + b.r;
  16. res.i = a.i + b.i;
  17. return res;
  18. }
  19.  
  20. public static ComplexNum Multiplication(ComplexNum a, ComplexNum b) {
  21. ComplexNum res = new ComplexNum();
  22. res.r = a.r * b.r - a.i * b.i;
  23. res.i = a.i * b.r + a.r * b.i;
  24. return res;
  25. }
  26.  
  27. public static ComplexNum Subtract(ComplexNum a, ComplexNum b) {
  28. ComplexNum res = new ComplexNum();
  29. res.r = a.r - b.r;
  30. res.i = a.i - b.i;
  31. return res;
  32. }
  33.  
  34. public static ComplexNum operator +(ComplexNum a, ComplexNum b) {
  35. return ComplexNum.Sum(a, b);
  36. }
  37.  
  38. public static ComplexNum operator -(ComplexNum a, ComplexNum b) {
  39. return ComplexNum.Subtract(a, b);
  40. }
  41.  
  42. public static ComplexNum operator *(ComplexNum a, ComplexNum b) {
  43. return ComplexNum.Multiplication(a, b);
  44. }
  45.  
  46. public override string ToString() {
  47. return String.Format("{0} + i{1}", this.r, this.i);
  48. }
  49.  
  50. public void Print(ComplexNum a) {
  51. Console.Write(a);
  52. }
  53.  
  54. public void PrintLine(ComplexNum a) {
  55. Console.WriteLine(a);
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement