2014-2015-1C#考试题库 一:控制台应用程序 1
定义描述复数的类Complex,具体要求如下: (1) 通过重载运算符:+、-、*、/,直接实现两个复数之间的各种运算
(2) 其中,两个复数相乘的计算公式为(a+bi)*(c+di)=(ac-bd)+(ad+bc)i; (3) 两个复数相除的计算公式为(a+bi)/(c+di)=(ac+bd)/(c*c+d*d)+(bc-ad)/(c*c+d*d) (4) 定义主函数测试类,在主函数中定义两个复数2+3i 和 1+2i,实现两个复数的加减,并将结果输出
using System; using System
Collections
Generic; using System
Linq; using System
Text; namespace L1 { class Complex { double real, image; public Complex(double a, double b) { this
real = a; this
image = b; } public static Complex operator +(Complex a, Complex b) { return new Complex(a
real + b
real, a
image + b
image); } public static Complex operator -(Complex a, Complex b) { return new Complex(a
real - b
real, a
image - b
image); } public static Complex operator *(Complex a, Complex b) { return new Complex(a
real * b
real - a