zoukankan      html  css  js  c++  java
  • 复数加法

     1 #include <iostream>
     2 
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 using namespace std;
     5 class Complex
     6 {
     7     public:
     8         Complex(){real=0;imag=0;}
     9         Complex(double r,double i){real=r;imag=i;}
    10         Complex operator+(Complex &c2);
    11         void display();
    12     private:
    13         double real;
    14         double imag;
    15 };
    16 
    17 Complex Complex::operator+(Complex &c2)
    18 {
    19     Complex c;
    20     c.real=real+c2.real;
    21     c.imag=imag+c2.imag;
    22     return c;
    23 }
    24 
    25 void Complex ::display()
    26 {
    27     cout<<"("<<real<<","<<imag<<"i)"<<endl;
    28 }
    29 int main(int argc, char** argv) {
    30     Complex c1(3,4),c2(5,-10),c3;
    31     c3=c1+c2;
    32     cout<<"c1=";c1.display();
    33     cout<<"c2=";c2.display();
    34     cout<<"c1+c2=";c3.display();
    35     return 0;
    36 }
  • 相关阅读:
    nuxt.js 学习与记录
    图片上传预览 接收
    k8s之deployment
    k8s之service
    k8s的一些命令
    ansible 学习
    k8s之ConfigMap && secret
    k8s 之Job/CronJob
    k8s之PV & PVC
    配置ssh免密登录
  • 原文地址:https://www.cnblogs.com/borter/p/9405360.html
Copyright © 2011-2022 走看看