↑ 收起筛选 ↑
C++的问题:定义描述复数的结构体类型变量,并实现...
2020-09-12

给你个类的吧,c++中一般不用结构体#include <iostream.h>//using namespace std; class complex { private: float real; float image; public: complex(float r=0,float i=0) { real=r; image=i; }/* void display() { cout<<real<<"+"<<image<<"i"<<endl; }*/

最近我也遇到这题,虽然有点迟,不过我还是想解答. #include<iostream>using namespace std; typedef struct Complex { double a; double b; }mc; //mc是Complex类型的变量 mc add(mc n,mc m) //复数相加 { mc result; result.a = n.a + m.a; //实

#include "stdio.h"struct complex{float a;//实部float b;//虚部};complex addcomplex(complex a,complex b){complex c;c.a=a.a+b.a;c.b=a.b+b.b;return c;}complex subcomplex(complex a,complex b){complex c;c.a

#include <stdio.h> struct complex { double re; double im; }; struct complex add(struct complex c1, struct complex c2) { struct complex sum; sum.re = c1.re + c2.re; sum.im = c1.im + c2.im; return sum; } int main(void) { struct complex a, b, s; printf("Input

#includeusing namespace std;typedef struct{ double a, b;} fushu;fushu add(fushu a, fushu b) /*计算a+b,返回一个复数*/{ fushu c; c.a = a.a + b.a; c.b = a.b + b.b; return c;}fushu jian(fushu a, fushu b){ fushu c; c.a= a.a - b.a; c.b = a.b- b.b; return c;}fushu

晕,这也属于数学范围?可惜不能用C++, 否则可以直接封装两个方法(加和减)#include <stdio.h>struct{ float x, y;} my_complex;main(){ my_complex a, b, c, d; a.x = 5; a.y = 4; // 复数a为:5+4i b.x = 3; b.y = -5; // 复数b为:3-5j c.x = a.x - b.x; c.y = a.y - b.y; // 复数c = a - b; d.x = a.x + b.x; d.y = a.y + b.y; // 复数d = a + b;}

typedef是定义新的数据类型的命令struct 后面有名字的叫 有名结构体 没名字的叫无名结构体 这个书上有详解结尾花括号后面的名字就是新定义的类型名,即:定义了两个新类型,一个叫LNode 一个叫Sqlist之后,我们就可以使用这两个类型去定义变量了,如:LNode *p1 ;Sqlist *p2 ;就象使用int char基本一样

#include <stdio.h> struct complex { int re; int im; }; void add(struct complex a, struct complex b, struct complex *c) { c->re=a.re+b.re; c->im=a.im+b.im; } void minus(struct complex a, struct complex b, struct complex *c) { c->re=a.re-b.re; c->im=a.im-b.

struct comple{int real;//实数部分int xushu//虚数部分};

变量名,储存内容为地址~

延伸阅读: