小编Toi*_*ila的帖子

复数的共轭函数

我试图创建一个共轭复数的函数,例如A(2,3)将通过键入变成A(2,-3)〜我已经在下面做了一些代码,但我想这是错的,我希望你可以帮我解决这个问题.我在下面的代码中引用了我做错的部分.

#include <iostream>
    using namespace std;
    class Complex
    {
    private:
        double real;
        double imaginenary;
    public:
        Complex();
        Complex(double r, double i = 0);

        // Declaration 
        Complex operator~(const Complex & c) const;


        Complex operator+(const Complex & c) const;
        Complex operator-(const Complex & c) const;
        Complex operator*(const Complex & c) const;
        Complex operator*(double n) const; 
       friend Complex operator*(double m, const Complex & c)
               { return c * m; }    
        friend ostream & operator<<(ostream & os, const Complex & c);
    };
    Complex::Complex()
    {
        real …
Run Code Online (Sandbox Code Playgroud)

c++

3
推荐指数
1
解决办法
6071
查看次数

需要有关getArea()函数的帮助

我试图通过使用现有数据(半径,宽度和高度)来计算圆和矩形的面积.但我有一些错误,我希望你能帮助我解决它.

#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Shape
{
public:
    virtual void Draw () = 0;
    virtual void MoveTo (int newx, int newy) = 0;
    virtual int GetArea()const = 0;
};

class Rectangle : public Shape
{
public:
    Rectangle (int x, int y, int w, int h);
    virtual void Draw ();
    virtual void MoveTo (int newx, int newy);
    int GetArea() {return height * width;}

private:
    int x, y;
    int width;
    int height;
};

void Rectangle::Draw () …
Run Code Online (Sandbox Code Playgroud)

c++

-3
推荐指数
1
解决办法
980
查看次数

标签 统计

c++ ×2