首页 > Windows开发 > 详细

用C#实现复数运算

时间:2014-12-09 12:17:59      阅读:361      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sample_01_CA
{
    public class Complex
    {
        //定义复试的实部和虚部
        private int integer;
        private int fraction;
        //构造函数
        public Complex(int integer,int fraction)
        {
            this.integer = integer;
            this.fraction = fraction;
        }
        //重载运算符
        public static Complex operator +(Complex left,Complex right)
        {
            return new Complex(left.integer + right.integer, left.fraction + right.fraction);
        }
        //重写从Object继承的ToString()方法
        public override string ToString()
        {
            return integer.ToString()+"."+fraction.ToString();
        }
        static void Main(string[] args)
        {
            Complex left = new Complex(2008, 10);
            Complex right = new Complex(100, 1);
            Console.WriteLine(left.ToString() + " + " + right.ToString() + " = " + (left + right).ToString());
            Console.Read();
        }
    };
}

用C#实现复数运算

原文:http://blog.csdn.net/qsyzb/article/details/41821731

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!