Posted on 2011-07-16 19:36
susu 阅读(254)
评论(0) 编辑 收藏 引用
1#include <iostream>
2#include <string>
3using namespace std;
4
5
6class complex
7{
8 double a;
9 double b;
10public:
11 complex()
12 {
13 a = 0;
14 b = 0;
15 }
16 complex operator + (complex another)
17 {
18 complex add;
19 add.a = a + another.a;
20 add.b = b + another.b;
21 return add;
22 }
23 void Putln()
24 {
25 cin >> a >> b;
26 return;
27 }
28 void show()
29 {
30 //输出复数
31 cout <<"("<<a<<"+"<<b<<"i)";
32 return;
33 }
34};
35class summator
36{
37public:
38 int addition(int a,int b);
39 float addition(float a,float b);
40 string addition(string a,string b);
41 complex addition(complex a,complex b);
42};
43complex summator :: addition(complex a,complex b)
44{
45 return a + b;
46}
47
48void main()
49{
50 summator sr;
51 //int inta ,intb;
52 //float fa ,fb;
53 //string stra,strb;
54 complex ca,cb;
55
56
57 cout << "请输入两个复数:"<<endl;
58 ca.Putln();
59 cb.Putln();
60
61 ca.show();
62 cout<< "+";
63 cb.show();
64 cout<< "=";
65
66 sr.addition(ca,cb).show();
67 cout<<endl;
68
69 return;
70}
71