1、 复数 ADT 的描述 ADT complex 数据对象: D= c1,c2 c1,c2 FloatSet 数据关系: R= c1 c2 基本操作:创建一个复数 creat(a);输出一个复数 outputc(a);求两个复数相加之和 add(a,b);求两个复数相减之差 sub(a,b);求两个复数相乘之积 chengji(a,b);等等 ; ADT complex;实现复数 ADT 可以使用面向过程的程序设计方法,也可以用面向对象程序设计方法。复数 ADT 实现的面向过程 C 语言源程序-complex.h#include #include typedef struct Complexfl
2、oat real; float image;Complex; void CreatComplex(Complex void AddComplex(Complex void Subtract_C(Complex void Multiple_C(Complex void Print_C(Complex c); void CreatComplex(Complexc.image = b; void AddComplex(Complexsum.image = c1.image + c2.image ; void Subtract_C(ComplexSub.image = c1.image - c2.im
3、age ;void Multiple_C(Complexproduct.image = c1.real * c2.image + c1.image * c2.real ;void Print_C(Complex c)if (c.image = 0.0)printf(“%5.2fn“,c.real );elseprintf(“%5.2f+%5.2fin“,c.real ,c.image );if(c.real=0.0)printf(“%5.2fin“,c.image);complex.cpp 代码:#include “complex.h“#include void main()float a,b,c,d;Complex c1,c2,sum,Sub,Prod;scanf(“%f%f%f%f“,CreatComplex(c1,a,b);Print_C(c1);CreatComplex(c2,c,d);Print_C(c2);AddComplex(sum,c1,c2);Print_C(sum);Subtract_C(Sub,c1,c2);Print_C(Sub);Multiple_C(Prod,c1,c2);Print_C(Prod);