Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using FractionOp;
- namespace ComplexNums {
- class ComplexNum {
- public Fraction r, i;
- public ComplexNum() {
- this.r = new Fraction(1, 2);
- this.i = new Fraction(4, 5);
- }
- public static ComplexNum Sum(ComplexNum a, ComplexNum b) {
- ComplexNum res = new ComplexNum();
- res.r = a.r + b.r;
- res.i = a.i + b.i;
- return res;
- }
- public static ComplexNum Multiplication(ComplexNum a, ComplexNum b) {
- ComplexNum res = new ComplexNum();
- res.r = a.r * b.r - a.i * b.i;
- res.i = a.i * b.r + a.r * b.i;
- return res;
- }
- public static ComplexNum Subtract(ComplexNum a, ComplexNum b) {
- ComplexNum res = new ComplexNum();
- res.r = a.r - b.r;
- res.i = a.i - b.i;
- return res;
- }
- public static ComplexNum operator +(ComplexNum a, ComplexNum b) {
- return ComplexNum.Sum(a, b);
- }
- public static ComplexNum operator -(ComplexNum a, ComplexNum b) {
- return ComplexNum.Subtract(a, b);
- }
- public static ComplexNum operator *(ComplexNum a, ComplexNum b) {
- return ComplexNum.Multiplication(a, b);
- }
- public override string ToString() {
- return String.Format("{0} + i{1}", this.r, this.i);
- }
- public void Print(ComplexNum a) {
- Console.Write(a);
- }
- public void PrintLine(ComplexNum a) {
- Console.WriteLine(a);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement