Complex类

 #include<iostream>
#include<cmath>
using namespace std;
class Complex {
public:
Complex(double nreal = 0.0, double nimaginary = 0.0);
Complex(Complex &c);
void add(Complex com);
void show();
double mod();
private:
double real;
double imaginary; };
Complex::Complex(double nreal, double nimaginary) :real(nreal), imaginary(nimaginary) {};
Complex::Complex(Complex &c) {
real = c.real;
imaginary = c.imaginary;
}
void Complex::add(Complex com) {
real += com.real;
imaginary += com.imaginary;
}
void Complex::show() {
if (imaginary == )
cout << real << endl;
else if (imaginary > )
cout << real << "+" << imaginary << "i" << endl;
else
cout << real << imaginary << "i" << endl;
}
double Complex::mod() {
return sqrt(real*real + imaginary * imaginary);
}
int main() {
Complex c1(,);
Complex c2=4.5;
Complex c3(c1);
c1.add(c2);
c1.show();
cout << c1.mod();
return ;
}

课堂练习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. CF 1073C Vasya and Robot(二分答案)

    C. Vasya and Robot time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. Windows正向绑定shell和反向反弹shell的Python代码

    Windows下的shell原理 经过查阅资料,使用os.dup2(nfd, ofd)的方式重定向socket的输入输出到windows系统的cmd是无法做到的,属于系统原因,不能直接复制Linux下 ...

  3. 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验十二:串口模块① — 发送

    实验十二:串口模块① — 发送 串口固然是典型的实验,想必许多同学已经作烂,不过笔者还要循例介绍一下.我们知道串口有发送与接收之分,实验十二的实验目的就是实现串口发送,然而不同的是 ... 笔者会用另 ...

  4. windows_xp下卸载office2003报无法打开此修补程序包错误

    今天在给公司一同事装完xp系统后.准备卸载预安装的Microsoft office2003,然后安装Microsoft office2007.结果在卸载office2003时报如下错误. 经过上网查询 ...

  5. 在python pydev中使用todo标注任务

    在做自动化测试时,有部分代码因需求未定或界面需要更改,代码不做修改或更新,这里就需要用到TODO功能. 在PyCharm中TODO功能很详细,但在pydev中怎么用呢.看了文档后,截图如下: 1.设置 ...

  6. jquery ajax中事件的执行顺序

    jquery中各个事件执行顺序如下: 1.ajaxStart(全局事件) 2.beforeSend 3.ajaxSend(全局事件) 4.success 5.ajaxSuccess(全局事件) 6.e ...

  7. java如何把文件转化成oracle的blob

    import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IO ...

  8. linux文件归档脚本

    #!/bin/bash range= dir="/app/xx/logs" bak_dir="/app/xx/logs_archive" cd $dir $ra ...

  9. 初学filter

    一. Filter介绍 Filter可以认为是Servlet的一种加强版,它主要用于对用户请求进行预处理,也可以对HTTPServletResponse进行后处理,是个典型的处理链.它的完整处理流程是 ...

  10. FZU2110 Star【计算几何】

    Overpower often go to the playground with classmates. They play and chat on the playground. One day, ...