隨筆 - 251  文章 - 504  trackbacks - 0
          <2006年9月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          本博客系個人收集材料及學習記錄之用,各類“大俠”勿擾!

          留言簿(14)

          隨筆分類

          收藏夾

          My Favorite Web Sites

          名Bloger

          非著名Bloger

          搜索

          •  

          積分與排名

          • 積分 - 204317
          • 排名 - 283

          最新評論

          [ 復數 ADT 的描述 ]
            ADT complex{
              數據對象: D={ c1,c2   c1,c2 FloatSet }
              數據關系: R={ <c1,c2>   c1   c2    }
              基本操作:創建一個復數     creat(a);
                   輸出一個復數     outputc(a);
                   求兩個復數相加之和  add(a,b);
                   求兩個復數相減之差  sub(a,b);
                   求兩個復數相乘之積  chengji(a,b);
                   等等 ;
          } ADT complex;
          實現復數 ADT 可以使用面向過程的程序設計方法,也可以用面向對象程序設計方法。
          [復數ADT實現的面向過程C語言源程序]-complex.h
          #include <stdio.h>
          #include <stdlib.h>
          typedef struct Complex
          {
          ?float?real;?
          ?float?image;
          }Complex;

          void CreatComplex(Complex& c,float a,float b);

          void AddComplex(Complex& sum,Complex c1,Complex c2 );

          void Subtract_C(Complex& Sub,Complex c1,Complex c2 );

          void Multiple_C(Complex& product,Complex c1,Complex c2 );

          void Print_C(Complex c);

          void CreatComplex(Complex& c,float a,float b)
          {
          ?c.real = a;
          ?c.image = b;
          }

          void AddComplex(Complex& sum,Complex c1,Complex c2)
          {
          ?sum.real = c1.real + c2.real ;
          ?sum.image = c1.image? + c2.image? ;
          }


          void? Subtract_C(Complex& Sub,Complex c1,Complex c2 )
          {
          ?Sub.real = c1.real -c2.real ;
          ?Sub.image = c1.image?- c2.image ;
          }

          void Multiple_C(Complex& product,Complex c1,Complex c2 )
          {
          ?product.real = c1.real * c2.real - c1.image * c2.image ;

          ?product.image = c1.real * c2.image + c1.image * c2.real ;
          }


          void Print_C(Complex c)
          {
          ?if (c.image == 0.0)
          ??printf("%5.2f\n",c.real );
          ?else
          ??printf("%5.2f+%5.2fi\n",c.real ,c.image );
          ?if(c.real==0.0)
          ??printf("%5.2fi\n",c.image);
          }
          complex.cpp代碼:
          #include "complex.h"
          #include <stdio.h>
          void main()
          {
          ?float a,b,c,d;
          ?Complex??c1,c2,sum,Sub,Prod;
          ?
          ?scanf("%f%f%f%f",&a,&b,&c,&d);
          ???
          ?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);
          }

          posted on 2006-09-25 18:52 matthew 閱讀(3376) 評論(0)  編輯  收藏 所屬分類: 數據結構與算法設計
          主站蜘蛛池模板: 武穴市| 静宁县| 武山县| 辰溪县| 肥城市| 金沙县| 婺源县| 横山县| 朔州市| 鄂伦春自治旗| 通州区| 济阳县| 新野县| 湛江市| 武宣县| 武鸣县| 彭泽县| 余干县| 梁山县| 聊城市| 漳州市| 崇州市| 安庆市| 潞西市| 延津县| 枣强县| 会泽县| 讷河市| 湘西| 政和县| 昭苏县| 泗水县| 牟定县| 通榆县| 大英县| 本溪| 探索| 铁岭县| 平和县| 桃源县| 垫江县|