课堂练习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 ...
随机推荐
- eclipse中改变默认的workspace的方法
1.File-->Switch Workspace-->Other 2.Window-->Preferences-->General-->Startup and Shui ...
- git上传GitHub并预览
- [原]git的使用(一)---建立本地仓库、add和commit、status和git diff、版本回退使用git reset
在window下已经安装了git的环境 1.建立本地仓库 mkdir test #建立test目录 cd test #进入目录 git init # ...
- web自动化时,sendkeys输入长文本时浏览器响应慢或错误时处理
在做某个测试时,要在文本框中输入大量的文本,文件内容如下: "-----BEGIN CERTIFICATE-----\nMIIBozCCAQwCAQEwDQYJKoZIhvcNAQEFBQA ...
- ajax无刷新获取天气信息
浏览器由于安全方面的问题,禁止ajax跨域请求其他网站的数据,但是可以再本地的服务器上获取其他服务器的信息,在通过ajax请求本地服务来实现: <?php header("conten ...
- tomcat启动后,页面浏览时报错 Unable to compile class for JSP的解决方案【原创】
问题描述: tomcat启动后,console正常,console中语句为: 信息: Server startup in 7291 ms 但浏览器访问首页面http://localhost:808 ...
- 9.10Django模板
2018-9-10 16:37:29 模板就一个 不能嵌套 模板: http://www.cnblogs.com/liwenzhou/p/7931828.html 2018-9-10 21:23:3 ...
- RGB颜色值与十六进制颜色码对照表
颜色码对照表 颜色 英文代码 形象描述 十六进制 RGB LightPink 浅粉红 #FFB6C1 255,182,193 Pink 粉红 #FFC0CB 255,192,203 Crimson 猩 ...
- Mongodb之主从复制
本次在同一台主机启动两个端口进行配置 在文件夹/etc/mongod下面新建两个配置文件 一个主配置文件一个从配置文件 master.conf dbpath=/data/mongo-master lo ...
- 计蒜客 31447 - Fantastic Graph - [有源汇上下界可行流][2018ICPC沈阳网络预赛F题]
题目链接:https://nanti.jisuanke.com/t/31447 "Oh, There is a bipartite graph.""Make it Fan ...