c++问题求大神

2025-02-27 07:01:04
推荐回答(1个)
回答1:

#include 

#include 

using namespace std;

class complex1{

double x;

double y;

public:

complex1(int a,int b):x(a),y(b){};

complex1():x(0),y(0){};

complex1& add(const complex1& temp) {

       this->x=this->x+temp.x;

       this->y=this->y+temp.y;

       return *this;

       }

complex1& init (int x, int y){

       this->x=x;

       this->y=y;

       return *this;

       }

void readcomplex1(){

      double a=0;double b=0;char ch=NULL;

      cout<<"input x , y(like(1,2) "<

      cin>>a>>ch>>b;

      this->x=a;this->y=b;

      }

void writecomplex1(){

     cout<

     }

double getreal(){return x;}

double getmaginary(){return y;}

};

using namespace std;

int main()

{

    complex1 z1(10,5),z2,z3,z4;

    z2.init(5,6);

    z3.readcomplex1();

    z1.add(z2);

    cout<<"z1: "<

    cout<<"z2: "<

    cout<<"z3: "<

    cout << "Hello world!" << endl;

    return 0;

}