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;
    }

  • 相关阅读:
    tcp和udp的区别
    链路聚合配置
    TCP/IP协议
    ip数据报格式
    私有IP地址和公网IP地址
    ipconfig
    ipconfig
    命令更改ip地址2
    命令更改ip地址一
    路由器静态ip设置
  • 原文地址:https://www.cnblogs.com/nuo26/p/8748767.html
Copyright © 2011-2022 走看看