function

#include<iostream>
using std::cout;
using std::endl;
class pu
{
public:
    pu(double r = 0,double i = 0)
    {
        real = r;
        im = i;
    }
    void setr(double r )
    {
        real = r;
    }
    void seti(double i)
    {
        im = i;
    }
    double putr()
    {
        return real;
    }
    double puti()
    {
        return im;
    }
    void operator-=(pu & a)
    {
        real = real - a.putr();
        im = im - a.puti();
    }
    ~pu(){}
private:
    double real;
    double im;
};
class array
{
public:
    array()
    {
        int i=0;
        for(i=0;i<10;i++)
        {
            a[i]=0;
        }
    }
    array(int b[] )
    {
        int i;
        for(i=0;i<10;i++)
        {
            a[i] = b[i];
        }
    }
    int put(int i)
    {
        return a[i];
    }
    void set(int i ,int aa)
    {
        a[i] = aa;
    }
    friend array operator+(array &aa,array & b); 
    /*array operator+ (array & aa)
    {
        array b;
        int i;
        for(i = 0;i < 10;i ++)
        {
            b.set(i,(aa.put(i) + a[i]));
        }
        return b;
    }*/
    friend void operator+=(array & a, array & b);
    void print ()
    {
        int i;
        for (i = 0;i < 10;i ++)
        {
            cout << a[i] << " ";
        }
        cout << endl;
    }
    ~array(){}
private:
    int a[10];
};
void operator+=(array & a,array & b)
{
    int i;
    for(i=0;i<10;i++)
        a.a[i] = a.a[i] + b.a[i];
}
array operator+(array & aa,array & b)
{
    array cc;
    int i;
    for(i=0;i<10;i++)
        //cc.set(i,(aa.put(i)+b.put(i)));
        cc.a[i]=aa.a[i]+b.a[i];
    return cc;
}
class money
{
public:
    money(int a = 0,int b = 0,int c=0)
    {
        y = a;
        j = b;
        f = c;
    }
    ~money(){}
    money operator--()
    {
        y--;
        return *this;
    }
    money operator--(int)
    {
        money temp(*this);
        y--;
        return temp;
    }
    void display()
    {
        cout << y <<" " << j << " " << f << endl;
    }
private:
    int y;
    int j;
    int f;
};
void main()
{
    money m1(10,8,5),m2,m3;
    pu c1(10,20),c2(15,30);
    c2 -= c1;
    int a[10] = {1,2,3,4,5,6,7,8,9,10};
    int b[10] = {4,5,6,7,8,9,10,11,12,13};
    array arr1(a),arr2(b),arr3;
    cout << "c1( " << c1.putr() << "," << c1.puti() << ")" <<endl;
    cout << "c2( " << c2.putr() << "," << c2.puti() << ")" <<endl;
    arr3 = arr1 + arr2;
    cout << "arr3 = " ;
    arr3.print();
    arr1 += arr2;
    cout << "arr1 = ";
    arr1.print();
    m3 = m1;
    cout << "m1: ";
    m1.display();
    --m1;
    m2 = m1;
    cout << "m2: ";
    m2.display();
    m1 = m3;
    m3 = m1 --;
    cout << "m3 :";
    m3.display();
}

 

posted on 2013-12-26 16:57  了发发  阅读(162)  评论(0)    收藏  举报

导航