Posted on 2011-07-16 19:36 
susu 阅读(283) 
评论(0)  编辑 收藏 引用  
			 
			
		 
		 1 #include <iostream>
#include <iostream>
 2 #include <string>
#include <string>
 3 using namespace std;
using namespace std;
 4
 5
 6 class complex
class complex
 7

 {
{
 8 double a;
    double a;
 9 double b;
    double b;
10 public:
public:
11 complex()
    complex()
12
 
     {
{
13 a = 0;
        a = 0;
14 b = 0;
        b = 0;
15 }
    }
16 complex operator + (complex another)
    complex operator + (complex another)
17
 
     {
{
18 complex add;
        complex add;
19 add.a = a + another.a;
        add.a = a + another.a;
20 add.b = b + another.b;
        add.b = b + another.b;
21 return add;
        return add;
22 }
    }
23 void Putln()
    void Putln()
24
 
     {
{
25 cin >> a >> b;
        cin >> a >> b;
26 return;
        return;
27 }
    }
28 void show()
    void show()
29
 
     {
{
30 //输出复数
        //输出复数
31 cout <<"("<<a<<"+"<<b<<"i)";
        cout <<"("<<a<<"+"<<b<<"i)";
32 return;
        return;
33 }
    }
34 };
};
35 class summator
class summator
36

 {
{
37 public:
public:
38 int addition(int a,int b);
    int addition(int a,int b);
39 float addition(float a,float b);
    float addition(float a,float b);
40 string addition(string a,string b);
    string addition(string a,string b);
41 complex addition(complex a,complex b);
    complex addition(complex a,complex b);
42 };
};
43 complex summator :: addition(complex a,complex b)
complex summator :: addition(complex a,complex b)
44

 {
{
45 return a + b;
    return a + b;
46 }
}
47
48 void main()
void main()
49

 {
{
50 summator sr;
    summator sr;
51 //int inta ,intb;
    //int inta ,intb;
52 //float fa ,fb;
    //float fa ,fb;
53 //string stra,strb;
    //string stra,strb;
54 complex ca,cb;
    complex ca,cb;
55 
    
56 
    
57 cout << "请输入两个复数:"<<endl;
    cout << "请输入两个复数:"<<endl;
58 ca.Putln();
    ca.Putln();
59 cb.Putln();
    cb.Putln();
60
61 ca.show();
    ca.show();
62 cout<< "+";
    cout<< "+";
63 cb.show();
    cb.show();
64 cout<< "=";
    cout<< "=";
65
66 sr.addition(ca,cb).show();
    sr.addition(ca,cb).show();
67 cout<<endl;
    cout<<endl;
68
69 return;
    return;
70 }
}
71