函数,复数,运算符的简解

“”"

函数

“”"

  • 字面意思:输入

    作用:在终端中输入信息,按下回车后,信息进入程序(左边)。

    = 叫做 赋值 符号 msg = input(“输吧:”)

    字面意思:打印/显示

    作用:将程序中的信息,输出到终端。 print(msg)

**

数据类型

                       **复数 运算符 比较 逻辑**  
  • 1.复数 = 实部 + 虚部

  •  	a = 10 + 3j print(type(a))
    

    2. bool 命题:带有判断性质的陈述句。

       例如:我是一个男人.  结果:对True    错Flase 
       			num01 = 10 num02 = 3 b = 10 < 3 print(b)  # F
    
  • 3. 比较运算符

        >   <  >=   <=  相同 ==   不同!= 
        				print(10.5 > 5)  
    

4. 逻辑运算符 and or not

     and   :是并且的关系,也就是说两个条件都需要满足才						 行。
     现象:一假俱假 
     print(True and True) #显示为True 
     print(True and False)#显示为False
     print(False and True) #显示为False 
     print(False and False)  # 显示为False

or : 是或者的关系,也就是说两个条件只需要满足一个就行。
现象:一真俱真
print(True or True) # 显示为True
print(True or False) # 显示为True
print(False or True) # 显示为True
print(False or False) # 显示为False
not (非): 这个就不用说吧,就是取反得意思。
b = True c = not b print© # False

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include<iostream> #include<cmath> using namespace std; class Complex { public: Complex(double r = 0.0, double m = 0.0) :real(r), magic(m) { cout << "Complex instructor!" << endl; } ~Complex() { cout << "Complex destructor!" << endl; } void display() const { if (real == 0) cout << magic << "i" << endl; else { if (magic > 0) cout << real << "+" << magic << "i" << endl; else if (magic < 0) cout << real << magic << "i" << endl; else cout << real << endl; } } Complex operator +(const Complex& c2) const; Complex operator -(const Complex& c2) const; Complex operator *(const Complex& c2) const; Complex operator /(const Complex& c2) const; friend Complex operator + (const double& d, const Complex& c); friend Complex operator - (const double& d, const Complex& c); friend Complex operator + (const Complex& c, const double& d); friend Complex operator - (const Complex& c, const double& d); friend ostream& operator << (ostream& out, const Complex& c);//operator"<<" friend Complex operator / (const double& d, const Complex& c); friend Complex operator * (const Complex& c, const double& d); friend Complex operator / (const Complex& c, const double& d); private: double real, magic; }; Complex Complex::operator +(const Complex& c2) const { return Complex(real + c2.real, magic + c2.magic);//copy } Complex Complex::operator -(const Complex& c2) const { return Complex(real - c2.real, magic - c2.magic);//copy } Complex Complex::operator *(const Complex& c2) const { return Complex(real * c2.real - magic * c2.magic, c2.real * magic + real*c2.magic);//copy } Complex Complex::operator /(const Complex& c2) const { double k = pow(c2.real, 2) + pow(c2.magic, 2); return Complex((real * c2.real + magic * c2.magic)/k, (c2.real * magic - real * c2.magic)/k);//copy } Complex operator + (const double& d, const Complex& c) { return Complex(d + c.real, c.magic);//copy } Complex operator - (const double& d, const Complex& c) { return Complex(d - c.real, -c.magic);//copy } Complex operator + (const Complex& c, const double& d) { return Complex(c.real + d, c.magic);//copy } Complex operator / (const double& d, const Complex& c) { double k = pow(c.real, 2) + pow(c.magic, 2); return Complex(d * c.real / k, - d * c.magic / k);//copy } Complex operator - (const Complex& c, const double& d) { return Complex(c.real - d, c.magic);//copy } Complex operator * (const Complex& c, const double& d) { return Complex(c.real * d, c.magic * d);//copy } Complex operator / (const Complex& c, const double& d) { return Complex(c.real / d, c.magic / d);//copy } ostream& operator<<(ostream& out, const Complex& c) { if (c.real == 0) cout << c.magic << "i" << endl; else { if (c.magic > 0) cout << c.real << "+" << c.magic << "i" << endl; else if (c.magic < 0) cout << c.real << c.magic << "i" << endl; else cout << c.real << endl; } return out; } int main() { Complex C1(5, 4), C2(7,2), C3; cout << "C1=" << C1 << endl; cout << "C2=" << C2 << endl; C3 = C1 + C2; cout << "C3=" << C3 << endl; C3 = C1 - C2; cout << "C3=" << C3 << endl; C3 = C1 * C2; cout << "C3=" << C3 << endl; C3 = C1 / C2; cout << "C3=" << C3 << endl; double d; cin >> d; C3 = d + C1; cout << "C3=" << C3 << endl; C3 = d - C1; cout << "C3=" << C3 << endl; C3 = C1 + d; cout << "C3=" << C3 << endl; C3 = C1 - d; cout << "C3=" << C3 << endl; C3 = C1 * d; cout << "C3=" << C3 << endl; C3 = C1 / d; cout << "C3=" << C3 << endl; C3 = d / C1; cout << "C3=" << C3 << endl; return 0; }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值