zoukankan      html  css  js  c++  java
  • c++ 实验三

    #include<iostream>
    using namespace std;
    class rectangle {
    public:
        rectangle(float l, float w);
        float area();
    private:
        float length, width;
    };
    rectangle::rectangle(float l, float w) {
        length = l;
        width = w;
    }
    float rectangle::area() {
        return length * width;
    }
    int main() {
        float length, width;
        cout << "Enter the length and width of the rectangle:";
        cin >> length >> width;
        rectangle a(length, width);
        cout << a.area() << endl;
        return 0;
    }

    #include<iostream>
    using namespace std;
    class Complex {
    public:
        Complex(float re, float im);
        Complex(float re);
        void add(Complex &c) {
            real += c.real;
        };
        void show() {
            cout << real << (imaginary>0?'+':'-') << imaginary << "i" << endl;
        };
    private:
        float real, imaginary;
    };
    Complex::Complex(float re, float im) {
        real = re;
        imaginary = im;
    };
    Complex::Complex(float re) {
        real = re;
        imaginary = 0;
    };
    int main(){
        Complex c1(3,5);
        Complex c2 = 4.5;
        c1.add(c2);
        c1.show();
        return 0;
    }

  • 相关阅读:
    H3C 配置vlan及vlan间路由
    H3C 端口安全技术
    H3C 备份系统应用程序与文件
    H3C 类似于Linux编辑命令
    H3C telnet
    H3C基本命令
    Python里的目录
    Python 模块
    Python 函数
    JS 100内与7相关的数
  • 原文地址:https://www.cnblogs.com/nuo26/p/8748767.html
Copyright © 2011-2022 走看看