Complex类

  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4. class Complex {
  5. public:
  6. Complex(double nreal = 0.0, double nimaginary = 0.0);
  7. Complex(Complex &c);
  8. void add(Complex com);
  9. void show();
  10. double mod();
  11. private:
  12. double real;
  13. double imaginary;
  14.  
  15. };
  16. Complex::Complex(double nreal, double nimaginary) :real(nreal), imaginary(nimaginary) {};
  17. Complex::Complex(Complex &c) {
  18. real = c.real;
  19. imaginary = c.imaginary;
  20. }
  21. void Complex::add(Complex com) {
  22. real += com.real;
  23. imaginary += com.imaginary;
  24. }
  25. void Complex::show() {
  26. if (imaginary == )
  27. cout << real << endl;
  28. else if (imaginary > )
  29. cout << real << "+" << imaginary << "i" << endl;
  30. else
  31. cout << real << imaginary << "i" << endl;
  32. }
  33. double Complex::mod() {
  34. return sqrt(real*real + imaginary * imaginary);
  35. }
  36. int main() {
  37. Complex c1(,);
  38. Complex c2=4.5;
  39. Complex c3(c1);
  40. c1.add(c2);
  41. c1.show();
  42. cout << c1.mod();
  43. return ;
  44. }

课堂练习Complex类的更多相关文章

  1. 课堂作业Complex类的实现

    #include <iostream> #include <cmath> using namespace std; class Complex{ public: Complex ...

  2. 设计、定义并实现Complex类

    设计.定义并实现Complex类 #include <iostream> #include <cmath> using namespace std; class MyCompl ...

  3. Complex类的设计与改进

    Complex类 源码 #include <cmath> #include <iomanip> #include <iostream> #include <s ...

  4. 《Java 程序设计》课堂实践项目-类定义

    <Java 程序设计>课堂实践项目类定义 课后学习总结 目录 改变 类定义实验要求 课堂实践成果 课后思考 改变 修改了博客整体布局,过去就贴个代码贴个图很草率,这次布局和内容都有修改. ...

  5. 课堂作业-Bag类的实现

    课堂作业-Bag类的实现 要求: 代码运行在命令行中,路径要体现学号信息,IDEA中,伪代码要体现个人学号信息 参见Bag的UML图,用Java继承BagInterface实现泛型类Bag,并对方法进 ...

  6. 课堂小练习 设计、定义并实现Complex类

    定义一个负数类Complex使得下面的代码能够工作.(课本P145) #include<iostream> #include<cmath> using namespace st ...

  7. 课堂小练习(complex类)

    定义一个复数类Complex,使得下面的代码能够工作: Complex c1(3,5);     //用复数3+5i初始化c1: Compex c2=4.5;      //用实数4.5初始化c2 c ...

  8. complex类

    #include<iostream> #include<cmath> using namespace std; class complex{ public: complex() ...

  9. 课堂实验-String类和Arrays类

    课堂实验 在IDEA中以TDD的方式对String类和Arrays类进行学习 测试相关方法的正常,错误和边界情况 String类 charAt split Arrays类 sort binarySea ...

随机推荐

  1. OGG遇到相关问题汇总

    OGG初始化加载数据时遇到的问题 1.target端拒绝source端访问 2016-12-13 14:31:03 INFO OGG-00963 Oracle GoldenGate Manager f ...

  2. 【CF772D】Varying Kibibits FWT

    [CF772D]Varying Kibibits 题意:定义函数f(a,b,c...)表示将a,b,c..的10进制下的每一位拆开,分别取最小值组成的数.如f(123,321)=121,f(530,  ...

  3. windows 环境下node开发环境搭配问题

    当我们使用ccap 生成验证码时,需要node-gyp构建build,但是c的编译环境是在python,vc. node-gyp包 https://github.com/TooTallNate/nod ...

  4. Windows Mysql binlog 数据恢复

    show variables like 'log_bin%'; 可以看到Mysql binlog为关闭状态,那我们去更改为开启状态

  5. R排序sort、order、rank、arrange

    Ø sort sort(x, decreasing = FALSE, ...) ## Default S3 method: sort(x, decreasing = FALSE, na.last = ...

  6. ztree学习---将默认勾选的展开

    这里只给出前台页面上的代码,数据可以从后台获取,注意,在封装数据的时候,注意:Id(节点的id,可以是数字也可以是字符串) , pid(父亲节点的id) , name(节点名称)不能少 . html页 ...

  7. Linux下搭建Hadoop集群(Centos7.0)

    Hadoop集群安装 概述 集群 cluster,将很多任务进程分布到多台计算机上:通过联合使用多台计算机的存储.计算能力完成更庞大的任务.为了实现无限量的存储和计算能力,在生产环境中必须使用集群来满 ...

  8. hihocoder 1829 - 压缩字符串 - [状压+暴力枚举][2018ICPC北京网络预赛B题]

    题目链接:https://hihocoder.com/problemset/problem/1829 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Lara Croft, ...

  9. SPOJ MKTHNUM & POJ 2104 - K-th Number - [主席树模板题]

    题目链接:http://poj.org/problem?id=2104 Description You are working for Macrohard company in data struct ...

  10. 11.28JavaScript学习

    JavaScript输出JavaScript通常用于操作HTML元素,如果要访问某个HTML元素,使用document.getElementById(id)方法,使用id属性标识HTML元素 文档输出 ...