📄 cmplx_sp.cpp
字号:
#include <iostream.h>
struct Complex {
double real;
double iamge;
};
void cmplx_prt(struct Complex);
void cmplx_ipt(struct Complex *);
void cmplx_add(struct Complex *, struct Complex, struct Complex);
void cmplx_sub(struct Complex *, struct Complex, struct Complex);
void cmplx_mul(struct Complex *, struct Complex, struct Complex);
void cmplx_div(struct Complex *, struct Complex, struct Complex);
void main(void) {
struct Complex op1, op2, result;
cmplx_ipt(&op1);
cmplx_ipt(&op2);
cmplx_add(&result, op1, op2);
cmplx_prt(op1); cout<<" + "; cmplx_prt(op2); cout<<" = "; cmplx_prt(result); cout<<endl;
cmplx_sub(&result, op1, op2);
cmplx_prt(op1); cout<<" - "; cmplx_prt(op2); cout<<" = "; cmplx_prt(result); cout<<endl;
cmplx_mul(&result, op1, op2);
cmplx_prt(op1); cout<<" * "; cmplx_prt(op2); cout<<" = "; cmplx_prt(result); cout<<endl;
cmplx_div(&result, op1, op2);
cmplx_prt(op1); cout<<" / "; cmplx_prt(op2); cout<<" = "; cmplx_prt(result); cout<<endl;
}
void cmplx_prt(struct Complex c) {
cout<<'('<<c.real<<(c.iamge<0 ? '-' : '+')<<(c.iamge<0 ? -c.iamge : c.iamge)<<"i)";
return;
} // cmplx_prt
void cmplx_ipt(struct Complex * c) {
char s, i;
cout<<" Please input a complex in the form of a+bi -- ";
cin>>c->real>>s>>c->iamge>>i;
if (s == '-') c->iamge=-c->iamge;
return;
} // cmplx_ipt
void cmplx_add(struct Complex * c, struct Complex o1, struct Complex o2) {
c->real=o1.real+o2.real;
c->iamge=o1.iamge+o2.iamge;
return;
} // cmplx_add
void cmplx_sub(struct Complex * c, struct Complex o1, struct Complex o2) {
c->real=o1.real-o2.real;
c->iamge=o1.iamge-o2.iamge;
return;
} // cmplx_sub
void cmplx_mul(struct Complex * c, struct Complex o1, struct Complex o2) {
c->real=o1.real*o2.real-o1.iamge*o2.iamge;
c->iamge=o1.iamge*o2.real+o1.real*o2.iamge;
return;
} // cmplx_mul
void cmplx_div(struct Complex * c, struct Complex o1, struct Complex o2) {
double b;
b=o2.real*o2.real+o2.iamge*o2.iamge;
c->real=(o1.real*o2.real+o1.iamge*o2.iamge)/b;
c->iamge=(o1.iamge*o2.real-o1.real*o2.iamge)/b;
return;
} // cmplx_div
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -