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. C# 中文日期 周几

    //该语句显示的为英文格式 DateTime.Now.DayOfWeek.ToString(); //显示中文格式星期几 "星期" + DateTime.Now.ToString( ...

  2. Python pyQt4/PyQt5 学习笔记3(绝对对位,盒布局,网格布局)

    本节研究布局管理的内容. (一)绝对对位  import sys from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__( ...

  3. Toast 自定义

    转:http://www.cnblogs.com/salam/archive/2010/11/10/1873654.html 1.默认效果 代码 Toast.makeText(getApplicati ...

  4. Mycat的简易安装及测试

    1.环境 OS版本 CentOS release 6.5 (Final) 64bit DB版本 Mysql 5.6.37 Mycat 1.6 jdk1.7及以上版本 2.实战部署 1.创建用户及用户组 ...

  5. sencha touch Demo(示例)(2014-6-25)

    这是一个开源示例,是我对sencha touch的深层应用.已停止更新 sencha touch版本:2.2.1/2.3.1 源码地址: https://bitbucket.org/moLangZai ...

  6. 使用Autolayout xib实现动态高度的TableViewCell

    http://my.oschina.net/u/2360693/blog/481236?p={{totalPage}} 创建Xib文件 首先将Cell做好布局,调整到满意的位置和宽度,然后开始做Aut ...

  7. Listview多tab上滑悬浮

    extends:http://blog.163.com/xueshanhaizi@126/blog/static/37250245201410541721892/ 1:近期要做一个含有两个tab切换页 ...

  8. Python2.7设置在shell脚本中自动补全功能的方法

    1.新建tab.py文件 #!/usr/bin/env python # python startup file import sys import readline import rlcomplet ...

  9. 2018-2019-2 20165330《网络对抗技术》Exp2 后门原理与实践

    目录 基础问题 相关知识 实验内容 实验步骤 实验过程中遇到的问题 实验总结与体会 实验内容 使用netcat获取主机操作Shell,cron启动 使用socat获取主机操作Shell, 任务计划启动 ...

  10. XTU 1261 - Roads - [最小割][2017湘潭邀请赛B题(江苏省赛)]

    之前在网上搜了一个下午没搜到这道题的题解,然后同时又对着叉姐写的两行字题解看了一个下午: 虽然基本上已经知道了这题的思路,但愣是因为自己代码实现起来太繁复,外加不确定正确性,没敢码…… 但是一道题肝了 ...