Complex类的实现
#include<iostream>
#include<cmath>
using namespace std;
class complex{
public:
complex(double a,double b=);
complex(complex &p);
void show();
void madd(complex q);
double mod();
private:
double real;
double imag;
};
complex::complex(double a,double b)
{
real=a;
imag=b;
}
complex::complex(complex &p)
{
real.p.real;
imag=p.imag;
}
void complex::show()
{
if(real!=)
{
if(imag!=)
cout<<real<<'+'<<imag<<'i'<<endl;
else
cout<<real<<endl;
}
else
{
if(imag!=)
cout<<imag<<'i'<<endl;
else
cout<<<<endl;
}
}
void complex::madd(complex q)
{
real+=q.real;
imag+=q.imag;
}
double complex::mod()
{
double x,y;
x=real*real+imag*imag;
y=sqrt(x);
return y;
}
int main()
{
complex c1(,);
complex c2(4.5);
complex c3(c1);
c1.show();
c2.show();
c3.show();
cout<<c3.mod()<<endl;
c1.madd(c2);
c1.show();
return ;
}

Complex类的实现的更多相关文章
- 设计、定义并实现Complex类
设计.定义并实现Complex类 #include <iostream> #include <cmath> using namespace std; class MyCompl ...
- Complex类的设计与改进
Complex类 源码 #include <cmath> #include <iomanip> #include <iostream> #include <s ...
- 课堂练习Complex类
Complex类 #include<iostream> #include<cmath> using namespace std; class Complex { public: ...
- 课堂小练习 设计、定义并实现Complex类
定义一个负数类Complex使得下面的代码能够工作.(课本P145) #include<iostream> #include<cmath> using namespace st ...
- complex类
#include<iostream> #include<cmath> using namespace std; class complex{ public: complex() ...
- 课堂小练习(complex类)
定义一个复数类Complex,使得下面的代码能够工作: Complex c1(3,5); //用复数3+5i初始化c1: Compex c2=4.5; //用实数4.5初始化c2 c ...
- complex 类
//定义一个复数类Complex,使得下面的代码能够工作. //Complex c1(3,5)//用复数3+5i初始化c1 //complex c2=4.5//用实数4.5初始化c1 //comple ...
- complex类的定义、实现
复数类complex的定义.实现(求模.复数加法) #include <iostream> #include <cmath> using namespace std; clas ...
- 课堂作业Complex类的实现
#include <iostream> #include <cmath> using namespace std; class Complex{ public: Complex ...
随机推荐
- [C#.Net]全局钩子实现USB扫码枪无焦点状态下扫入
https://www.cnblogs.com/masonlu/p/10105135.html
- c# 读取json文件信息
两种方法: /// <summary> /// /// </summary> /// <returns></returns> private strin ...
- sbadmin表单事件
Form表单 自定义表单 <from action="" method="'><!--- 这里可以用表单组件快速生成表单元素哦 ...
- Mapreduce的序列化和流量统计程序开发
一.Hadoop数据序列化的数据类型 Java数据类型 => Hadoop数据类型 int IntWritable float FloatWritable long LongWritable d ...
- sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError)
在我学习flask建立网站时间碰到了一个棘手的问题,就是在我进行操作日志的更新时间,发现表格建立有点错误,导致表缺失,从而报了下面的错误 sqlalchemy.exc.ProgrammingError ...
- cmd应用基础 扫盲教程
cmd是什么? 对于程序员而言,cmd命令提示符是windows操作系统下一个比较重要的工具.对于程序员而言,为了追求更高的效率而抛弃花俏的界面已然是意见很常见的行为,截止到目前的,全世界仍有大量的服 ...
- day13_H5_CSS_1
一.标签.HTML是可以被浏览器解析的一套规则 1.a标签:他是主动闭合标签,表现形式<a href="http://www.baidu.com">baidu<a ...
- [LeetCode] Encode N-ary Tree to Binary Tree 将N叉树编码为二叉树
Design an algorithm to encode an N-ary tree into a binary tree and decode the binary tree to get the ...
- Solve Error: node postinstall sh: node: command not found
When install the yeoman using the following command: npm install -g yo You might have the following ...
- Hangover POJ - 1003
How far can you make a stack of cards overhang a table? If you have one card, you can create a maxim ...