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. Big Spatio temporal Data(R-tree Index and NN & RNN & Skyline)

    一.简单介绍大数据技术产物 “大数据”一词首先出现在2008年9月<Nature>杂志发表的一篇名为“Big Data: Wikiomics”的文章上(Mitch,2008).“大数据科学 ...

  2. php 函数合并 array_merge 与 + 的区别

    array_merge()是PHP语言中的一个函数,作用是将两个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面.返回作为结果的数组. 如果输入的数组中有相同的字符串键名,该键的键值为最 ...

  3. hihoCoder挑战赛28 题目1 : 异或排序

    题目1 : 异或排序 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个长度为 n 的非负整数序列 a[1..n] 你需要求有多少个非负整数 S 满足以下两个条件: ...

  4. 一个lucene源码分析的博客

    ITpub上的一个lucene源码分析的博客,写的比较全面:http://blog.itpub.net/28624388/cid-93356-list-1/

  5. linux shell脚本中 mode=${1:-sart} filename=${fileuser:-"filename"}

    $1代表第二个参数m=${1:-start}表示如果$1存在且不为空,m就是$1如果$1不存在或为空,那么m就是start filename=${fileuser:-"filename&qu ...

  6. SDRAM相位角计算

    SDRAM相位角计算 下面是我复制别人的没有图片 如果想看原文 点击下面链接,, http://wenku.baidu.com/view/91e2d76a27284b73f24250e6.html 一 ...

  7. linux系统下kvm虚拟机的安装

    一 KVM虚拟机简介 KVM是kernel-based Virtual Machine的简称,目前已成为学术界的主流VMM之一.KVM的虚拟化需要硬件支持(如Intel VT技术或者AMD V技术) ...

  8. Java秒杀简单设计一:搭建springboot环境

    项目参考:慕课网  https://www.imooc.com/learn/587 Java秒杀 开发环境 JDK1.8.Maven.Mysql.Eclipse.SpringBoot2.0.5.myb ...

  9. Druid的Segment Balance及其代价计算函数分析

    Balance $Cost(X, Y) $ $$ J_\alpha(x) = \sum_{m=0}^\infty \frac{(-1)^m}{m! \Gamma (m + \alpha + 1)} { ...

  10. Nginx防止恶意域名解析

    为了防止别人恶意将大量域名解析到自己的网站上面.我们可以对nginx做防止恶意域名解析,这样就只能通过自己的域名访问网站,其他域名就会显示错误500 打开Nginx配置文件nginx.conf,在原来 ...