注册 登录
编程论坛 C++教室

类的复数计算 出现问题了,改不过来

yangcaifei 发布于 2015-05-28 13:11, 506 次点击
#include <iostream>

using namespace std;

struct complex
{
    double a;
    double b;
};

struct tcomple
{
    complex one;
    complex two;
};

class tcomplex
{
private:
    complex one;
    complex two;
public:
    void begin(tcomplex *pi,const complex& first,const complex& second);
    void plus();
    void minus();
    void multiplies();
    void divides();
};

void tcomplex::plus()
{
    double addx=one.a+two.a;
    double addy=one.b+two.b;
    cout<<addx<<" "<<addy<<endl;
}

void tcomplex::minus()
{
    double minusx=one.a-two.a;
    double minusy=one.b-two.b;
    cout<<minusx<<" "<<minusy<<endl;
}

void tcomplex::multiplies()
{
    double multipliesx=one.a*two.a-one.b*two.b;
    double multipliesy=one.b*two.a+one.a*two.b;
    cout<<multipliesx<<" "<<multipliesy<<endl;
}

void tcomplex::divides()
{
    double dividesx=(one.a*two.a+one.b*two.b)/(two.a*two.a+two.b*two.b);
    double dividesy=(one.b*two.a-one.a*two.b)/(two.a*two.a+two.b*two.b);
    cout<<dividesx<<" "<<dividesy<<endl;
}

int main(void)
{
    complex first,second;
    tcomplex value;

    cin>>first.a>>first.b;
    cin>>second.a>>second.b;

    value.begin(first,second);//编译器说:error: no matching function for call to 'tcomplex::begin(complex&, complex&)'|
    value.plus();
    value.minus();
    value.multiplies();
    value.divides();
}
3 回复
#2
诸葛欧阳2015-05-28 13:23
感觉你把问题复杂化了,直接设计一个复数类不就好了吗
#3
yangfrancis2015-05-28 13:57
begin函数只是声明了,还没定义呢!并且你的声明当中也是用了三个参数,调用的时候只输入了两个参数,自然要报错了。
#4
yangcaifei2015-05-28 15:20
回复 3楼 yangfrancis
ok 知道了 谢谢
1