课堂练习Complex类
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类的更多相关文章
- 课堂作业Complex类的实现
#include <iostream> #include <cmath> using namespace std; class Complex{ public: Complex ...
- 设计、定义并实现Complex类
设计.定义并实现Complex类 #include <iostream> #include <cmath> using namespace std; class MyCompl ...
- Complex类的设计与改进
Complex类 源码 #include <cmath> #include <iomanip> #include <iostream> #include <s ...
- 《Java 程序设计》课堂实践项目-类定义
<Java 程序设计>课堂实践项目类定义 课后学习总结 目录 改变 类定义实验要求 课堂实践成果 课后思考 改变 修改了博客整体布局,过去就贴个代码贴个图很草率,这次布局和内容都有修改. ...
- 课堂作业-Bag类的实现
课堂作业-Bag类的实现 要求: 代码运行在命令行中,路径要体现学号信息,IDEA中,伪代码要体现个人学号信息 参见Bag的UML图,用Java继承BagInterface实现泛型类Bag,并对方法进 ...
- 课堂小练习 设计、定义并实现Complex类
定义一个负数类Complex使得下面的代码能够工作.(课本P145) #include<iostream> #include<cmath> using namespace st ...
- 课堂小练习(complex类)
定义一个复数类Complex,使得下面的代码能够工作: Complex c1(3,5); //用复数3+5i初始化c1: Compex c2=4.5; //用实数4.5初始化c2 c ...
- complex类
#include<iostream> #include<cmath> using namespace std; class complex{ public: complex() ...
- 课堂实验-String类和Arrays类
课堂实验 在IDEA中以TDD的方式对String类和Arrays类进行学习 测试相关方法的正常,错误和边界情况 String类 charAt split Arrays类 sort binarySea ...
随机推荐
- Big Spatio temporal Data(R-tree Index and NN & RNN & Skyline)
一.简单介绍大数据技术产物 “大数据”一词首先出现在2008年9月<Nature>杂志发表的一篇名为“Big Data: Wikiomics”的文章上(Mitch,2008).“大数据科学 ...
- php 函数合并 array_merge 与 + 的区别
array_merge()是PHP语言中的一个函数,作用是将两个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面.返回作为结果的数组. 如果输入的数组中有相同的字符串键名,该键的键值为最 ...
- hihoCoder挑战赛28 题目1 : 异或排序
题目1 : 异或排序 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个长度为 n 的非负整数序列 a[1..n] 你需要求有多少个非负整数 S 满足以下两个条件: ...
- 一个lucene源码分析的博客
ITpub上的一个lucene源码分析的博客,写的比较全面:http://blog.itpub.net/28624388/cid-93356-list-1/
- linux shell脚本中 mode=${1:-sart} filename=${fileuser:-"filename"}
$1代表第二个参数m=${1:-start}表示如果$1存在且不为空,m就是$1如果$1不存在或为空,那么m就是start filename=${fileuser:-"filename&qu ...
- SDRAM相位角计算
SDRAM相位角计算 下面是我复制别人的没有图片 如果想看原文 点击下面链接,, http://wenku.baidu.com/view/91e2d76a27284b73f24250e6.html 一 ...
- linux系统下kvm虚拟机的安装
一 KVM虚拟机简介 KVM是kernel-based Virtual Machine的简称,目前已成为学术界的主流VMM之一.KVM的虚拟化需要硬件支持(如Intel VT技术或者AMD V技术) ...
- Java秒杀简单设计一:搭建springboot环境
项目参考:慕课网 https://www.imooc.com/learn/587 Java秒杀 开发环境 JDK1.8.Maven.Mysql.Eclipse.SpringBoot2.0.5.myb ...
- Druid的Segment Balance及其代价计算函数分析
Balance $Cost(X, Y) $ $$ J_\alpha(x) = \sum_{m=0}^\infty \frac{(-1)^m}{m! \Gamma (m + \alpha + 1)} { ...
- Nginx防止恶意域名解析
为了防止别人恶意将大量域名解析到自己的网站上面.我们可以对nginx做防止恶意域名解析,这样就只能通过自己的域名访问网站,其他域名就会显示错误500 打开Nginx配置文件nginx.conf,在原来 ...