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. Android studio修改字体(font)大小(size)

    Android Studio 默认编辑器(Editor)的方案(Scheme)是无法修改字体的, 可以Save as, 保存为新的方案(Scheme), 然后更改字体大小; 位置: File-> ...

  2. [转]Linux sendmail 详解

    Internet上最基本的服务,现在应该大部分人都有自己的邮箱吧,用的人多,但理解的人估计没多少,我自己以前也是常常用,但对其原理并不操心.今天就来操心下,进行个小总结 一.邮件服务的基本流程     ...

  3. DragonBones龙骨插槽的隐藏

    参考: 插槽中对象的显示与隐藏问题 let factory = dragonBones.EgretFactory.factory; factory.parseDragonBonesData(RES.g ...

  4. Internet Explorer 9 已安装在此系统上

    问题: win7系统,IE11浏览器,想换成IE9,安装IE9的时候,提示错误. 解决方案: 方案一: 1.打开 控制面板--程序--程序和功能--点击打开或者关闭Windows功能,找到Intern ...

  5. PS-CC常用快捷键总结

    灵活使用photoshop软件快捷键是学好该软件的基础,ps快捷键对于ps平时操作有很大帮助 熟练掌握ps的快捷键可以为了处理图片节省很多时间.现在笔者将自己平时常用的快捷键总结如下: 移动工具[V] ...

  6. where are you from

    where are you from 如果问美国人这句话的话,他们一般会说: I'm from California. I'm from Pennsylvanian. 一般是说州,而不是说Americ ...

  7. nginx socket转发设置

    1.添加依赖模块,如下 --with-stream --with-stream_ssl_module 2.nginx.conf 配置,参考说明:ngx_stream_core_module user ...

  8. RabbitMQ 安装和说明

    一.安装 1. 下载源码,RabbitMQ是使用Erlang开发,所以安装RabbitMQ前需要先安装Erlang.官方推荐从源码安装Erlang,因此下面开始从源码安装OTP 17.0.下载OTP ...

  9. Kibana在Linux上安装部署及使用说明

    Kibana安装及使用说明 Kibana是一个针对Elasticsearch的开源分析及可视化平台,用来搜索.查看交互存储在Elasticsearch索引中的数据. 官方地址:https://www. ...

  10. Python 基础知识(一)

    1.Python简介 1.1.Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文名字:龟叔)为了在阿姆斯特丹打发时 ...